Making the bot a client
by Dane Nielsen · in Torque Game Engine · 09/02/2006 (1:08 am) · 28 replies
I'm new to Torque and over the past few days I have been looking through the fps starter kit. Now upon looking at scoring I have found that it keeps track of client scores. This makes it so bots aren't on the list and don't count for kills. I was wondering if there's a way to edit the code to make the bot a client. If someone would help me out it would really help me understand how this is writen alot better and also it would make it so I could easily add bots later if I wanted to.
Thanks
Thanks
#22
Very much thanking Martin, for his generosity and patience with scriptors of limited abilities!
Rex
09/05/2006 (9:13 am)
Martin: I'm serious, this should be a HowTo... It seems elegant in it's simplicity. As I said, I'd tried to create some bots thru a preexisting list and the scriptObject[seemed to be the TribesII methodology??], but my artisty-scripting abilities just weren't there yet. This schema seems to fill in the gaps. If this works correctly with the messaging system, I'd even purchase something like this. Also, this scriptObjecting things would seem to work with a much asked about PlayerSelection mode/gui...;)...create a scriptObject from a bunch of global variables in a gui..??...sound logical?Very much thanking Martin, for his generosity and patience with scriptors of limited abilities!
Rex
#23
Thanks, I was starting to doubt my sanity there for a minute, I thought I was right but new languages are always filled with unknowns and opprotunities for over confidence. ;)
Your solution was, not surprisingly, more elegant than mine but the process of tracking it down taught me a lot about scripting and script<->C++ code tracing and interaction and comparing my solution to yours will teach me some good stuff as well. I made some of my own changes to the bot/scoring in this thread and since these touch on one another I'll see about rolling these all up into a single package. I had noticed the body only damage reporting and the leg/body/arm/head damage suggestion is interesting so maybe I'll follow that up. (I always respect fps engines more that honor headshots.) I was also thinking about hooking up an "air" supply to the second meter and decrementing it when you are completely "underwater" and then inflicting damage when your "air" runs out would be an interesting and multi-layered problem.
Right now I'm just trying to learn the ropes so all this is good stuff. The AI section interests me as well but I think there are more things for me to figure out before I tackle that huge issue.
Thanks again,
=Tod
09/05/2006 (12:20 pm)
@TimThanks, I was starting to doubt my sanity there for a minute, I thought I was right but new languages are always filled with unknowns and opprotunities for over confidence. ;)
Your solution was, not surprisingly, more elegant than mine but the process of tracking it down taught me a lot about scripting and script<->C++ code tracing and interaction and comparing my solution to yours will teach me some good stuff as well. I made some of my own changes to the bot/scoring in this thread and since these touch on one another I'll see about rolling these all up into a single package. I had noticed the body only damage reporting and the leg/body/arm/head damage suggestion is interesting so maybe I'll follow that up. (I always respect fps engines more that honor headshots.) I was also thinking about hooking up an "air" supply to the second meter and decrementing it when you are completely "underwater" and then inflicting damage when your "air" runs out would be an interesting and multi-layered problem.
Right now I'm just trying to learn the ropes so all this is good stuff. The AI section interests me as well but I think there are more things for me to figure out before I tackle that huge issue.
Thanks again,
=Tod
#24
Edit: At first, AIClient was the only way to get AI in your game. As new versions of Torque were rolled out, it was replaced by AIPlayer. This is probably the reason why it is no longer used, its obsolete.
09/05/2006 (12:54 pm)
I think you guys should rethink your reasons for using AIClient. It is *alot* less efficent than AIPlayer.Edit: At first, AIClient was the only way to get AI in your game. As new versions of Torque were rolled out, it was replaced by AIPlayer. This is probably the reason why it is no longer used, its obsolete.
#25
Edit: Stefan: That's right. But for the game code handling it was very convinient to use the AIClient as it behaves exactly the same as the human connected player. For the AIPlayer stuff you need to write if / else branches. But hell yes, it is really really more efficient than the overhead of the AIClient. :-)
09/05/2006 (12:59 pm)
He he, right Stefan. That was another reason for me to do the fake client objects :)Edit: Stefan: That's right. But for the game code handling it was very convinient to use the AIClient as it behaves exactly the same as the human connected player. For the AIPlayer stuff you need to write if / else branches. But hell yes, it is really really more efficient than the overhead of the AIClient. :-)
#26
Bigtime. You have to have damage modifiers, head shots and location damage if you're making an fps and Torque supports it all, you just have to set it up right in script.
One of the first things I did with Torque was replace the scoring system. I have over 100 unique messages that will display, based on a simple random function, for a direct hit to another player, damage to yourself via falling, damage to yourself via shooting a weapon with radius damage carelessly, suicide, radius damage inflicted to other players etc all of which report weapon used, player names, bot names, damage location where applicable with bonus scores for head shots and the like.
I use the Tribes2 scripts as my bible most of the time. I'm hosting them on FileFront if you ever want to have a gander through them.
files.filefront.com/T2scriptsrar/;4847272;;/fileinfo.html
09/05/2006 (1:24 pm)
@ Tod Kuykendall,Bigtime. You have to have damage modifiers, head shots and location damage if you're making an fps and Torque supports it all, you just have to set it up right in script.
One of the first things I did with Torque was replace the scoring system. I have over 100 unique messages that will display, based on a simple random function, for a direct hit to another player, damage to yourself via falling, damage to yourself via shooting a weapon with radius damage carelessly, suicide, radius damage inflicted to other players etc all of which report weapon used, player names, bot names, damage location where applicable with bonus scores for head shots and the like.
I use the Tribes2 scripts as my bible most of the time. I'm hosting them on FileFront if you ever want to have a gander through them.
files.filefront.com/T2scriptsrar/;4847272;;/fileinfo.html
#27
I'm going to work thru Martin's example for the stock AIPlayer with my next free day...see what happens. I followed a system suggested by Gonzo[after seeing Martin's]...but that didn't work quite correctly. Martin's schema seems to have all the pieces in place...! I think it would be good to have this outlined...it seems to be one of the first AI questions...well, how to change body mesh is usually #1.
09/05/2006 (4:21 pm)
@Tim: do you use 'taunts'? I had a system setup to play a random .wav/.ogg file and print to ChatHud, the text of it...worked pretty good. Then I noticed that in TribesII[I own a few copies; one even unwrapped!], they seem to have the taunts arrive via the ChatHud system?? Do you utilize them in this manner? I've got the scripts for Classic and TribesII...both that came with the CD's I purchased. Some of the old DTS/DSQ files also work in STP...some don't.I'm going to work thru Martin's example for the stock AIPlayer with my next free day...see what happens. I followed a system suggested by Gonzo[after seeing Martin's]...but that didn't work quite correctly. Martin's schema seems to have all the pieces in place...! I think it would be good to have this outlined...it seems to be one of the first AI questions...well, how to change body mesh is usually #1.
#28
That is exactly how I do it.
09/06/2006 (9:27 am)
Quote:
Then I noticed that in TribesII[I own a few copies; one even unwrapped!], they seem to have the taunts arrive via the ChatHud system?? Do you utilize them in this manner?
That is exactly how I do it.
Torque Owner Martin Schultz
As I'm back home now, I could copy & paste now from my working code:
function makeABunchOfBots() { for (%i = 0; %i < 64; %i++) // do a random bot deployment somewhere within the next 10 seconds schedule(15000 * getRandom(), 0, "createBot", "Bot" SPC %i); } function createBot(%name) { if (%name $= "") %name = "Bot"; // create a fake client object (code handles the difference to a game connection client object!) // as we don't want real game connections for AI players. %so = new ScriptObject() { //player = %player; // our back reference - set later when spawning the bot. class = "AIObject"; // for our callbacks score = 0; name = %name; // give this little ai idiot a name :) aiObject = true; // for quick identification within ClientGroup.getObject(...) loops }; MissionCleanup.add(%so); ClientGroup.add(%so); // now spawn the bot. %bot = spawnBot(%so); %bot.setMoveDestination( %bot.getRandomBotMoveDestination() ); } function spawnBot(%aiObject) { %player = new AiEagleFlyingVehicle() { dataBlock = ScoutShip; ai = true; // checking later for this is mucho quicker than doing an isObject(player.aiObject) which is doing a lookup on the object aiObject = %aiObject; target = 0; action = 0; }; MissionCleanup.add(%player); // our back reference for the aiObject %aiObject.player = %player; // Player setup... %player.setTransform( pickSpawnPoint() ); %player.setShapeName(%aiObject.name); ... ... // set here the weapons etc. return %player; }Those are the dummy object functions that need to be there in case you add the fake AI client to the ClientConnection group like I did in the above example:
// ============================================================================= // Some fake functions to maintain compability with the gameconnection client objects function AIObject::play2D(%profile) { //error("AIObject::ServerPlay2D... empty fake function for virtual aiObject client objects..."); } function AIObject::play3D(%profile,%transform) { //error("AIObject::ServerPlay3D... empty fake function for virtual aiObject client objects..."); } function AIObject::isAIControlled(%this) { //error("AIObject::isAIControlled... empty fake function for virtual aiObject client objects..."); return true; }This code below is taken from my flying vehicle class to demonstrate the usage of the fake client ".ai" usage:
[code] function Scout::onReachDestination(%this, %obj) { error("Scout::onReachDestination called..."); [b]if (%obj.ai) // if ai, then so some action[/b] botSetNewAction(%obj); }There's one thing not working at the moment: If you add the bots and then go into the Mission editor the game crashes. I guess it's because I didn't add the getId() calls and alike which are needed by the editor (mostly the same stuff as dump() gives you back. You need to add most of the functions as dummy to stay in my example).
But nevertheless - as you can see above - calling makeABunchOfBots(); will create a ton of bots with fake client objects.
Hope this helps a bit :)
Martin
By the way: This code is taken directly out of my game Subsonic. In this link you can see the 64 bots flying that this code here above creates. So.. a real life example :-)
Edit: Typos