Game Development Community

How to Add Multipe AI Player

by CloudFire · in Torque Developer Network · 11/27/2009 (7:20 am) · 12 replies


In my project i have to display multiple different ai players. I have replaced the kork ai player and i have to add more AI different player.I have already created different paths and dts.How can i display multipe AI Player?

#1
11/30/2009 (7:52 am)
I have replaced default ai player. I have new dts how i can create another new ai player?
#2
03/14/2010 (3:08 am)
I have the same question. Anyone could tell us how I can add another new AIPlayer?
#3
03/14/2010 (4:39 am)
function insertAnotherAIPlayer()
{
   new AIPlayer()
   {
      position = "0 0 0"; // or another position
      datablock = playerDB; // use the Datablock of the player...
                            // ...or create your own PlayerData-Datablock
   };
}

#4
03/14/2010 (4:46 am)
If you want to try it with the console, simply type the same in post #3 into one line.

new AIPlayer() {position = "0 0 0"; datablock = playerDB; };
#5
03/18/2010 (11:18 am)
Which project is this? Is this a demo kit or starter kit we can download?
#6
03/25/2010 (9:19 am)
@Thomas Bang i have created new datablock.and i have add new object in AIManager. But when i execute the game second ai player it is not spawning on the path . Only the default ai player is spawning on the two paths.
How can i spawn the new aiplayer in the new path

shall i have to change any code for spawn the new ai player in new path.

Thanks in advance
#7
03/25/2010 (7:06 pm)
I would suggest you read aiPlayer.cs

At the bottom of the file (at least in TGEA) there is the function,

function AIManager::spawn(%this)
{
   %player = AIPlayer::spawnOnPath("Kork","MissionGroup/Paths/Path1");
   
   if (isObject(%player))
   {
      %player.followPath("MissionGroup/Paths/Path1",-1);
      return %player;
   }
   else
      return 0;
}

That is the code you are looking for, you can duplicate that or if you understand about loops and scripting enough rebuild it to spawn as many AI bots as you want.
#8
03/26/2010 (4:55 am)
@joseph Jonathan Thank You for your reply .

I am using torque 3d demo.

I have applied your method. but i did not get the new aiplayer running . I have properly exec the databloc also.

In both path demo player(default player) is running.

i dont know why the new ai player is not running.

shall i have to make any change in gamecore.cs or in anything to run the new ai player.




#9
03/28/2010 (1:14 am)
shall i have to change in gamecore.cs to spawn a second ai player

#10
03/28/2010 (6:22 am)
I really don't know about T3D but if you duplicate AIManager::spawn(%this)
you would have to call function AIManager::spawn2(%this) (or whatever you called it) right after AIManager::spawn(%this) was called. In TGEA it is in AIManager::think.

Here is how I would edit it:
function AIManager::think(%this)
{
   // We could hook into the player's onDestroyed state instead of
   // having to "think", but thinking allows us to consider other
   // things...
   if (!isObject(%this.player))
      %this.player = %this.spawn();

   //This checks if there is already a player2 part of the AI system.
   if (!isObject(%this.player2))
      %this.player2 = %this.spawn2();

   %this.schedule(500,think);
}

And then for the second spawn function I would make it,

function AIManager::spawn2(%this)
{
   %player2 = AIPlayer::spawnOnPath("Kork Jr","MissionGroup/Paths/Path2");
   
   if (isObject(%player2))
   {
      %player2.followPath("MissionGroup/Paths/Path2",-1);
      return %player2;
   }
   else
      return 0;
}

hopefully that helps you get a start.
#11
03/31/2010 (9:37 pm)
@joseph jonathan Thank you for your help. Your idea was helped me to get the second ai player.

i have passed the function like this .

function AIPlayer::spawnOnPath(%name,%path)
{
// Spawn a player and place him on the first node of the path

if (!isObject(%path))
return 0;
%node = %path.getObject(0);

if(%name $="shootme")
{

%player = AIPlayer::spawn(%name, %node.getTransform());
return %player;
}
if(%name $="Kork Jr")
{
%player2 = AIPlayer::spawn2(%name, %node.getTransform());
return %player2;
}

}

the player is running.
#12
04/07/2010 (4:59 am)
function spawnWhoever(%datablock,%path)   
{   
   %player = spawnWhoeverOnPath(%datablock,%path);   
      
   if (isObject(%player))   
   {   
      %player.followPath(%path,-1);   
      return %player;   
   }   
   else  
      return 0;   
}
...should spawn who ever on what ever path and can be called when ever from where ever.