Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Creature.move(self, direction)
- return doMoveCreature(self:getId(), direction)
- end
- --// CONFIG
- local waypoints = {
- Position(1010, 1000, 7),
- Position(1000, 1000, 7)
- }
- local moveSpeed = 300
- local walkSpeed = 280 -- Millisecond interval each step
- local storage = 99999 -- Storage value used to search player targets
- --\\
- local moving = {} -- Store waypoint index data for each creature moving
- local teams = {} -- Store minion team data
- local function searchPlayerTarget(creature)
- local specs = Game.getSpectators(creature:getPosition(), false, true, 7, 7, 5, 5)
- if (#specs > 0) then
- local teamId = teams[creature:getId()]
- for i = 1, #specs do
- local player = specs[i]
- if (player:getStorageValue(storage) ~= teamId) and not player:getGroup():getAccess() then
- creature:addTarget(player)
- return player
- end
- end
- end
- end
- local function searchMonsterTarget(creature)
- local specs = Game.getSpectators(creature:getPosition(), false, false, 4, 4, 4, 4)
- if (#specs > 0) then
- local teamId = teams[creature:getId()]
- local teamIdEx = teams[thing:getId()]
- for i = 1, #specs do
- local thing = specs[i]
- if thing:isMonster() and (teamIdEx and (teamId ~= teamIdEx)) and (thing:getId() ~= creature:getId()) then
- creature:addTarget(thing)
- return thing
- end
- end
- end
- end
- local function walkPath(cid, path, i)
- local creature = Creature(cid)
- if not creature then
- return
- end
- --// Creature has finished the current path
- i = i or 1
- if i > #path then
- executeWalk(creature)
- return
- end
- creature:move(path[i])
- --// Creature has found a player target
- if searchPlayerTarget(creature) then
- return
- end
- --// Creature has found a monster target
- if searchMonsterTarget(creature) then
- return
- end
- addEvent(walkPath, walkSpeed, cid, path, i+1)
- end
- local function executeWalk(creature)
- if creature:getSpeed() ~= moveSpeed then
- creature:changeSpeed(moveSpeed-creature:getSpeed())
- end
- local cid = creature:getId()
- moving[cid] = (moving[cid] or 0) + 1
- --// Creature has reached last waypoint
- if (moving[cid] > #waypoints) then
- moving[cid] = nil
- return
- end
- local path = creature:getPathTo(waypoints[moving[cid]], 0, 0, true, true, 0)
- if not path then
- return
- end
- walkPath(creature:getId(), path)
- end
- function spawnMinion(name, position, teamId)
- local minion = Game.createMonster(name, position)
- if minion then
- teams[minion:getId()] = teamId
- return executeWalk(minion)
- end
- return false
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement