door problem

i start the game and add the items needed to unlock the door when i try to go through it wont let me
but if i drop one of the items and pick it back up it unlocks
why does that happen why cant i just go trough at the start

start game
AddToInventory (breast plate1)
AddToInventory (pants1)

the locked door
if (Got(breast plate1)) {
if (Got(pants1)) {
UnlockExit (lockdoor)
}
}


When are you running the script for the locked door?

Is the door an object separate from the exit?


If the script that unlocks the door is a turnscript, then you should be aware that turnscripts don't run until the player has done something, so the exit will be locked on the first turn.

If the script is on the exit, you should be aware that exit scripts don't run when it's locked. For imposing limitations on when the player can use an exit, you would normally do something like:

if (Got(breast plate1) and Got(pants1)) {
  MovePlayer (lockdoor.to)
}
else {
  msg (lockdoor.lockmessage)
}

This uses the exit script instead of the "locked" flag.


no its a normal exit i got a bunch of different options that the player can put on and i dont want them leavin the room naked


If it's an exit, the script will only run if it's already unlocked. You use the script to control whether the player can go through, not the "locked" attribute.

If there's multiple options, your code will end up getting quite complex, with lots of 'if' statements. But there may be a quicker way. If you are using the default wearables system, you can use the worn attribute to get a list of all worn items. So your script might be something like:

clothes = FilterByAttribute (ScopeInventory(), "worn", true)
if (ListCount (clothes) < 1) {
  msg ("You can't go out naked.")
}
else {
  MovePlayer (this.to)
}

If you want the player to be wearing multiple garments (shirt and trousers, maybe), you could change the number 1 in that script to something higher, the minimum number of garments. Or if you're using "slots" on the wearables tab? If so, you can use the function GetOuterFor to check if the player is wearing anything in a particular slot. In that case, the script would be something like:

my naked = NewStringList()
foreach (slot, Split("chest;legs")) {
  if (GetOuterFor (game.pov, slot) = null) {
    list add (naked, slot)
  }
}
if (ListCount (naked) = 0) {
  MovePlayer (this.to)
}
else {
  msg ("You can't go out naked! You need to cover your " + FormatList (naked, ", ", " and ", "") + ".")
}

(GetOuterFor returns the outermost garment worn in a slot, or null if the player isn't wearing anything there)
This script is a little more complex, as it lists the slots that are currently empty. You can change the list of slots that the player needs to cover; and change the message based on how you have named your slots.)


Log in to post a reply.

Support

Forums