I needed a monster to set the nearest corpse as its target
, but the same idea could be adapted to anything else easily enough.
-
Clear the source's
target
. Set some user var on the source,user_closest_target
, to a null-ish value like -1. -
Use
A_RadiusGive
from the source to give a dummy inventory item to every candidate actor. -
From the inventory item, call an ACS script.
-
In the ACS script (where the candidate is the activator), check the distance from the candidate to the source via
GetActorX
,GetActorY
, andVectorLength
. If that distance is closer thanuser_closest_target
(oruser_closest_target
is -1, meaning this is the first candidate checked), updateuser_closest_target
and set the source'starget
to this candidate.