daily pastebin goal
43%
SHARE
TWEET

Untitled

a guest Feb 17th, 2017 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Creature.move(self, direction)
  2.     return doMoveCreature(self:getId(), direction)
  3. end
  4.  
  5. --// CONFIG
  6. local waypoints = {
  7.     Position(1010, 1000, 7),
  8.     Position(1000, 1000, 7)
  9. }
  10.  
  11. local moveSpeed = 300
  12. local walkSpeed = 280 -- Millisecond interval each step
  13. local storage = 99999 -- Storage value used to search player targets
  14. --\\
  15.  
  16. local moving = {} -- Store waypoint index data for each creature moving
  17. local teams = {} -- Store minion team data
  18.  
  19. local function searchPlayerTarget(creature)
  20.     local specs = Game.getSpectators(creature:getPosition(), false, true, 7, 7, 5, 5)
  21.     if (#specs > 0) then
  22.         local teamId = teams[creature:getId()]
  23.         for i = 1, #specs do
  24.             local player = specs[i]
  25.             if (player:getStorageValue(storage) ~= teamId) and not player:getGroup():getAccess() then
  26.                 creature:addTarget(player)
  27.                 return player
  28.             end
  29.         end
  30.     end
  31. end
  32.  
  33. local function searchMonsterTarget(creature)
  34.     local specs = Game.getSpectators(creature:getPosition(), false, false, 4, 4, 4, 4)
  35.     if (#specs > 0) then
  36.         local teamId = teams[creature:getId()]
  37.         local teamIdEx = teams[thing:getId()]
  38.         for i = 1, #specs do
  39.             local thing = specs[i]
  40.             if thing:isMonster() and (teamIdEx and (teamId ~= teamIdEx)) and (thing:getId() ~= creature:getId()) then
  41.                 creature:addTarget(thing)
  42.                 return thing
  43.             end
  44.         end
  45.     end
  46. end
  47.  
  48. local function walkPath(cid, path, i)
  49.     local creature = Creature(cid)
  50.     if not creature then
  51.         return
  52.     end
  53.  
  54.     --// Creature has finished the current path
  55.     i = i or 1
  56.     if i > #path then
  57.         executeWalk(creature)
  58.         return
  59.     end
  60.  
  61.     creature:move(path[i])
  62.    
  63.     --// Creature has found a player target
  64.     if searchPlayerTarget(creature) then
  65.         return
  66.     end
  67.  
  68.     --// Creature has found a monster target
  69.     if searchMonsterTarget(creature) then
  70.         return
  71.     end
  72.  
  73.     addEvent(walkPath, walkSpeed, cid, path, i+1)
  74. end
  75.  
  76. local function executeWalk(creature)
  77.     if creature:getSpeed() ~= moveSpeed then
  78.         creature:changeSpeed(moveSpeed-creature:getSpeed())
  79.     end
  80.     local cid = creature:getId()
  81.     moving[cid] = (moving[cid] or 0) + 1
  82.  
  83.     --// Creature has reached last waypoint
  84.     if (moving[cid] > #waypoints) then
  85.         moving[cid] = nil
  86.         return
  87.     end
  88.  
  89.     local path = creature:getPathTo(waypoints[moving[cid]], 0, 0, true, true, 0)
  90.  
  91.     if not path then
  92.         return
  93.     end
  94.  
  95.     walkPath(creature:getId(), path)
  96. end
  97.  
  98. function spawnMinion(name, position, teamId)
  99.     local minion = Game.createMonster(name, position)
  100.     if minion then
  101.         teams[minion:getId()] = teamId
  102.         return executeWalk(minion)
  103.     end
  104.     return false
  105. end
RAW Paste Data
Top