1
Scripting Chat / Re: Follow sub
« on: March 08, 2010, 09:35:39 AM »Code: [Select]
namespace global Movement
set !characters ; all characters intending to be moved
set !Leader ; the leader
set %Move_Timer 200 ; time in ms between move checks
set %Move_Time #systime
set %Follow_Dist 2 ; how far it stays behind
While #true
{
while #systime < %Move_Time
wait 1
repeat
uoxl swap
until #charid = !Leader
set !Leaderx #charposx
set !Leadery #charposy
for %clinr 1 #clicnt
{
uoxl swap
if #charid notin !characters
continue
Gosub Calculate_Dist ; Some math required in this sub. Explanation below
if #result > 2
{
gosub Calculate_Move ; based on #chardir sets where the follower should move
Event pathind %Pathfindx %Pathfindy %Pathfindz
}
}
set %Move_Time #systime + %Move_Timer
}
Sub Calculate_Dist
set %Distance_X ABS ( #charposx - !Leaderx )
set %Distance_Y ABS ( #charposy - !Leadery )
if %Distance_X >= %Distance_Y
set %Distance1 %Distance_X
else
set %Distance1 %Distance_Y
set %Total_Distance ( %Distance1 + ( ABS ( %Distance_X - %Distance_Y ) ) )
return %Total_Distance
The Cpu usage and script lag for doing a mathematical calculation is far less than that of Repeated Finditems. Plus Utilizing the info already on your computer (!Leaderx !Leadery) you get a much more accurate reading of the distance/location.