Advertisement
Mordred

MovePath2.0

Oct 7th, 2011
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.66 KB | None | 0 0
  1. --[[ (c) Copyright is for everyone who loves Lua ;)
  2. ---------------------------------------------------
  3. ...............Move Path..Build 2.0................
  4. .................Script by Mordred.................
  5. ___________________________________________________
  6. requires: LCF......................................
  7. ---------------------------------------------------
  8. ]]
  9.  
  10. --[[ Commands
  11. MP -> Main command table
  12.  
  13. StartPath(unit, path table)                                                                             -> Starts the Path with the unit and the table with the containing informations.
  14. ChangePathNode(path table, PathNode, [X],[Y],[Z],[Delay],[Flag],[function called],[delayed function])   -> Changes the properties of the PathNode, but only the given ones and returns true if successfully changed or false if failed.
  15. SetRestartFlag(path table, true/false)                                                                  -> Changes the RestartFlag of the last PathNode to true/false and returns true if successfully changed or false if failed.
  16. AddPathNode(path table, PathNode, X, Y, Z, Delay, Flag, function called, delayed function)              -> Adds a new PathNode to the table with the given informations and returns true if successfully added or false if failed.
  17. RemovePathNode(path table, PathNode)                                                                    -> Removes a PathNode from the table and returns true if successfully removed or false if failed.
  18. ]]
  19.  
  20. --[[   How to register.
  21.  
  22. local PathIDs = {
  23. [1] = {x,y,z,delay,flag[,function called, delayed function]},
  24. [2] = {...},
  25. ...
  26. [9] = {...},
  27. [10] = {x,y,z,delay,Restartflag[,function called, delayed function]}}
  28. MP.StartPath(Unit, PathIDs)
  29.  
  30. ]]
  31. -- Flags: 0=Walk; 1=Run; (2=Fly bugged, never lands again)
  32. -- Restartflag: false/true
  33.  
  34.  
  35. MP = {Flag = {[0] = 0.39, [1] = 0.172, [2] = 0.13}} --default
  36.  
  37. function MP.StartPath(Unit, Table)
  38.     local x = Table[1][1]; local y = Table[1][2]; local z = Table[1][3]
  39.     Unit:SetMovementFlags(Table[1][5])
  40.     local rTime = ((Unit:CalcToDistance(x,y,z)*MP.Flag[Table[1][5]])*1000) - ((Unit:CalcToDistance(x,y,z)*80) - (Unit:CalcToDistance(x,y,z)*5))
  41.     if rTime < 100 then
  42.         MP.PathPoints(Unit, Table, 1)
  43.     else
  44.         LCF:RegisterLuaEvent(tostring(Unit),MP.PathPoints,rTime,1, Unit, Table, 1)
  45.     end
  46.     Unit:MoveTo(x,y,z,0)
  47. end
  48.  
  49. function MP.PathPoints(Unit, Table, PathNum)
  50.     local x = Table[PathNum][1]; local y = Table[PathNum][2]; local z = Table[PathNum][3]
  51.     local rTime = ((Unit:CalcToDistance(x,y,z)*MP.Flag[Table[PathNum][5]])*1000) - ((Unit:CalcToDistance(x,y,z)*80) - (Unit:CalcToDistance(x,y,z)*5))
  52.     if rTime < 150 then
  53.         if (Table[PathNum][6]~=nil) then
  54.             _G[Table[PathNum][6]](Unit, PathNum)
  55.         end
  56.         if (PathNum<table.getn(Table)) and Unit:IsInWorld() then
  57.             if (Table[PathNum][4]~=0) then
  58.                 LCF:RegisterLuaEvent(tostring(Unit),MP.DelayMove,Table[PathNum][4],1, Unit, Table, PathNum)
  59.             else
  60.                 Unit:SetMovementFlags(Table[PathNum][5])
  61.                 local x = Table[PathNum+1][1]; local y = Table[PathNum+1][2]; local z = Table[PathNum+1][3]
  62.                 local rTime = ((Unit:CalcToDistance(x,y,z)*MP.Flag[Table[PathNum][5]])*1000) - ((Unit:CalcToDistance(x,y,z)*80) - (Unit:CalcToDistance(x,y,z)*5))
  63.                 if rTime < 100 then
  64.                     MP.PathPoints(Unit, Table, PathNum+1)
  65.                 else
  66.                     LCF:RegisterLuaEvent(tostring(Unit),MP.PathPoints,rTime,1, Unit, Table, PathNum+1)
  67.                 end
  68.                 Unit:MoveTo(x,y,z,0)
  69.             end
  70.         elseif Table[PathNum][5] then
  71.             MP.StartPath(Unit, Table)
  72.         end
  73.     else
  74.         LCF:RegisterLuaEvent(tostring(Unit),MP.PathPoints,rTime,1, Unit, Table, PathNum)
  75.         if not Unit:IsCreatureMoving() then Unit:MoveTo(x,y,z,0) end
  76.     end
  77. end
  78.  
  79. function MP.DelayMove(Unit, Table, PathNum)
  80.     if (Table[PathNum][7]~=nil) then
  81.         _G[Table[PathNum][7]](Unit, PathNum)
  82.     end
  83.     Unit:SetMovementFlags(Table[PathNum][5])
  84.     local x = Table[PathNum+1][1]; local y = Table[PathNum+1][2]; local z = Table[PathNum+1][3]
  85.     Unit:MoveTo(x,y,z,0)
  86.     local rTime = ((Unit:CalcToDistance(x,y,z)*MP.Flag[Table[PathNum][5]])*1000) - ((Unit:CalcToDistance(x,y,z)*80) - (Unit:CalcToDistance(x,y,z)*5))
  87.     if rTime < 100 then
  88.         MP.PathPoints(Unit, Table, PathNum+1)
  89.     else
  90.         LCF:RegisterLuaEvent(tostring(Unit),MP.PathPoints,rTime,1, Unit, Table, PathNum+1)
  91.     end
  92. end
  93.  
  94. -----------------------------Additional-Commands---------------------------------------
  95.  
  96. function MP.ChangePathNode(Table, PathNum, X,Y,Z,Delay,Flag,FuncCalled,DelayFunc)
  97.     if Table~=nil then
  98.         if X~=nil then if type(X)~="number" then return false; end
  99.             Table[PathNum][1] = X
  100.         end if Y~=nil then if type(X)~="number" then return false; end
  101.             Table[PathNum][2] = Y
  102.         end if Z~=nil then if type(X)~="number" then return false; end
  103.             Table[PathNum][3] = Z
  104.         end if Delay~=nil then if type(X)~="number" then return false; end
  105.             Table[PathNum][4] = Delay
  106.         end if Flag~=nil and PathNum~=getn(Table) then if type(X)~="number" then return false; end
  107.             Table[PathNum][5] = Flag
  108.         end if FuncCalled~=nil then if type(X)~="string" then return false; end
  109.             Table[PathNum][6] = FuncCalled
  110.         end if DelayFunc~=nil then if type(X)~="string" then return false; end
  111.             Table[PathNum][7] = DelayFunc
  112.         end
  113.         return true;
  114.     else return false; end
  115. end
  116.  
  117. function MP.SetRestartFlag(Table, Boolean)
  118.     if Table~=nil then
  119.         if type(Boolean)=="boolean" then
  120.             Table[getn[Table]][5] = Boolean
  121.             return true;
  122.         else return false; end
  123.     else return false; end
  124. end
  125.  
  126. function MP.AddPathNode(Table, PathNum, X,Y,Z,Delay,Flag,FuncCalled,DelayFunc)
  127.     if Table~=nil then
  128.         if PathNum<=getn(Table) then
  129.             table.insert(Table, PathNum, {X,Y,Z,Delay,Flag,FuncCalled,DelayFunc})
  130.             return true;
  131.         else return false; end
  132.     else return false; end
  133. end
  134.  
  135. function MP.RemovePathNode(Table, PathNum)
  136.     if Table~=nil then
  137.         if type(PathNum)=="number" then
  138.             table.remove(Table, PathNum)
  139.             return true;
  140.         else return false; end
  141.     else return false; end
  142. end
  143.  
  144.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement