How do I make an NPC have a "line of sight" or an area in which it can detect a hero and how do I make it act upon it?
From OHRRPGCE-Wiki
Sometimes you want an NPC to be activated from a distance away, for example, a pacing guard who sees your heroes if they step in front of him. There is no built-in "line of sight" or "distance" feature for triggering NPC's, but you can fake the effect with plotscripting.
For this example we will write a script that makes a guard NPC do something if you stand in front of him within 8 spaces.
This script must run as a continual loop. Normally you would make it the "map autorun" script for the map the guard is on. This script assumes that the guard is NPC 0
include, plotscr.hsd
plotscript, vigilant guard, begin
variable(guard, this map)
guard := NPC reference (0)
this map := current map
while (this map == current map) do, begin
variable (n1, n2, dist)
n1 := hero X(me)
n2 := NPC X(guard)
dist := n2 -- n1
if(n1 == n2, and, dist <= 8, and, dist >= -8) then (activate NPC (guard))
n1 := hero Y(me)
n2 := NPC Y(guard)
dist := n2 -- n1
if(n1 == n2, and, dist <= 8, and, dist >= -8) then (activate NPC (guard))
wait(1)
end
end
This script hasn't actually been tested in a real RPG yet, so I can't consider this article finished until it has been.
Alternative method: You can place a certain number of "step-on" invisible NPCs in front of the guard, but this only works if he is standing still.
