Scripts:Realign hero or NPC

From OHRRPGCE-Wiki
Jump to navigationJump to search

If you stop a hero or npc in the middle of movement they might become misaligned, that is, stuck between two tiles. This will cause problems with movement and collision. Use these scripts to move a hero or NPC to the nearest tile.

# Snap hero which has become misaligned with the tile grid back to the grid
script, realign hero, who, begin
  variable(x, y, offx, offy)
  x := hero pixel X(who)
  y := hero pixel Y(who)
  offx := x ,mod, 20
  offy := y ,mod, 20
  if (offx <= 10) then (
    x := x / 20
  ) else (
    x := x / 20 + 1
  )
  if (offy <= 10) then (
    y := y / 20
  ) else (
    y := y / 20 + 1
  )
  set hero position(who, x, y)
end
# Snap npc which has become misaligned with the tile grid back to the grid
script, realign npc, npc, begin
  variable(x, y, offx, offy)
  x := npc pixel X(npc)
  y := npc pixel Y(npc)
  offx := x ,mod, 20
  offy := y ,mod, 20
  if (offx <= 10) then (
    x := x / 20
  ) else (
    x := x / 20 + 1
  )
  if (offy <= 10) then (
    y := y / 20
  ) else (
    y := y / 20 + 1
  )
  set npc position(npc, x, y)
end