Game Development Community

Quick AI spawning question.

by Max Thomas · in Torque Game Engine · 04/04/2006 (1:35 pm) · 3 replies

Just somthing that seems simple enough thats been bothering me for the past few days. Heres an example of what I'm having a problem with. When "Kork1" dies, he isn't respawned untill "Kork2" is also dead, but if the player skips killing "Kork1" and goes strait to "Kork2" then another instance of "Kork1" is also spawned. I've tried multiple ways around this, but unfortunatly to no avail. I'm assuming it's somthing dumb and simple, just figured I'd ask here though.

Thanks, Max


function AIManager::spawn(%this)
{
%player = AIPlayer::spawnOnPath("Kork1","MissionGroup/Paths/Path1");
%player.followPath("MissionGroup/Paths/Path1",-1);
%player.mountImage(PistolImage,0);
%player.setInventory(PistolAmmo,12);

%player = AIPlayer::spawnOnPath("Kork2","MissionGroup/Paths/Path2");
%player.followPath("MissionGroup/Paths/Path2",-1);
%player.mountImage(PistolImage,0);
%player.setInventory(PistolAmmo,12);

return %player;
}


^ Just as an example

#1
04/04/2006 (8:53 pm)
Having the AIManager::spawn create both ai players everytime it is called is probably the issue. Rewrite the spawn method to be more reuseable.

You might start by creating an iniSpawn method which is only called at the beginning of the mission, and then another method to handle the re-spawn event.
#2
04/06/2006 (11:11 am)
Hey Brandon,

Thanks for the reply, it was kind of unexpected. :P

But I have been doing what you suggested, still to no avail. From bot counters checking the max number of bots and spawning more if there don't happen to be the correct number, to hacking appart resources and other whatnot in hopes of getting this working.

I supose I'll just keep on working on this for now, none the less any advice or examples are always greatly appreciated.

Thanks, Max
#3
04/07/2006 (9:22 am)
Ok, here is a very quick and dirty solution to get you going.. In your ./server/scripts/aiplayer.cs file:

Replace your AIPlayer::spawnOnPath with this:
function AIPlayer::spawnOnPath(%name,%path, %myNode)
{
   // Spawn a player and place him on the first node of the path
   if (!isObject(%path))
      return;
   %node = %path.getObject(%myNode);
   %player = AIPlayer::spawn(%name,%node.getTransform());
   return %player;
}


And replace your AIManager functions at the bottom with these:
function AIManager::init(%this, %totalAI)
{  
   if(%totalAI < 0 || %totalAI > 4) //Very rough temp testing validation
   {
      %totalAI = 1;
   }
     
   for( %i = 0; %i < %totalAI; %i++)
   {
      %myPlayer = %this.spawn(%i);
      %this.schedule(500, think, %i, %myPlayer);
   }
}

function AIManager::think(%this, %i, %myPlayer)
{
      if (!isObject(%myPlayer))
       %myPlayer = %this.spawn(%i);
      %this.schedule(500, think, %i, %myPlayer);
}

function AIManager::spawn(%this, %i)
{
   //Spawn bots with numerical name and at numerical node
   %player = AIPlayer::spawnOnPath(%i,"MissionGroup/Paths/Path1", %i);
  
   %player.followPath("MissionGroup/Paths/Path1",-1);

   %player.mountImage(CrossbowImage,0);
   %player.setInventory(CrossbowAmmo,1000);
   return %player;
}


Now change the AIManager function call around line 120 in the ./server/scripts/game.cs to this:
// Start the AIManager
   new ScriptObject(AIManager) {};
   MissionCleanup.add(AIManager);
   AIManager.init(3); //create 3 bots


This is just a quick example of what I was talking about in the previous post. This is not the best way to manage multiple bots, but it works given the existing aiplayer and datablock situation. Ideally you would want to create the AI players with there own datablocks, seperate the AIManager into it's own space, and possibily use a SimSet to manage the list of bots. This should get you going in the right direction though. I didn't test this much, but it did appear to work during the 1 minute that I tested it.. So, your mileage *will* vary! :)

B--