Game Development Community

Killing AiSpawnpoints

by KevinG · in Torque Game Engine · 12/20/2005 (12:13 pm) · 3 replies

Basically we have a master(boss) bot(s) that has with him a hoard of smaller minion bots.
We have the spawnpoints attached to the master bot so it will continualy replentish any
minions that you kill.
We cant stop the minions from spawning after the master bot is destroyed, and we reallly
need to.


Can we/ How do we drop in a few lines of code that will simply stop spawning minions
once the related master bot is destroyed?

Any help, pointer, clues, tricks, tips, advice, bright alternative ideas to help us along?

Cheers,

KevinG

#1
12/20/2005 (4:32 pm)
You need to add code for your bot spawning to check the state of your master bot. Make each spawn point "aware" of the master bot so that your bot spawn code knows if the master bot is alive. I assume you keep track for your master bot using states in script like the "player" object. Also, you do not really need spawn points on your master bot. You could just have a think routine on your master bot that will stop thinking if it dies. I did that on a turret and I forgot to check for death. It kept firing but could not turn to aim. If you want to stay with your spawn locations then generate them dynamically, but put them is a special group under missioncleanup and in your spawn code for your master bot or whereever you spawn for just the master bots, put your code to spawn and check for life or death of each master or the master depending on how you do it.

For instance in the function that creates your master bot:
...
// this calls your think routine
%this.schedule(500, "think", %obj);  // where %this is the datablock and %obj is the object reference for the master bot 
%obj.spawnGroup = new SimGroup();  // remember this group
MIssioncleanup.add(%obj.spawnGroup); // put group is cleanup so it does not get saved with your mission file
// Add spawn points to %obj.spawnGroup
...

Now the think routine:
function BotDataBlockName::think(%obj)
{
   // check for bot death
   if (%obj.getState() $= "Dead")
      return;
   
   %this.schedule(500,"think",%obj);

   // process bot spawning and whatever else
   // get spawn points from %obj.spawnGroup using SImGroup methods to get each item in group and spawn a bot
}

Using the method above makes all spawn spheres relative to each bot. Also if your player dies then you can squash the SimGroup if needed. Notice that the bot will stop thinking if you do not recal schedule on it. Hence it really died.
#2
01/17/2006 (3:33 pm)
Thanks Frank!
That info was pivotal. We ended up crafting something a bit better for our specific situation,
but our little bots now spawn from our big bots---when big bot is killed: no more spawning!!


Cheers,

KevinG
#3
01/17/2006 (3:51 pm)
Just for the record, your approach is subject slight problems for better handling I would use...


if(!isObject(%obj) || "Dead" $= %obj.getState()){ return; }


This helps to not run a method call on an object which doesn't exist. Better to check for existance of a non permanant and then check its state if available.


Also, the half a second think rate is pretty heavy in regards to a constant running schedule and would be a worse resource hog if you encountered several "objects" that were running schedules. It will certainly work, but the time should definately be optimized to be as long as possible while achieving the desired effect.


Just a few cents for ya.

:)