Scripts:Strafing

From OHRRPGCE-Wiki
Jump to: navigation, search

This script lets the player move around without changing the direction that they are facing, by pressing the A, S, W, D keys. You can adapt it to strafe when the player holds down Z while moving by replacing keyispressed(key:a) with keyispressed(key:z) && keyispressed(key:left).

When the hero is stationary and the player presses a movement key this script uses walk hero followed by set hero direction to override the direction the hero is facing. Because the hero is now moving the normal movement keys do nothing.

# Set as the on-keypress script on every map
plotscript, strafe, begin
  variable(dir)
  dir := hero direction(me)
  if (hero is walking(me) == false) then (
    if (keyispressed(key:a)) then (
      walk hero(me, left)
      set hero direction(me, dir)
    ) else if (keyispressed(key:d)) then (
      walk hero(me, right)
      set hero direction(me, dir)
    ) else if (keyispressed(key:w)) then (
      walk hero(me, up)
      set hero direction(me, dir)
    ) else if (keyispressed(key:s)) then (
      walk hero(me, down)
      set hero direction(me, dir)
    )
  )
end