[DiscordArchive] Any reason why you don't just have a timed event tied to the creatures on spawn that checks for thei
[DiscordArchive] Any reason why you don't just have a timed event tied to the creatures on spawn that checks for thei
Archived author: Foe • Posted: 2022-04-24T10:26:13.116000+00:00
Original source
Any reason why you don't just have a timed event tied to the creatures on spawn that checks for their health?
Archived author: Foe • Posted: 2022-04-24T10:26:47.414000+00:00
Original source
That way you wouldn't have to deal with trying to find the objects at all
Archived author: Foe • Posted: 2022-04-24T10:27:40.389000+00:00
Original source
Then you just have a table with their status, and on your event end, you just check if the status reported by the creatures is correct
Archived author: Honey • Posted: 2022-04-24T10:28:05.167000+00:00
Original source
They could potentially die and their corpses despawn, depending on the server's settings. From what i understand, their events would be removed.
Archived author: Foe • Posted: 2022-04-24T10:28:36.670000+00:00
Original source
Their timed event, yes, but their status would then reflect in the status table as not successful still or whatever
Archived author: Foe • Posted: 2022-04-24T10:28:45.348000+00:00
Original source
And the event would fail
Archived author: Foe • Posted: 2022-04-24T10:28:56.462000+00:00
Original source
So it would serve the same purpose but a lot less complex
Archived author: Foe • Posted: 2022-04-24T10:29:55.011000+00:00
Original source
It would also not limit you to a hard coded amount of creatures, as the status table would be expanded dynamically on spawn
Archived author: Honey • Posted: 2022-04-24T10:30:31.887000+00:00
Original source
I'll try to think that over when i'm Back from my shopping trip. Appreciate the suggestions!
Archived author: Foe • Posted: 2022-04-24T11:47:24.505000+00:00
Original source
```Lua
local statusStore = {}
local eventActive = false
local function OnSpawn(event, creature)
-- initial status on spawn
statusStore[creature:GetGUIDLow()] = 0
-- register checking of health event every second
creature:RegisterEvent(OnTimedEvent, 1000, 0)
end
local function OnTimedEvent(eventid, delay, repeats, creature)
if(eventActive) then
if(creature:IsFullHealth())
statusStore[creature:GetGUIDLow()] = 1
end
else
creature:RemoveEvents()
-- add other despawn and deinit per creature stuff here
end
end
local function OnEventEnd()
eventActive = false
local eventCompleted = false
for _, creatureStatus in pairs(statusStore) do
if(creatureStatus == 0) then
eventCompleted = false
break
else
eventCompleted = true
end
end
-- Reset the creature status table
creatureStatus = {}
if(eventCompleted) then
-- do save event
else
-- do failure event
end
end```