Quote: "Thanks for the code, but it seems to me about as opaque as it could possibly be, relying upon a knowledgebase that I cannot, nor ever will be able to call upon."
not really sure why it would be opaque, it's using the normal method to get distance based calculations, all answers on the subject will use it in some form, trial and error is your friend, just change the numbers and see what happens
to trigger sitting down for a while (for example) you just need to trigger the state to do so...
i.e.
this code would be used to trigger an entity to change to "sit" state when he reaches node 5 on the path
(note it doesn't actually work, it's just theory - you would need to add code to actually walk the path and animations etc)
if state == "patrol" then
local nodeIndex = 5
local patrolx = AIPathGetPointX(ai_bot_pathindex[e],nodeIndex)
local patroly = AIPathGetPointY(ai_bot_pathindex[e],nodeIndex)
local patrolz = AIPathGetPointZ(ai_bot_pathindex[e],nodeIndex)
local tDistX = g_Entity[e]['x'] - patrolx
local tDistZ = g_Entity[e]['z'] - patrolz
local VertDist = math.abs(g_Entity[e]['y'] - patroly)
local DistFromPath = math.sqrt(math.abs(tDistX*tDistX)+math.abs(tDistZ*tDistZ))
if DistFromPath < 25 and VertDist < 95 then
--trigger event here
StartTimer(e)
state = "sit"
end
elseif state == "sit" then
--now we are in sit state
--check if some time has passed (1 second = 1000) and go back to patrol
if GetTimer(e) > 1000 then
state = "patrol"
end
end
if you need it broken down then essentially these lines
local patrolx = AIPathGetPointX(ai_bot_pathindex[e],nodeIndex)
local patroly = AIPathGetPointY(ai_bot_pathindex[e],nodeIndex)
local patrolz = AIPathGetPointZ(ai_bot_pathindex[e],nodeIndex)
are just getting the point's location in GG - i.e. the same as if you had an invis object at some location and called
local patrolx = GetEntityPositionX(e)
local patroly = GetEntityPositionY(e)
local patrolz = GetEntityPositionZ(e)
the next part just works out the difference between the object/node and the NPC
local tDistX = g_Entity[e]['x'] - patrolx
local tDistZ = g_Entity[e]['z'] - patrolz
local VertDist = math.abs(g_Entity[e]['y'] - patroly)
and finally get those values as 1 value rather than 3 (or 2 in this case as height is dealt with separately in the next step)
local DistFromPath = math.sqrt(math.abs(tDistX*tDistX)+math.abs(tDistZ*tDistZ))
then that value is compared to some distance you want the NPC to be within
if DistFromPath < 25 and VertDist < 95 then