Scripts:Activate doors with a use key
Jump to navigation
Jump to search
If you want to be able to activate all your doors with the use key you can set the following script as the global or per-map on-keypress script.
If you don't want the player to be able to activate a door by stepping on it, either put walls around it, or use the suspenddoors command to prevent doors from activating normally (for example, place that command in a map autorun script, or in your new-game and load-game scripts to affect the whole game).
plotscript, use doors on keypress, begin if (player is suspended || hero is walking(me)) then (exit script) if (keypress(use key)) then, begin variable (x, y, door) x := hero x(me) y := hero y(me) # Find the tile in front of the hero switch (hero direction(me)) do, begin case (up) y -= 1 case (down) y += 1 case (left) x -= 1 case (right) x += 1 end door := door at spot(x, y) if (door > -1) then (use door(door)) end end
Note that this script won't work for activating a door over the edge of a wrap-around map.
A simple solution for a single door is to place an invisible NPC at the door and make it run this script:
plotscript, door, door id, begin use door (door id) end
Set the Script Argument on the NPC to the right door ID.