Scripts:Activate doors with a use key

Jump to navigationJump 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 map's 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).

plotscript, use doors on keypress, begin
  if (keyval(key:enter) > 1 || keyval(key:ctrl) > 1 || keyval(key:space) > 1) then, begin
    variable (x, y)
    x := hero x(me)
    y := hero y(me)
    # Find the tile in front of hero
    switch (hero direction(me)) do, begin
      case (up)   y -= 1
      case (down) y += 1
      case (left) x -= 1
      case (right) x += 1
    if (door at spot(x, y) > -1) then (use door(door at spot(x, y)))

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)

Set the Script Argument on the NPC to the right door ID.