[DiscordArchive] Can anyone give me some pointers on how to achieve this: i want to check all the time if there is an
[DiscordArchive] Can anyone give me some pointers on how to achieve this: i want to check all the time if there is an
Archived author: Linguster • Posted: 2024-04-09T12:14:01.347000+00:00
Original source
Can anyone give me some pointers on how to achieve this: i want to check all the time if there is any hostile NPCs within 30 yards and if so, cast a spell on them every 10 seconds. Somehow done on ::Update so the spell cast is forced server side. Does that make sense?
Archived author: stoneharry • Posted: 2024-04-09T12:42:45.893000+00:00
Original source
```lua
local function NearbyHostileNpcCheck(_, _, _, pUnit)
-- See doc: https://elunaluaengine.github.io/WorldOb...Range.html
for _,v in pairs(pUnit:GetCreaturesInRange( range, entryId, hostile )) do
pUnit:CastSpell(v, spellId)
end
end
local function OnSpawn(_, pUnit)
pUnit:RegisterEvent(NearbyHostileNpcCheck, 10000, 0)
end
RegisterCreatureEvent(npcid, CREATURE_EVENT_ON_SPAWN, OnSpawn)
```