Aller au contenu

Photo

Locked door requiring a key


  • Veuillez vous connecter pour répondre
6 réponses à ce sujet

#1
Jereniva

Jereniva
  • Members
  • 114 messages

I created a door that would be locked and require a key.

I was testing, and very surprised to see notice that the door unlocked itself upon picking up the key! 

I had put the key right on ground in front of door. Prior to picking key up, icon for mousing over the door was the lock icon, once I picked up the key, it was the "open the door" icon.

Is that normal?

And how do you re-lock a door, as a player from within the game, not script?

 

 

EDIT, ok, that's normal, the icon changes but the door isn't actually unlocked. dropping the key makes the icon return to a padlock, and door never unlocked.

 

But I'm still not sure how do you, as a player, lock a door, or is that not possible?



#2
Tchos

Tchos
  • Members
  • 5 030 messages

As far as I know the base game doesn't handle locking doors -- only unlocking.  The modder/builder would have to create an item scripted to lock the targeted door, if you want to do it.


  • Jereniva aime ceci

#3
Jereniva

Jereniva
  • Members
  • 114 messages

Ok, I must be thinking of NWN 1. Thanks!



#4
Dann-J

Dann-J
  • Members
  • 3 161 messages

You can set doors to be re-lockable in their properties, but only a rogue can do it (and they don't need a key to do so).

 

A simple way to do it would be to create a usable placeable next to the door that has a conversation attached to it. A conditional (GC) script could check for the presence of the key on the player and offer a conversation option that locks the door again via an action (GA) script. Both scripts already exist in the game.

 

The hard part would be in coming up with a reason for players to click on the usable placeable to relock the door that is immediately obvious to them. :)



#5
Tchos

Tchos
  • Members
  • 5 030 messages

I was thinking more along the lines of a door-locking widget you can carry around, just to make it more obvious for the player.



#6
Dann-J

Dann-J
  • Members
  • 3 161 messages

I was thinking more along the lines of a door-locking widget you can carry around, just to make it more obvious for the player.

 

The script could get quite complex. You'd have to check if the tag of the key matches the key tag of the door you targeted, via GetLockKeyTag(). It'd be easier to give the key itself a unique power (most likely touch-ranged), that way you don't have to search the inventory for the presence of a specific key (just use the tag of the activated item).

 

And would you want to check whether the targeted door was closed before locking it, or would you automatically want the script to close it *while* locking it? The former is more realistic, but the latter might be more player-friendly.

 

 

Another option is to give a locked door a heartbeat script so that it closes and re-locks itself after it's been opened. You'd want to check that the last opener was no longer within a certain range, to stop it from closing in the player's face if they hesitate. I have an automatic door-closing script that does much the same (albeit without any re-locking function):

// hb_door_autoclose
//
// Auto-close a door if the last opener is no longer within 5m of it

void main()
{
object oDoor = OBJECT_SELF;
object oUser = GetLastUsedBy();
int iStayOpen = 0;

if (GetIsOpen(oDoor) == FALSE) return;// Do nothing if door is not open

object oTarget = GetFirstObjectInShape(SHAPE_SPHERE, 5.0, GetLocation(oDoor), FALSE, OBJECT_TYPE_CREATURE);
 
while (GetIsObjectValid(oTarget))
	{
	if (oTarget == oUser) iStayOpen = 1;// Don't close if last opener still close
	oTarget = GetNextObjectInShape(SHAPE_SPHERE, 5.0, GetLocation(oDoor), FALSE, OBJECT_TYPE_CREATURE);
	}//end while

if (iStayOpen) return;// Abort closing
AssignCommand(oDoor, ActionCloseDoor(oDoor));
}



#7
Tchos

Tchos
  • Members
  • 5 030 messages

You're right that adding the function to the key itself would probably be the best idea.  I'd probably go ahead and make it automatically close the door if it's not already closed, locking it at the same time. 

 

I don't think it would be necessary to make it a targeted use.  Just being near enough to the door and activating the key could make it pretty simple.  The key's activation script could check to see if door with tag X is within a certain distance from the activating PC (not from the item itself, since held items don't seem to work with distance functions), and if so, the door is closed and locked.  Might be troublesome if the PC is standing in the doorway, but who knows.

 

I wasn't aware of that rogue ability.