Making An Area Accessible ONLY If Wearing A Certain Item

Is it possible to have someone not be able to access an area unless they are wearing something specific?

For example, you can't walk NORTH into the water unless you are wearing the SCUBA SUIT.


Yes.

You need to think about the problem like a programmer. So here's the thought process that leads me to a solution.

When do you want this code to run? It seems to be when the player tries to enter a particular area.

You could use the "on entering the room" script for the water, but that happens after the player moves, so you'd have to let them enter and then move them back again.

So you'd have a script that checks if the player is wearing the scuba suit, and if not it returns them to the beach. It would look something like:

if (not GetBoolean (SCUBA SUIT, "worn")) {
  msg ("You try to swim out, but you have to give up and go back because the water is so cold. Maybe you need proper equipment.")
  MoveObject (game.pov, beach)
}

(in this version, the player enters the water and is then immediately moved back. It has some problems, especially if either room has other enter/exit scripts, but it can be useful)
In this one, SCUBA SUIT and beach are the names of objects, you'll need to change them to make them match what your object is actually called. (name, not alias. Code uses the name, the player sees the alias)

OR you could put a script on the exit that leads into the water. Every exit has a place where you can add a script, so that script is run instead of just moving the player. In this case, the script would look like:

if (GetBoolean (SCUBA SUIT, "worn")) {
  msg ("You swim out into the water.")
  MoveObject (game.pov, this.to)
}
else {
  msg ("The water's too cold to swim out without a proper suit.")
}

(you don't need to use the room name in the code this time; it uses the special attributes game.pov to mean the player, and this.to to mean the exit's destination)


Log in to post a reply.

Support

Forums