View Full Version : [SOLVED] Despawning GameObjects during boss fight (and other errors)

08-28-2015, 03:57 PM
So I'm trying to create a bossfight in which there will spawn flames under random players that deals x amount of damage every second the player stand in the flame. So what I've done is I've created a gameobject with the same type as the Campfire flames (6 - Trap) and added my spell to it. The gameobject works perfectly and does damage whenever someone comes into the radius.

The problem I'm having currently is the despawning of the object once the fight is over. It doesn't seem to be working. I have

SummonList summons;

and then

void Reset();

But it does not seem to be working, only the spawned creatures are despawning, not the gameobjects.

And while I'm making a thread, I might as well ask if anyone has any idea how to select random players that are in combat with the boss and cast this spell on, say, 5 of them at once without having it cast the spell twice on any player, which is what my code is currently doing (sometimes it will cast all 5 fires on one player or 2 on 1 and 3 on another and so on).

What I currently have is:

for (uint64 i = 0; i < 5; i = i+1)
if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 0.0f, true))
me->SummonGameObject(100050, target->GetPositionX(), target->GetPositionY(), target->GetPositionZ(), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0);

As you can see there's no check to see if the spell has already been cast on the target, because I have no clue how to do that :)

Full code for anyone interested:

08-28-2015, 05:16 PM
Issue solved, for anyone else who wants to do something similar here is how I fixed it:
For the flame I used SendTargetList instead of SelectTarget.
This is how it looks now:

std::list<Unit*> targets;
SelectTargetList(targets, 5, SELECT_TARGET_RANDOM, 100, true);
for (std::list<Unit*>::const_iterator i = targets.begin(); i != targets.end(); ++i)
me->SummonGameObject(100050, (*i)->GetPositionX(), (*i)->GetPositionY(), (*i)->GetPositionZ(), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0);

Basically it adds all players on the aggro table in a 100 yards radius to a table, then goes through the table to cast the spell and it won't cast on the same player several times :)

As for the despawning of gameobjects. I used
me->RemoveAllGameObjects(); as it deletes all gameobjects with references to the creature :)