Advertisement
Mordred

Untitled

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