I have a setup in which a guard protects an area and starts a "no trespassing" dialog if they perceive a player around. This is done by the guard's OnPerception script
starting the dialog, if the GetLastPerceived() is a PC and GetLastPerceptionSeen() is TRUE
To avoid being driven away, the PC might go into Stealth Mode or cast Invisibility, in which case GetLastPerceptionSeen() is FALSE, which makes perfect sense.
In other situations a similar check is performed by using GetObjectSeen().
However, the PC having Sanctuary
or Greater Sanctuary
on themselves still causes the guard to receive GetLastPerceptionSeen() is TRUE events when walking into the perception range of the guard and GetObjectSeen() is also TRUE.
A user pointed out to me that Sanctuary
should "work" in such situations, but apparently it doesn't (anymore).
Is there perhaps a best practice as how such guard situations should be coded?
How does the game handle sanctuary?
There are the spell scripts NW_S0_Sanctuary for Sanctuary and x0_s0_ether for Greater Sanctuary, and there is nw_i0_generic's InvisibleTrue, which seems to respect Sanctuary.
I discovered the nw_i0_plot CanSeePlayer function, which uses GetNearestCreature(..., CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN) to determine if a PC is seen by a creature, but this doesn't respect successul Sanctuary