Game Development Community

A Bot as a player?

by CodingChris · in Torque Game Engine · 12/23/2006 (12:09 am) · 13 replies

Hi,
For my new game there are lot's of bots driving against the player. They are wonderful drivers, but they aren't in
score table, because they aren't players. Now, now how to make them handled as players?

Hope for help.

#1
12/23/2006 (9:01 am)
What resource did you use for your bots? There many ways of doing this but not knowing how you have your bots setup I would be guess on how do this. You can put scoring system on death, ondamge or on the respawn.
#2
12/23/2006 (9:03 am)
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=8836
Is there no simple way to say this bot is now like a player?
#3
12/23/2006 (10:22 am)
They're not showing up in your scoreboard because they do not have a client connection. There's an aiConnect call which will create an ai connection which you can then connect with your bot. Much like the connection between a normal clientConnection and the %client.player variable.
#4
12/23/2006 (11:53 am)
And I only have to add a clientConnection to the bot? Could you give me a sample.
#5
12/23/2006 (11:58 am)
I have not play around with this resource but I will install it and see if my scoring system will work with it. If it does I will email it to you with instruction on how to install it. I will try and have something for you tonight.
#6
12/23/2006 (11:59 am)
Thank you.
#7
12/23/2006 (2:18 pm)
%botConnection = aiConnect("MasterBlaster" @ %i, -1, 0.5, false, "SDF", 1.0);

This will create the AI client connection and eventually call GameConnection::onClientEnterGame. This is where you have a switch based on if the connection is AI controlled. Here's an example:

function GameConnection::onClientEnterGame(%this)
{
  if (%this.isAIControlled()) {
    %this.player = MyFancyBotSpawningCode();
  } else {
    // spawn a normal player
  }
}
#8
12/23/2006 (2:51 pm)
That's making it alot more complicated for nothing, and is terribly hacky.

You need to check how the storyboard updates it's GUI. Basically, it iterates trough the client connection table and lists them. You could make a similiar table but with only AI players in it and iterate both, or just add both players and AI to a global score table which you update when they leave/join. Simple!

Indeed, the above suggested stuff (by Brian) will work, but you should be aware that you are adding alot of overhead and complexity which will limit your game's scalability later.
#9
12/23/2006 (6:39 pm)
I can't imagine why using the aiconnection for its intended purpose is hacky. ;) If I were abusing it for some other purpose, I'd be proud to call it a hack! ;)

I'm not really sure the impacts that the aiclientconnection should really have? I'd imagine it'd be fairly minimal. It might make walking the client connection list take a little longer, but other than that, what overhead does it bring?

The reason I went that route on a previous project was that all of the scoring code was tied to the connection. So if I didn't make the aiconnection, I'd have to have completely seperate sets of scoring code for AI vs. non-AI players. The aiconnection basically made the scripting code a lot simpler because I could handle ai and non ai players exactly the same.

Anyways, there are many options and you have to make your tradeoffs.
#10
12/24/2006 (1:08 am)
I think it would easier with the AIConnection, make a lap counter for the AI, the position and some other aspects are already done for the players. Why do all this again?
#11
12/24/2006 (1:30 am)
Now I've got the bot as player, but I have one problem:
But happens with this code:
before:
$Bot1 = CreateAIWheeledVehicle2("Herbie","CarPath",pickSpawnPoint());
MissionCleanup.Add($Bot1);
echo("Bot id: " @ $Bot1);
I made:
%botConnection = aiConnect("MasterBlaster" @ %i, -1, 0.5, false, "SDF", 1.0);
and what about this code:
before:
$Bot1.followPath("CarPath", -1);
$Bot1.lap = -1;
$Bot1.nextCheck = 1;

I made this:
%this.player.followPath("CarPath", -1);
%this.player.lap = -1;
%this.player.nextCheck = 1;
and now the bot doesn't drive along the path...
One last aspect: How to delete this connection with %botConnection.delete?
Anyone an idee?
#12
12/24/2006 (5:39 am)
Quote:
I can't imagine why using the aiconnection for its intended purpose is hacky. ;) If I were abusing it for some other purpose, I'd be proud to call it a hack! ;)

I never said using AIConnection for its intended purpose is hacky. What I said was that there is no reason to use AIConnection over AIPlayer just because you can't get the GUI to update properly. I'm not sure (considering the quote above) you knew, but there is a bit of a difference between the two classes. Basically, AIConnection is the core of GameConnection with AI slapped ontop. Like a dummy player. So using it is
not as lightweight as AIPlayer, which has no connection.

There are also scoping differences.

So yes, using AIConnection instead of AIPlayer in that case would be very hacky but a fast way to avoid the real issue. I'm just pointing out that there are better ways for the OP to approach the problem and if he strives to scale later then it might be a good idea to reconsider. Whether you want to is another topic entirely and is something I did not intend to discuss. :)

Edit: Clarification.
#13
12/24/2006 (5:59 am)
Oh, then it was my misstake, sorry.
Do you know how to change the code above, so that my bot is working?

Merry Christmas,
Christian