Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ (c) Copyright is for everyone who loves Lua ;)
- ---------------------------------------------------
- ...............Move Path..Build 2.0................
- .................Script by Mordred.................
- ___________________________________________________
- requires: LCF......................................
- ---------------------------------------------------
- ]]
- --[[ Commands
- MP -> Main command table
- StartPath(unit, path table)
- -> Starts the Path with the unit and the table with the containing informations.
- ChangePathNode(path table, PathNode, [X],[Y],[Z],[Delay],[Flag],[function called],[delayed])
- -> Changes the properties of the PathNode, but only the given ones and returns true if successfully changed or false if failed.
- 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.
- 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.
- RemovePathNode(path table, PathNode)
- -> Removes a PathNode from the table and returns true if successfully removed or false if failed.
- ]]
- --[[ How to register.
- local PathIDs = {
- [1] = {x,y,z,delay,flag[,function called, delayed function]},
- [2] = {...},
- ...
- [9] = {...},
- [10] = {x,y,z,delay,Restartflag[,function called, delayed function]}}
- MP.StartPath(Unit, PathIDs)
- ]]
- -- Flags: 0=Walk; 1=Run; (2=Fly bugged, never lands again)
- -- Restartflag: false/true
- MP = {Flag = {[0] = 0.39, [1] = 0.172, [2] = 0.13}} --default
- function MP.StartPath(Unit, Table)
- local x = Table[1][1]; local y = Table[1][2]; local z = Table[1][3]
- Unit:SetMovementFlags(Table[1][5])
- 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))
- if rTime < 100 then
- MP.PathPoints(Unit, Table, 1)
- else
- LCF:RegisterLuaEvent(tostring(Unit),MP.PathPoints,rTime,1, Unit, Table, 1)
- end
- Unit:MoveTo(x,y,z,0)
- end
- function MP.PathPoints(Unit, Table, PathNum)
- local x = Table[PathNum][1]; local y = Table[PathNum][2]; local z = Table[PathNum][3]
- 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))
- if rTime < 150 then
- if (Table[PathNum][6]~=nil) then
- _G[Table[PathNum][6]](Unit, PathNum)
- end
- if (PathNum<table.getn(Table)) and Unit:IsInWorld() then
- if (Table[PathNum][4]~=0) then
- LCF:RegisterLuaEvent(tostring(Unit),MP.DelayMove,Table[PathNum][4],1, Unit, Table, PathNum)
- else
- Unit:SetMovementFlags(Table[PathNum][5])
- local x = Table[PathNum+1][1]; local y = Table[PathNum+1][2]; local z = Table[PathNum+1][3]
- 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))
- if rTime < 100 then
- MP.PathPoints(Unit, Table, PathNum+1)
- else
- LCF:RegisterLuaEvent(tostring(Unit),MP.PathPoints,rTime,1, Unit, Table, PathNum+1)
- end
- Unit:MoveTo(x,y,z,0)
- end
- elseif Table[PathNum][5] then
- MP.StartPath(Unit, Table)
- end
- else
- LCF:RegisterLuaEvent(tostring(Unit),MP.PathPoints,rTime,1, Unit, Table, PathNum)
- if not Unit:IsCreatureMoving() then Unit:MoveTo(x,y,z,0) end
- end
- end
- function MP.DelayMove(Unit, Table, PathNum)
- if (Table[PathNum][7]~=nil) then
- _G[Table[PathNum][7]](Unit, PathNum)
- end
- Unit:SetMovementFlags(Table[PathNum][5])
- local x = Table[PathNum+1][1]; local y = Table[PathNum+1][2]; local z = Table[PathNum+1][3]
- Unit:MoveTo(x,y,z,0)
- 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))
- if rTime < 100 then
- MP.PathPoints(Unit, Table, PathNum+1)
- else
- LCF:RegisterLuaEvent(tostring(Unit),MP.PathPoints,rTime,1, Unit, Table, PathNum+1)
- end
- end
- -----------------------------Additional-Commands---------------------------------------
- function MP.ChangePathNode(Table, PathNum, X,Y,Z,Delay,Flag,FuncCalled,DelayFunc)
- if Table~=nil then
- if X~=nil then if type(X)~="number" then return false; end
- Table[PathNum][1] = X
- end if Y~=nil then if type(X)~="number" then return false; end
- Table[PathNum][2] = Y
- end if Z~=nil then if type(X)~="number" then return false; end
- Table[PathNum][3] = Z
- end if Delay~=nil then if type(X)~="number" then return false; end
- Table[PathNum][4] = Delay
- end if Flag~=nil and PathNum~=getn(Table) then if type(X)~="number" then return false; end
- Table[PathNum][5] = Flag
- end if FuncCalled~=nil then if type(X)~="string" then return false; end
- Table[PathNum][6] = FuncCalled
- end if DelayFunc~=nil then if type(X)~="string" then return false; end
- Table[PathNum][7] = DelayFunc
- end
- return true;
- else return false; end
- end
- function MP.SetRestartFlag(Table, Boolean)
- if Table~=nil then
- if type(Boolean)=="boolean" then
- Table[getn[Table]][5] = Boolean
- return true;
- else return false; end
- else return false; end
- end
- function MP.AddPathNode(Table, PathNum, X,Y,Z,Delay,Flag,FuncCalled,DelayFunc)
- if Table~=nil then
- if PathNum<=getn(Table) then
- table.insert(Table, PathNum, {X,Y,Z,Delay,Flag,FuncCalled,DelayFunc})
- return true;
- else return false; end
- else return false; end
- end
- function MP.RemovePathNode(Table, PathNum)
- if Table~=nil then
- if type(PathNum)=="number" then
- table.remove(Table, PathNum)
- return true;
- else return false; end
- else return false; end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement