Game Development Community

Turning standard ai player into a actual player...

by Max Thomas · in Torque Game Engine · 10/22/2004 (7:19 am) · 19 replies

Hello,

I know this is a stupid question but I need the standars Ai player to come up as an actual player. So I want to have it when a aiplayer kills me for it to say "player gets nailed by kork!" instead of "player gets nailed by !" also I want to have it so when I hit F2 to see the scores I want to have all the bots come up as players.

Thanks, Max ;)

#1
10/22/2004 (7:38 am)
All you have to do is add those fields into the creation function of the bot in script, and then you can do all those things. For the name, it sounds like maybe it wasn't accessed correctly if nothing is showing up.
#2
10/22/2004 (11:18 am)
Yeah I understand that but I couldn't find any problems calling the name funcion. I'm useing aiplayer not aiclient could that be one of the problems? Could you give me an example pleease?

I'm using this code do spawn the bots on there waypoints.

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.schedule(500,think);
}

function AIManager::spawn(%this)
{
//player3
%player = AIPlayer::spawnOnPath("bot3","MissionGroup/Paths/Path3");
%player.followPath("MissionGroup/Paths/Path3",-1);

%player.mountImage(ShotgunImage,0);
%player.setInventory(ShotgunAmmo,100000);

//player2
%player = AIPlayer::spawnOnPath("bot2","MissionGroup/Paths/Path2");
%player.followPath("MissionGroup/Paths/Path2",-1);

%player.mountImage(CrossbowImage,0);
%player.setInventory(CrossbowAmmo,100000);

//player1
%player = AIPlayer::spawnOnPath("bot1","MissionGroup/Paths/Path1");
%player.followPath("MissionGroup/Paths/Path1",-1);

%player.mountImage(LauncherImage,0);
%player.setInventory(LauncherAmmo,100000);

return %player;
}

Thanks, Max
#3
10/22/2004 (11:24 am)
To get this working with the least code changes, you need to create an AIConnection, then add your bot to it (like %conn.player = %mybot). There's a function called aiConnect or aiClient which will almost work. I had to add a few more calls within that function in the engine to make it work. When I get home, I'll post up the changes for you.
#4
10/22/2004 (11:40 am)
AIClient is what you want actually.
#5
10/22/2004 (12:39 pm)
Thanks guys,

Yeah I thought that ai client was what I was going to need. I have yet to try it with ai client but I'll wait to see what you guys post.
#6
10/22/2004 (5:59 pm)
Anyone? Anyone? I really need help on this as soon as possible.

Thanks, Max
#7
10/23/2004 (8:15 am)
Actually, I'm using aiConnect. I added these lines after aiConnection->registerObject() in aiConnection.cc

aiConnection->setGhostFrom(true);
   aiConnection->setGhostTo(false);
   aiConnection->setSendingEvents(true);
   aiConnection->setTranslatesStrings(true);

In script, do the following:
for (%i = 0; %i < $Game::numAIPlayers; %i++) 
      $BotConnection = aiConnect("MasterBlaster" @ %i, -1, 0.5, false, "SDF", 1.0);
#8
10/23/2004 (9:27 am)
None of this is neccesary to achieve what he wanted originally.

First in GameConnection::onDeath find the following block of code....


// Doll out points and display an appropriate message
   if(%damageType $= "Suicide" || %sourceClient == %this)
   {
      %this.incScore(-1);
      messageAll('MsgClientKilled','%1 takes his own life!',%this.name);
   }
   else
   {
      %sourceClient.incScore(1);
      messageAll('MsgClientKilled','%1 gets nailed by %2!',%this.name,%sourceClient.name);
      if(%sourceClient.score >= $Game::EndGameScore)
         cycleGame();
   }


Modify it as follows....


// Doll out points and display an appropriate message
   if(%damageType $= "Suicide" || %sourceClient == %this)
   {
      %this.incScore(-1);
      messageAll('MsgClientKilled','%1 takes his own life!',%this.name);
   }
   else
   {
	if(!%sourceClient)  //  If no source client, chances are it's a bot
	{
		%bot = %sourceObject.sourceObject;
		
		if(%bot.getClassName() $= "AIPlayer")
		{
      		        messageAll('MsgClientKilled','%1 gets nailed by %2!',%this.name,%bot.getShapeName());
                        //  Add in scoring for the bots if you need it at this point
                }
                else
                {
			// some other object like a turret at work here.
		}
	}
	else
	{
		%sourceClient.incScore(1);
		messageAll('MsgClientKilled','%1 gets nailed by %2!',%this.name,%sourceClient.name);
		if(%sourceClient.score >= $Game::EndGameScore)
			cycleGame();
	}
   }

This will insure that the bot that killed you(Kork) gets credit for his kill. And if you need him to, you could score a kill for him as well, just add in what you need.

To get the bots on your player list all you need to do insert the following into the function you are using to spawn the bot after it has spawned. Assuming your using %bot then it would look like this....


messageAll('MsgClientJoin', '%1 is ready for combat.', %bot.getShapeName(), %bot, %bot, 0);


Nothing to it! That will give you exactly what you wanted and you don't even have to mess with the AI client stuff or even heavily modify the scripts to get it.
#9
10/23/2004 (9:33 am)
Thanks,

One quick question though where do I put this line?

for (%i = 0; %i < $Game::numAIPlayers; %i++)
$BotConnection = aiConnect("MasterBlaster" @ %i, -1, 0.5, false, "SDF", 1.0);

do I put that in aiplayer.cs or in aiConnection.cc after the first segment of code? Sorry for my stupidity.

Thanks, Max
#10
10/23/2004 (9:52 am)
Thanks Gonzo, question though is this what the aimanager should look like then or does this messageAll('MsgClientJoin', '%1 is ready for combat.', %bot.getShapeName(), %bot, %bot, 0); line go somewhere else please help me. ;)

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.schedule(500,think);
}

function AIManager::spawn(%this)
{
//player1
%player = AIPlayer::spawnOnPath("bot1","MissionGroup/Paths/Path1");
%player.followPath("MissionGroup/Paths/Path1",-1);
messageAll('MsgClientJoin', '%1 is ready for combat.', %bot.getShapeName(), %bot, %bot,0);

%player.mountImage(LauncherImage,0);
%player.setInventory(LauncherAmmo,100000);

return %player;
}
#11
10/23/2004 (10:28 am)
Function AIManager::spawn(%this)
{
//player1
%player = AIPlayer::spawnOnPath("bot1","MissionGroup/Paths/Path1");
%player.followPath("MissionGroup/Paths/Path1",-1);

messageAll('MsgClientJoin', '%1 is ready for combat.', %player.getShapeName(), %player, 0);

%player.mountImage(LauncherImage,0);
%player.setInventory(LauncherAmmo,100000);

return %player;
}
#12
10/23/2004 (10:44 am)
Ok, this is reall wierd with the little line of code there it won't spawn a single bot and tons of errors come up. Any idea why? Actuall Gonzo can you please send me the game.cs and aiplayer.cs because I have no Idea whats happinin. thomasmax@comcast.net

Thanks, Max :(
#13
10/23/2004 (11:03 am)
LOL, not a chance. My AI development is waaaaaaaaaaaaaaaaayyyyy beyond what comes stock with TGE and I'm not about to GIVE it away yet. Sorry, but I put a lot of work into it and it's some extremely well written code. Toot Toot!!!

your problem is these....

'


replace each of those with the one right next to your Enter key

or try this line to see if it will work....

messageAll('MsgClientJoin', '%1 is ready for combat.', %player.getShapeName(), %player, 0);


Always keep in mind when you copy paste code from these forums that you pay attention to those apostrophes and replace them or you'll get errors, the ones the forum displays are not the same as the ones on your keyboard(don't ask me why, I don't know)


If that doesn't work, you can send me your AiPlayer.cs and I'll make sure it's fixed for you.
#14
10/23/2004 (11:12 am)
Yeah I changed those and still nuthin. Wail why won't it work! Well, Here are my two bits of code tell me whats wrong please.

aiplayer.cs we have this.

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.schedule(500,think);
}

function AIManager::spawn(%this)
{
//player1
%player = AIPlayer::spawnOnPath("bot1","MissionGroup/Paths/Path1");
%player.followPath("MissionGroup/Paths/Path1",-1);

messageAll('MsgClientJoin', '%1 is ready for combat.', %player.getShapeName(), %player, 0);

%player.mountImage(LauncherImage,0);
%player.setInventory(LauncherAmmo,100000);

return %player;
}


and game.cs we have this.

function GameConnection::onDeath(%this, %sourceObject, %sourceClient, %damageType, %damLoc)
{
// Clear out the name on the corpse
%this.player.setShapeName("");

// Switch the client over to the death cam and unhook the player object.
if (isObject(%this.camera) && isObject(%this.player)) {
%this.camera.setMode("Corpse",%this.player);
%this.setControlObject(%this.camera);
}
%this.player = 0;

// Doll out points and display an appropriate message
if(%damageType $= "Suicide" || %sourceClient == %this)
{
%this.incScore(-1);
messageAll(´MsgClientKilled´,´%1 takes his own life!´,%this.name);
}
else
{
if(!%sourceClient) // If no source client, chances are it´s a bot
{
%bot = %sourceObject.sourceObject;

if(%bot.getClassName() $= "AIPlayer")
{
messageAll(´MsgClientKilled´,´%1 gets nailed by %2!´,%this.name,%bot.getShapeName());
// Add in scoring for the bots if you need it at this point
}
else
{
// some other object like a turret at work here.
}
}
else
{
%sourceClient.incScore(1);
messageAll(´MsgClientKilled´,´%1 gets nailed by %2!´,%this.name,%sourceClient.name);
if(%sourceClient.score >= $Game::EndGameScore)
cycleGame();
}
}

help me please *wails*

Thanks, Max :)
#15
10/23/2004 (11:16 am)
Oopsey doubble post. ;)
#16
10/23/2004 (11:17 am)
Gah another one.
#17
10/23/2004 (11:18 am)
Gonzo, I have sent you the two files aiplayer.cs and game.cs.

Thanks, Max
#18
01/31/2005 (8:03 pm)
Someone should add Brian's code changes to the official engine. Without them, AIConnect crashes. At least, it did for me. I'm repeating them here:

aiConnection->setGhostFrom(true);
   aiConnection->setGhostTo(false);
   aiConnection->setSendingEvents(true);
   aiConnection->setTranslatesStrings(true);

after aiConnection->registerObject() in aiConnection.cs.

Thanks Brian!
#19
06/08/2005 (2:42 pm)
Great thread, addresses 2 much needed functions. Thanks.

Although I noticed that although my bots were added to the score board as shown above, they still are not getting credit for their kills.