Anyway to detect if player is lockpicking?

Questions specific to OpenMW-CS can be asked, and content development related topics can be discussed here
Post Reply
gebruikVonCookies
Posts: 1
Joined: 18 Jun 2021, 22:11

Anyway to detect if player is lockpicking?

Post by gebruikVonCookies »

Hi there, Morrowind modding newb here. I'm trying to make a mod to add an equipable key that will unlock and relock a door associated with it. The easiest I've found to do this so far is create a new lockpick and change the mesh to that of the key. The lockpick has the animation and partial functionality I'm looking for, but right now I've got a script on the load door that is supposed to check for right key and then do the locking/unlocking etc, but can't find a way to actually detect if player is making a lockpick attempt (Something like HitAttemptOnMe, but for a door/container). I've been googling and digging through the Scripting for Dummies guide but haven't found anything.

Here's my current script: a makeshift attempt that achieves basically the same functionality using OnActivate, which I'd prefer to not use so the player can actually "use" the key and have the animation.

Code: Select all

if (OnActivate == 1)
	set hasKey to (player->HasItemEquipped "key_vorar_equip")
	if hasKey == 1
		if(GetLocked == 0)
			Lock 35
			PlaySound3D, "Open Lock Fail"
		else
			Unlock
			PlaySound3D, "Open Lock"
		endif
	else
		Activate
	endif
endif
Not sure if what I want is possible until the big dehardcoding but I am new to this so wanted to see if anyone knew and hear your thoughts!

Cheers!
VonCookies
Wolvman
Posts: 23
Joined: 30 Apr 2012, 15:57

Re: Anyway to detect if player is lockpicking?

Post by Wolvman »

Without some kind of help from LUA you are probably stuck with checking to see if the player or door is playing the lockpicking attempt/success sounds. I don't remember if the sound is played from the player or the door on a lock pick attempt. If it's the door then the script that you have placed on the door should be able to pick up on that sound using "GetSoundPlaying" instead of using OnActivate.
User avatar
Jemolk
Posts: 231
Joined: 20 Mar 2017, 02:12
Location: Sadrith Mora

Re: Anyway to detect if player is lockpicking?

Post by Jemolk »

One problem with the GetSoundPlaying method -- no sound plays when you use a lockpick on a door that isn't locked. I don't think the game considers it a valid target at all. (Source: I just went in-game and checked.) For unlocking, it could work, but for locking, you're stuck with OnActivate for the moment.

What follows is a bunch of theoretical stuff that's probably more trouble than it's worth even if it would technically work: Even for unlocking, there may be issues with using it like a lockpick -- for one thing, the key would be able to be used as a lockpick on any other locked door, too. You might be able to script the key to auto-fail any other lockpick, but I'm not sure. You may be able to get around the limited uses of a lockpick by setting uses to -1, or if that doesn't work just set it to something so absurdly high that running out of uses is physically impossible. Beyond that, if you've somehow managed to script the key to auto-fail any other lockpick, and the sound comes from the door rather than the player, you might be able to use GetSoundPlaying "Open Lock Fail" to detect an unlock attempt on the specific door in question, stop the sound from playing using the script so that the humans involved won't actually hear it in this case, play the sound for success, and unlock the door via script.

All that, just to maybe accomplish half of what you're trying to do, and odds are good that at least one of the approximately half-dozen potential points of failure will cause it to not actually work anyway. Yeah, you're probably better off waiting, unfortunately.
Post Reply