Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local BoxX, BoxY, BoxZ = 70, 70, 3 -- 70*70*6 box around the spawn point
- local function RandomMovement(unit)
- local x,y = (math.random()*BoxX)-(BoxX/2)+unit:GetSpawnX(), (math.random()*BoxY)-(BoxY/2)+unit:GetSpawnY() -- get random X and Y inside our box around the original spawnpoint
- local z = unit:GetLandHeight(x, y) -- gets z position at given coords
- if(z > unit:GetSpawnZ()+BoxZ or z < unit:GetSpawnZ()-BoxZ) then -- check that height is not too much or else the NPC will fly etc
- RandomMovement(unit) -- was too high or too low, retry [stack overflow incase no good spot found, do not use in midair or non map spawning platform]
- else
- unit:MoveTo(x, y, z, 0) -- move the NPC to the coordinates
- end
- end
- local function OnSpawn(unit, event)
- unit:RemoveEvents()
- unit:RegisterEvent(RandomMovement, 3000, 0) -- On spawn start moving randomly
- end
- RegisterUnitEvent(NPCENTRY, 18, OnSpawn)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement