Advertisement
Guest User

order.lua

a guest
Jan 30th, 2016
472
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.00 KB | None | 0 0
  1. local dirpref = {
  2. [1] =  {[NORTH] = {[1] = {NORTH}, [2] = {EAST, WEST}, [3] = {NORTHEAST, NORTHWEST}},
  3.     [EAST] = {[1] = {EAST}, [2] = {NORTH, SOUTH}, [3] = {NORTHEAST, SOUTHEAST}},
  4.     [SOUTH] = {[1] = {SOUTH}, [2] = {EAST, WEST}, [3] = {SOUTHEAST, SOUTHWEST}},
  5.     [WEST] = {[1] = {WEST}, [2] = {SOUTH, NORTH}, [3] = {NORTHWEST, SOUTHWEST}},
  6.     [NORTHEAST] = {[1] = {NORTH, EAST}, [2] = {NORTHEAST}, [3] = {SOUTH, WEST}},
  7.     [SOUTHEAST] = {[1] = {SOUTH, EAST}, [2] = {SOUTHEAST}, [3] = {NORTH, WEST}},
  8.     [SOUTHWEST] = {[1] = {SOUTH, WEST}, [2] = {SOUTHWEST}, [3] = {NORTH, EAST}},
  9.     [NORTHWEST] = {[1] = {NORTH, WEST}, [2] = {NORTHWEST}, [3] = {EAST, SOUTH}}},
  10. [2] =  {[NORTH] = {[1] = {NORTH}, [2] = {WEST, EAST}, [3] = {NORTHWEST, NORTHEAST}},
  11.     [EAST] = {[1] = {EAST}, [2] = {SOUTH, NORTH}, [3] = {SOUTHEAST, NORTHEAST}},
  12.     [SOUTH] = {[1] = {SOUTH}, [2] = {WEST, EAST}, [3] = {SOUTHWEST, SOUTHEAST}},
  13.     [WEST] = {[1] = {WEST}, [2] = {NORTH, SOUTH}, [3] = {SOUTHWEST, NORTHWEST}},
  14.     [NORTHEAST] = {[1] = {EAST, NORTH}, [2] = {NORTHEAST}, [3] = {WEST, SOUTH}},
  15.     [SOUTHEAST] = {[1] = {EAST, SOUTH}, [2] = {SOUTHEAST}, [3] = {WEST, NORTH}},
  16.     [SOUTHWEST] = {[1] = {WEST, SOUTH}, [2] = {SOUTHWEST}, [3] = {EAST, NORTH}},
  17.     [NORTHWEST] = {[1] = {WEST, NORTH}, [2] = {NORTHWEST}, [3] = {SOUTH, EAST}}},
  18. }
  19.  
  20. function doPushCreature(uid,direction,distance,time)
  21.    if isCreature(uid) == TRUE then
  22.    local rand = (2*math.random(0,1))-1
  23.    local rand2 = math.random(-1,0)
  24.       if direction == 0 then
  25.       signal = {0,rand,-rand,rand,-rand,0,-1,-1,-1,0,0,0}
  26.       elseif direction == 1 then
  27.       signal = {1,1,1,0,0,0,0,rand,-rand,rand,-rand,0}
  28.       elseif direction == 2 then
  29.       signal = {0,rand,-rand,rand,-rand,0,1,1,1,0,0,0}
  30.  
  31.       elseif direction == 3 then
  32.  
  33.       signal = {-1,-1,-1,0,0,0,0,rand,-rand,rand,-rand,0}
  34.  
  35.       elseif direction == 4 then
  36.  
  37.       signal = {-1,rand2,(-rand2)-1,0,1,rand2+1,rand2,0}
  38.  
  39.       elseif direction == 5 then
  40.  
  41.       signal = {1,-rand2,-((-rand2)-1),0,1,rand2+1,rand2,0}
  42.  
  43.       elseif direction == 6 then
  44.  
  45.       signal = {-1,rand2,(-rand2)-1,0,-1,(-rand2)-1,rand2,0}
  46.  
  47.       else
  48.  
  49.       signal = {1,-rand2,-((-rand2)-1),0,-1,(-rand2)-1,rand2,0}
  50.  
  51.       end
  52.  
  53.    local pos = getThingPos(uid)
  54.  
  55.    nsig = #signal
  56.  
  57.    nvar = 0
  58.  
  59.    
  60.  
  61.    repeat
  62.  
  63.    nvar = nvar+1
  64.  
  65.    newpos = {x=pos.x+(signal[nvar]),y=pos.y+(signal[(nsig/2)+nvar]),z=pos.z}
  66.  
  67.    newtile = {x=newpos.x,y=newpos.y,z=newpos.z,stackpos=0}
  68.  
  69.    until getTileThingByPos(newtile).uid ~= 0 and hasProperty(getTileThingByPos(newtile).uid,3) == FALSE and canWalkOnPos(newtile, true, false, true, true, false) and queryTileAddThing(uid,newpos) == 1 or nvar == (nsig/2)
  70.                                                                                                                         --alterado v2.5
  71.    
  72.  
  73.       if distance == nil or distance == 1 then
  74.  
  75.       doTeleportThing(uid,newpos,TRUE)  
  76.  
  77.       else
  78.  
  79.       distance = distance-1
  80.  
  81.       doTeleportThing(uid,newpos,TRUE)
  82.  
  83.          if time ~= nil then
  84.  
  85.          addEvent(doPushCreature,time,uid,direction,distance,time)
  86.  
  87.          else
  88.  
  89.          addEvent(doPushCreature,500,uid,direction,distance,500)
  90.  
  91.          end       
  92.  
  93.       end
  94.  
  95.    end  
  96.  
  97. end
  98.  
  99. function doComparePosition(pos1, pos2)
  100.     if pos1.x == pos2.x and pos1.y == pos2.y and pos1.z == pos2.z then
  101.     return true
  102.     end
  103. return false
  104. end
  105.  
  106. function getNextStepDelay(cid, dir)
  107.     return 868
  108. end
  109.  
  110. function walkTo(cid, direction, finalp, useExtraMoveOrder)
  111.     if not isCreature(cid) then return true end
  112.  
  113.     doChangeSpeed(cid, 5)
  114.     local x = getThingPos(cid)
  115.     local ratedelaywalk = 1
  116.     local finalpos = {x = finalp.x, y = finalp.y, z = finalp.z}
  117.  
  118.         if not canWalkOnPos(finalpos, false, false, true, true, true) then
  119.             finalpos = getClosestFreeTile(cid, finalpos)
  120.         end
  121.  
  122.         if not finalpos then
  123.         return false
  124.         end
  125.  
  126.     local dir = getDirectionTo(getThingPos(cid), finalpos)
  127.     if dir and tonumber(dir) ~= nil and tonumber(dir) >= 0 and tonumber(dir) <= 7 then
  128.         if dir >= 4 then
  129.             ratedelaywalk = 0.4
  130.         end
  131.         doPushCreature(cid, dir, 1, getNextStepDelay(cid, dir) * ratedelaywalk)
  132.         return getNextStepDelay(cid, dir) * ratedelaywalk
  133.     elseif useExtraMoveOrder then
  134.  
  135. local random = math.random(1, 2)
  136.  
  137.     for ta = 1, 3 do
  138.         for tb = 1, #dirpref[random][direction][ta] do
  139.             local y = getPosByDir(getThingPos(cid), dirpref[random][direction][ta][tb])
  140.             local w = getCreatureLP(cid)
  141.             local z = getDirectionTo(y, getThingPos(cid)) -- direção q vai marcar
  142.             local j = getDirectionTo(getThingPos(cid), y) -- direção q ele vai
  143.             if canWalkOnPos(y, true, false, true, true, true) and w ~= j then
  144.                 if dirpref[random][direction][ta][tb] >= 4 then
  145.                     ratedelaywalk = 0.5
  146.                 end
  147.                 doPushCreature(cid, dirpref[random][direction][ta][tb], 1, getNextStepDelay(cid, dirpref[random][direction][ta][tb]) * ratedelaywalk)
  148.                 markLP(cid, z)
  149.             return getNextStepDelay(cid, dirpref[random][direction][ta][tb]) * ratedelaywalk
  150.             end
  151.         end
  152.     end
  153.     end
  154. return false
  155. end
  156.  
  157. function getCreatureLP(cid)
  158. return getPlayerStorageValue(cid, 197)
  159. end
  160.  
  161. function markLP(cid, dir)
  162. setPlayerStorageValue(cid, 197, dir)
  163. end
  164.  
  165. function markPos(sid, pos)
  166. if not isCreature(sid) then return end
  167. setPlayerStorageValue(sid, 145, pos.x)
  168. setPlayerStorageValue(sid, 146, pos.y)
  169. setPlayerStorageValue(sid, 147, pos.z)
  170. end
  171.  
  172. function markFlyingPos(sid, pos)
  173. if not isCreature(sid) then return end
  174. setPlayerStorageValue(sid, 33145, pos.x)
  175. setPlayerStorageValue(sid, 33146, pos.y)
  176. setPlayerStorageValue(sid, 33147, pos.z)
  177. end
  178.  
  179. function getFlyingMarkedPos(sid)
  180. if not isCreature(sid) then return end
  181. local xx = getPlayerStorageValue(sid, 33145)
  182. local yy = getPlayerStorageValue(sid, 33146)
  183. local zz = getPlayerStorageValue(sid, 33147)
  184. return {x = xx, y = yy, z = zz, stackpos = 0}
  185. end
  186.  
  187. function getMarkedPos(sid)
  188. if not isCreature(sid) then return end
  189. local xx = getPlayerStorageValue(sid, 145)
  190. local yy = getPlayerStorageValue(sid, 146)
  191. local zz = getPlayerStorageValue(sid, 147)
  192. return {x = xx, y = yy, z = zz}
  193. end
  194.  
  195. function getOwnerPos(sid)
  196. if not isCreature(sid) then return end
  197. local xx = getPlayerStorageValue(sid, 148)
  198. local yy = getPlayerStorageValue(sid, 149)
  199. local zz = getPlayerStorageValue(sid, 150)
  200. return {x = xx, y = yy, z = zz}
  201. end
  202.  
  203. function markOwnerPos(sid, pos)
  204. if not isCreature(sid) then return end
  205. setPlayerStorageValue(sid, 148, pos.x)
  206. setPlayerStorageValue(sid, 149, pos.y)
  207. setPlayerStorageValue(sid, 150, pos.z)
  208. end
  209.  
  210. function recheck(sid, skill, pos)
  211.     if not isCreature(sid) then return end
  212.     local cid = getCreatureMaster(sid)
  213.  
  214.     if skill == "cut" then
  215.  
  216.         local item = getTileItemById(pos, 2767)
  217.         doCreatureSay(sid, "CUT!", TALKTYPE_MONSTER)
  218.         markPos(sid, {x=1,y=1,z=7})
  219.         doFaceCreature(sid, pos)
  220.         doSendMagicEffect(getThingPos(item.uid), 141)
  221.         doTransformItem(item.uid, 6216)
  222.             local function growBush()
  223.             doTransformItem(getTileItemById(pos, 6216).uid, 2767)
  224.             end
  225.         addEvent(growBush, intervalToRegrowBushAndStones * 1000)
  226.  
  227.     elseif skill == "rock smash" then
  228.  
  229.         local item = getTileItemById(pos, 1285)
  230.         doCreatureSay(sid, "ROCK SMASH!", TALKTYPE_MONSTER)
  231.         markPos(sid, {x=1,y=1,z=7})
  232.         doFaceCreature(sid, pos)
  233.         doSendMagicEffect(getThingPos(item.uid), 118)
  234.         doTransformItem(item.uid, 3610)
  235.             local function growRock()
  236.             doTransformItem(getTileItemById(pos, 3610).uid, 1285)
  237.             end
  238.         addEvent(growRock, intervalToRegrowBushAndStones * 1000)
  239.        
  240.     elseif skill == "headbutt" then   --alterado v2.6
  241.    
  242.     local master = getCreatureMaster(sid)
  243.     local array = {}                          
  244.     local lvl = {25, 40, 60, 80, 1000} --lvls
  245.  
  246.     for i = 1, #lvl do
  247.         if getPlayerLevel(master) <= lvl[i] then
  248.            array = headbutt[lvl[i]]
  249.            break
  250.         end
  251.     end
  252.     local rand = array[math.random(#array)]
  253.     for j = 1, rand[2] do
  254.         local poke = doCreateMonster(rand[1], getClosestFreeTile(sid, pos))
  255.         doSetMonsterPassive(poke)              
  256.         doWildAttackPlayer(poke, master)
  257.     end
  258.     local item = getTileItemById(pos, 12591)    --id do item   arvore normal
  259.     doCreatureSay(sid, "HEADBUTT!", TALKTYPE_MONSTER)
  260.     markPos(sid, {x=1,y=1,z=7})
  261.     doFaceCreature(sid, pos)
  262.     doSendMagicEffect(getThingPos(item.uid), 118)
  263.     doTransformItem(item.uid, 12592)  --id do item   arvore quebrada
  264.     local function growHead()
  265.           doTransformItem(getTileItemById(pos, 12592).uid, 12591) --id do item  arvore quebrada, arvore normal
  266.     end
  267.     addEvent(growHead, choose(5, 10, 20, 30) * 60 * 1000)   --o tempo pra arvore voltar ao normal varia de 5~30min
  268.  
  269.     elseif skill == "dig" then
  270.  
  271.         local item = getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0})
  272.         doCreatureSay(sid, "DIG!", TALKTYPE_MONSTER)
  273.         markPos(sid, {x=1,y=1,z=7})
  274.         doFaceCreature(sid, pos)
  275.         doSendMagicEffect(getThingPos(item.uid), 3)
  276.         doTransformItem(item.uid, item.itemid+1)
  277.             local function closeHole()
  278.             doTransformItem(getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).uid, item.itemid)
  279.             end
  280.         addEvent(closeHole, intervalToRegrowBushAndStones * 1000)
  281.    
  282.     elseif skill == "fly" then
  283.    
  284.         --if not isPremium(cid) then
  285.         --doPlayerSendCancel(cid, "Only premium members are allowed to fly.")
  286.         --return true
  287.         --end
  288.         local pokemon = flys[getPokemonName(getCreatureSummons(cid)[1])]
  289.         doPlayerSendTextMessage(cid, 27, "Type \"up\" or \"h1\" to fly higher and \"down\" or \"h2\" to fly lower.")
  290.         doChangeSpeed(cid, -getCreatureSpeed(cid))
  291.         local speed = 500 + PlayerSpeed/5 + getSpeed(sid) * 6 * speedRate
  292.         doChangeSpeed(cid, speed)
  293.         setPlayerStorageValue(cid, 54844, speed)
  294.         doSetCreatureOutfit(cid, {lookType = pokemon[1] + 351}, -1)
  295.         doItemSetAttribute(getPlayerSlotItem(cid, 8).uid, "hp", getCreatureHealth(getCreatureSummons(cid)[1]) / getCreatureMaxHealth(getCreatureSummons(cid)[1]))
  296.         doRemoveCreature(getCreatureSummons(cid)[1])
  297.         setPlayerStorageValue(cid, 17000, 1)
  298.         if getCreatureOutfit(cid).lookType == 667 or getCreatureOutfit(cid).lookType == 999 then
  299.            markPosEff(cid, getThingPos(cid))
  300.            sendMovementEffect(cid, 136, getThingPos(cid))     --edited efeito quando anda com o porygon
  301.         end
  302.     return true
  303.  
  304.     elseif skill == "ride" then
  305.    
  306.         local pokemon = rides[getPokemonName(getCreatureSummons(cid)[1])]
  307.         doChangeSpeed(cid, -getCreatureSpeed(cid))
  308.         local speed = 150 + PlayerSpeed + getSpeed(sid) * 5 * speedRate
  309.         doChangeSpeed(cid, speed)
  310.         setPlayerStorageValue(cid, 54844, speed)
  311.         doSetCreatureOutfit(cid, {lookType = pokemon[1] + 351}, -1)
  312.         doItemSetAttribute(getPlayerSlotItem(cid, 8).uid, "hp", getCreatureHealth(getCreatureSummons(cid)[1]) / getCreatureMaxHealth(getCreatureSummons(cid)[1]))
  313.         doRemoveCreature(getCreatureSummons(cid)[1])
  314.         setPlayerStorageValue(cid, 17001, 1)
  315.  
  316.     return true
  317.     end
  318.  
  319.     if getOwnerPos(sid).x ~= getThingPos(getCreatureMaster(sid)).x or getOwnerPos(sid).y ~= getThingPos(getCreatureMaster(sid)).y or isCreature(getCreatureTarget(getCreatureMaster(sid))) then
  320.         doRegainSpeed(sid)
  321.         markPos(sid, {x=1,y=1,z=7})
  322.     return true
  323.     end
  324.  
  325.     addEvent(recheck, 120, sid)
  326. end
  327.  
  328. function goThere(sid, thepos, skill, target, rept)
  329.     if not isCreature(sid) then return true end
  330.     if getCreatureNoMove(sid) or isSleeping(sid) or isParalyze(sid) then return true end            --alterado v2.6
  331.     if thepos.x ~= getMarkedPos(sid).x or thepos.y ~= getMarkedPos(sid).y then return true end
  332.     if isCreature(getCreatureTarget(getCreatureMaster(sid))) and target == false or (rept and rept <= 0) then
  333.         doRegainSpeed(sid)
  334.         markPos(sid, {x=1,y=1,z=7})
  335.     return true
  336.     end
  337.  
  338. if (skill == "ride" or skill == "fly") and getDistanceBetween(getThingPos(sid), getMarkedPos(sid)) <= 1 then
  339.  
  340.     local currentPos = getThingPos(getCreatureMaster(sid))
  341.     local summonPos = getThingPos(sid)
  342.     local masterPos = getCreatureLastPosition(sid)
  343.  
  344.     if (getThingPos(sid).x == getThingPos(getCreatureMaster(sid)).x and getThingPos(sid).y == getThingPos(getCreatureMaster(sid)).y) or (currentPos.x == masterPos.x and currentPos.y == masterPos.y) then
  345.     recheck(sid, skill, thepos)
  346.     return true
  347.     end
  348.  
  349.     if currentPos.x == thepos.x and currentPos.y == thepos.y then
  350.         if getDirectionTo(getThingPos(sid), getThingPos(getCreatureMaster(sid))) <= 3 then
  351.             doRegainSpeed(sid)
  352.             local ndelay = getNextStepDelay(sid, 0)
  353.             doTeleportThing(sid, thepos, true)
  354.             doChangeSpeed(sid, -getCreatureSpeed(sid))
  355.             markPos(sid, getThingPos(getCreatureMaster(sid)))
  356.             addEvent(goThere, ndelay, sid, getMarkedPos(sid), skill, target)
  357.         else
  358.             doChangeSpeed(sid, - getCreatureSpeed(sid))
  359.             doRegainSpeed(sid)
  360.             markPos(sid, getThingPos(getCreatureMaster(sid)))
  361.             local x = walkTo(sid, getDirectionTo(getThingPos(sid), getMarkedPos(sid)), getMarkedPos(sid), skill == "ride" or skill == "fly")
  362.             doChangeSpeed(sid, - getCreatureSpeed(sid))
  363.             addEvent(goThere, x, sid, getMarkedPos(sid), skill, target)
  364.             end
  365.     return true
  366.     else
  367.         markPos(sid, getThingPos(getCreatureMaster(sid)))
  368.         doChangeSpeed(sid, - getCreatureSpeed(sid))
  369.         doRegainSpeed(sid)
  370.         local ndelay = getNextStepDelay(sid, 0)
  371.             if getDirectionTo(getThingPos(sid), getMarkedPos(sid)) >= 4 then
  372.                 local x = walkTo(sid, getDirectionTo(getThingPos(sid), getMarkedPos(sid)), getMarkedPos(sid), skill == "ride" or skill == "fly")
  373.             else
  374.                 doTeleportThing(sid, getPosByDir(getThingPos(sid), getDirectionTo(getThingPos(sid), getMarkedPos(sid))))
  375.             end
  376.         doChangeSpeed(sid, - getCreatureSpeed(sid))
  377.         addEvent(goThere, x and x or ndelay, sid, getMarkedPos(sid), skill, target)
  378.     return true
  379.     end
  380.  
  381. addEvent(recheck, 350, sid, skill, thepos)
  382. return true
  383. end
  384.  
  385. if getThingPos(sid).x == getMarkedPos(sid).x and getThingPos(sid).y == getMarkedPos(sid).y then
  386.     if isCreature(getCreatureTarget(sid)) then
  387.     doFaceCreature(sid, getThingPos(getCreatureTarget(sid)))
  388.     end
  389.     if skill == "blink" then
  390.        doChangeSpeed(sid, - getCreatureSpeed(sid))   --edited blink
  391.     end
  392. addEvent(recheck, 350, sid, skill, thepos)
  393. return true
  394. end
  395.  
  396. if (getOwnerPos(sid).x ~= getThingPos(getCreatureMaster(sid)).x or getOwnerPos(sid).y ~= getThingPos(getCreatureMaster(sid)).y) and isCreature(getCreatureTarget(getCreatureMaster(sid))) == false and skill == "move" then
  397. doRegainSpeed(sid)
  398. markPos(sid, {x=1,y=1,z=7})
  399. return true
  400. end
  401.  
  402. doRegainSpeed(sid)
  403.  
  404. local holeid = thepos
  405. holeid.stackpos = 0
  406. holeid = getTileThingByPos(holeid).itemid
  407.  
  408. if getDistanceBetween(getThingPos(sid), getMarkedPos(sid)) <= 1 and (not isWalkable(getPosByDir(getThingPos(sid), getDirectionTo(getThingPos(sid), getMarkedPos(sid))), true, false, false, true) or isInArray(specialabilities["digholes"], holeid)) then
  409.     if isGhostPokemon(sid) and getPlayerStorageValue(getCreatureMaster(sid), 990) <= 0 then
  410.         local todir = getDirectionTo(getThingPos(sid), getMarkedPos(sid))
  411.         if todir <= 3 then
  412.             doTeleportThing(sid, getMarkedPos(sid), true)
  413.         else
  414.             local gotopos = getPosByDir(getThingPos(sid), dirpref[math.random(1, 2)][todir][1][math.random(1, 2)])
  415.             doTeleportThing(sid, gotopos, true)
  416.             addEvent(goThere, getNextStepDelay(sid, 0), sid, getMarkedPos(sid), skill, target)
  417.             return true
  418.         end
  419.     end
  420. doFaceCreature(sid, getMarkedPos(sid))
  421. addEvent(recheck, 180, sid, skill, thepos)
  422. doChangeSpeed(sid, - getCreatureSpeed(sid))
  423. return true
  424. end
  425.  
  426. local ret = 0
  427.     if getDistanceBetween(getThingPos(sid), getMarkedPos(sid)) <= 1 then
  428.         ret = walkTo(sid, getDirectionTo(getThingPos(sid), getMarkedPos(sid)), getMarkedPos(sid), skill == "ride" or skill == "fly" or isGhostPokemon(sid))
  429.         if not tonumber(ret) then
  430.             doFaceCreature(sid, getMarkedPos(sid))
  431.             addEvent(recheck, 180, sid, skill, thepos)
  432.             doChangeSpeed(sid, - getCreatureSpeed(sid))
  433.         return true
  434.         end
  435.     else
  436.         ret = walkTo(sid, getDirectionTo(getThingPos(sid), getMarkedPos(sid)), getMarkedPos(sid), skill == "ride" or skill == "fly" or not isGhostPokemon(sid))-- and isSightClear(getThingPos(sid), getMarkedPos(sid), false)))
  437.     end
  438.  
  439. if not tonumber(ret) then
  440. doPlayerSendCancel(getCreatureMaster(sid), "Destination is not reachable.")
  441. markPos(sid, {x=1,y=1,z=7})
  442. return true
  443. end
  444.  
  445. doChangeSpeed(sid, - getCreatureSpeed(sid))
  446. addEvent(goThere, tonumber(ret), sid, getMarkedPos(sid), skill, target, rept and rept - 1 or 22)
  447. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement