--DESCRIPTION: simple path following script by smallg g_getpath = {} function getpath_properties(e) local gp = g_getpath[e] gp.movespeed = GetEntityMoveSpeed(e)/100.0 gp.turnspeed = GetEntityTurnSpeed(e)/4.0 gp.closestflag = e gp.previousflag = -1 SetAnimationName(e,"walk_loop") LoopAnimation(e) gp.state = "find path" end function getpath_init(e) g_getpath[e] = {} getpath_properties(e) end function getpath_main(e) local function GetFlatDistanceFromEntity(e, t) local x1,z1 = g_Entity[e].x,g_Entity[e].z local x2,z2 = g_Entity[t].x,g_Entity[t].z local dx = x2-x1 local dz = z2-z1 local ddist = dx*dx+dz*dz return ddist end local function GetNextFlag(e, gp) local tflag = -1 for a = 0, 9 do local connectede = GetEntityRelationshipID(gp.closestflag, a) if connectede > 0 then if GetEntityMarkerMode(connectede) == 11 then if connectede ~= gp.previousflag then tflag = connectede break end end end end -- if we didn't get a valid flag we are at the end of the path so we should go to the previous flag if tflag == -1 then tflag = gp.previousflag end -- change our target flag local tflag2 = gp.closestflag gp.closestflag = tflag gp.previousflag = tflag2 -- get the path to our new flag local x,y,z,ax,ay,az = GetEntityPosAng(e) local tx,ty,tz = GetEntityPosAng(gp.closestflag) RDFindPath(x,y,z, tx,ty,tz) local pc = RDGetPathPointCount() if pc > 0 then StartMoveAndRotateToXYZ( e,gp.movespeed,gp.turnspeed,1,1) end end local gp = g_getpath[e] if gp.state == "find path" then -- check if we are connected to a flag or not gp.patrolmode = 0 for a = 0, 9 do -- first check there is an actual connected object local connectede = GetEntityRelationshipID(e,a) if connectede > 0 then -- now check it is a flag if GetEntityMarkerMode(connectede) == 11 then gp.patrolmode = 1 gp.closestflag = connectede gp.previousflag = connectede break end end end if gp.patrolmode > 0 then local x,y,z,ax,ay,az = GetEntityPosAng(e) local tx,ty,tz = GetEntityPosAng(gp.closestflag) RDFindPath(x,y,z, tx,ty,tz) local pc = RDGetPathPointCount() if pc > 0 then StartMoveAndRotateToXYZ(e,gp.movespeed,gp.turnspeed,1,1) gp.state = "follow path" end end elseif gp.state == "follow path" then if GetFlatDistanceFromEntity(e, gp.closestflag) < 120 then -- get the next flag in the path GetNextFlag(e, gp) end end PromptLocal(e, "state = "..gp.state.." , current flag = "..GetEntityName(gp.closestflag)) end