AI Guard Unit
by Mark Holcomb · 11/27/2004 (5:18 pm) · 335 comments
Download Code File
This is my second attempt at making an AI controlled character. The first was an
AIPlayer that would follow paths. This character is a guard unit. The guard will
wait at it's post (spawn point) until it sees a target. It will then attack that
target while trying to close with it.
If the target is lost the bot will wait at the last place it saw the character and
look around for a little bit, and then it will try to return to it's post.
There is a chance the bot will get stuck trying to return, but there is a simple
routine that has the bot try to move in random directions to try and clear itself
of any obstacles between it and it's post. It's not perfect.
The thinking routine is a simple state machine - which can be expanded on to give the bot more responses and actions.
As with my first ai character, I am using a simple system that allows the designer to drop
markers in the game map that will mark where the bots will start out. When the mission is loaded, the markers are detected and bots are spawned at the marker locations. The markers are then hidden from view. (The markers can be left visible to help in map editing.)
The markers for the guards can be given a dynamic variable called respawn. (Assigned to the marker during map editing.) 'Respawn' will determine whether a bot respawns or not upon death.
The bots have an attention setting. How often they scan is determined by their attention level. The bots get more sluggish (freeing up processor time) when targets are too far away. Conversely, the bot becomes incrementally more attentive as targets come within range, and further aware as targets come into sight.
When a target is found in range and in sight the bot will shoot at the target. The firing sequence is a step of scheduled calls that call for a firing cycle, a trigger down cycle, and a firing delay to control bot rate of fire.
When a bot is attacked it will attempt to sideatep and it's field of vision is temporarily increased to a 360deg field of vision - to emulate looking around to see what happened. The bot's attention level is also set to make it think at it's fastest rate when attacked.
To use the AIGuard...the following changes need to be made.
1. Back up your original game.cs, player.cs, and your current build of Torque. To install AIGuard will require a recompile, since I have created a new class cloned by copying AIPlayer.cc and AIPlayer.h and renaming all references to AIPlayer to AIGuard.
(I did this because I wanted to be able to run both my AIPatroller and AIGuards in the same maps and did not want to have any confusion between them.)
2. Add the files AIGuard.cc and AIGuard.h to your Torque project. (In my instance I saved them to my c:\Torque\engine\game directory and then added them into my project.)
3. Recompile your project and copy your new executable to the appropriate directory for your app.
4. Copy the file AIGuard.cs into your server/scripts directory.
5. Modify game.cs to add the line
to the function onServerCreated().
6. Also in game.cs: The section for function StartGame needs to modified the following ways:
Below the lines that read:
add this:
(If you followed my previous resource you may not have any reference to AImanager. Don't fret... just look for the place in game.cs where you have
and put in
right underneath it.
7. In player.cs in the code for Armor::Damage modify the lines
to read:
*** If you followed my previous resource there should be no need to change this code.
8. Load your map - Stronghold as an example.
9. Go into the map editor. (F11) Then go into the Editor Creator (F4)
10. Under Shapes there should be a drop down called AIMarker, under that a new item called AIGuard.
11. Create a new AIGuard marker.
12. Select your marker, position it where you like and hit (F3) to modify the marker.
13. If you want to override the default respawn value - create a dynamic variable called respawn and set it's value to true or false.
14. Update your item by clicking 'APPLY'- very important and easy to miss step.
15. Save your mission and reload it.
A bot called Guard1 should appear at the spot of your marker.
If you come within range of the guard he should shoot at you and try to hunt you down.
If you get away, or when you die, he should return to his post.
I hope the resource helps other people get up and running with some AI code in their game.
And again, I'd like to thank the other members of this website whose code has been used in several places in the scripting to make this all work.
Mark H.
P.S. I've also included my AIPatrol class files with this - to install it follow the same instructions as for AIGuard, just substitute AIPatrol where AIGuard appears in the instructions. They can both be run at the same times with no problems.
P.S.S. 11/28/04 - I modified the AIPatrol.cs file to correct for a couple of typos.
P.S.S.S 12/3/04 - Added ammo and health seeking capabilities and fixed some errors. (Read posts below - or file in .zip for full details.)
This is my second attempt at making an AI controlled character. The first was an
AIPlayer that would follow paths. This character is a guard unit. The guard will
wait at it's post (spawn point) until it sees a target. It will then attack that
target while trying to close with it.
If the target is lost the bot will wait at the last place it saw the character and
look around for a little bit, and then it will try to return to it's post.
There is a chance the bot will get stuck trying to return, but there is a simple
routine that has the bot try to move in random directions to try and clear itself
of any obstacles between it and it's post. It's not perfect.
The thinking routine is a simple state machine - which can be expanded on to give the bot more responses and actions.
As with my first ai character, I am using a simple system that allows the designer to drop
markers in the game map that will mark where the bots will start out. When the mission is loaded, the markers are detected and bots are spawned at the marker locations. The markers are then hidden from view. (The markers can be left visible to help in map editing.)
The markers for the guards can be given a dynamic variable called respawn. (Assigned to the marker during map editing.) 'Respawn' will determine whether a bot respawns or not upon death.
The bots have an attention setting. How often they scan is determined by their attention level. The bots get more sluggish (freeing up processor time) when targets are too far away. Conversely, the bot becomes incrementally more attentive as targets come within range, and further aware as targets come into sight.
When a target is found in range and in sight the bot will shoot at the target. The firing sequence is a step of scheduled calls that call for a firing cycle, a trigger down cycle, and a firing delay to control bot rate of fire.
When a bot is attacked it will attempt to sideatep and it's field of vision is temporarily increased to a 360deg field of vision - to emulate looking around to see what happened. The bot's attention level is also set to make it think at it's fastest rate when attacked.
To use the AIGuard...the following changes need to be made.
1. Back up your original game.cs, player.cs, and your current build of Torque. To install AIGuard will require a recompile, since I have created a new class cloned by copying AIPlayer.cc and AIPlayer.h and renaming all references to AIPlayer to AIGuard.
(I did this because I wanted to be able to run both my AIPatroller and AIGuards in the same maps and did not want to have any confusion between them.)
2. Add the files AIGuard.cc and AIGuard.h to your Torque project. (In my instance I saved them to my c:\Torque\engine\game directory and then added them into my project.)
3. Recompile your project and copy your new executable to the appropriate directory for your app.
4. Copy the file AIGuard.cs into your server/scripts directory.
5. Modify game.cs to add the line
exec("./aiGuard.cs"); to the function onServerCreated().
6. Also in game.cs: The section for function StartGame needs to modified the following ways:
Below the lines that read:
// Start the AIManager
new ScriptObject(AIManager) {};
MissionCleanup.add(AIManager);
AIManager.think();add this:
AIGuard::LoadEntities();
(If you followed my previous resource you may not have any reference to AImanager. Don't fret... just look for the place in game.cs where you have
AIPlayer::LoadEntities
and put in
AIGuard::LoadEntities();
right underneath it.
7. In player.cs in the code for Armor::Damage modify the lines
// Deal with client callbacks here because we don't have this
// information in the onDamage or onDisable methods
%client = %obj.client;
%sourceClient = %sourceObject ? %sourceObject.client : 0;
if (%obj.getState() $= "Dead")
%client.onDeath(%sourceObject, %sourceClient, %damageType, %location);to read:
// Deal with client callbacks here because we don't have this
// information in the onDamage or onDisable methods
%client = %obj.client;
%sourceClient = %sourceObject ? %sourceObject.client : 0; if (%obj.isbot == true)
{
%obj.attentionlevel=1;
%obj.enhancefov(%obj);
}
if (%obj.getState() $= "Dead")
{
if (%obj.isbot == true)
{
if (%obj.respawn == true)
{
%obj.delaybeforerespawn(%obj.botname, %obj.markerpos, %obj.marker);
%this.player=0;
}
}
else
{
%client.onDeath(%sourceObject, %sourceClient, %damageType, %location);
}
}*** If you followed my previous resource there should be no need to change this code.
8. Load your map - Stronghold as an example.
9. Go into the map editor. (F11) Then go into the Editor Creator (F4)
10. Under Shapes there should be a drop down called AIMarker, under that a new item called AIGuard.
11. Create a new AIGuard marker.
12. Select your marker, position it where you like and hit (F3) to modify the marker.
13. If you want to override the default respawn value - create a dynamic variable called respawn and set it's value to true or false.
14. Update your item by clicking 'APPLY'- very important and easy to miss step.
15. Save your mission and reload it.
A bot called Guard1 should appear at the spot of your marker.
If you come within range of the guard he should shoot at you and try to hunt you down.
If you get away, or when you die, he should return to his post.
I hope the resource helps other people get up and running with some AI code in their game.
And again, I'd like to thank the other members of this website whose code has been used in several places in the scripting to make this all work.
Mark H.
P.S. I've also included my AIPatrol class files with this - to install it follow the same instructions as for AIGuard, just substitute AIPatrol where AIGuard appears in the instructions. They can both be run at the same times with no problems.
P.S.S. 11/28/04 - I modified the AIPatrol.cs file to correct for a couple of typos.
P.S.S.S 12/3/04 - Added ammo and health seeking capabilities and fixed some errors. (Read posts below - or file in .zip for full details.)
#42
01/21/2005 (10:06 am)
All right guys, I did a clean compile of Torque, only added the aiguard and it still does it with the orc model. I went through the code (as best I can in my ignorance) and really couldn't figure anything out. What I did notice was that in the console there is a reference "object not found : ' ' " and then also "could not getposition" and "could not gettransform"(I think, this is from memory since i am at work). The lines that appear to be referenced over and over are 114, 436, 440, 697, 704(?). I don't know if this means anything execept the aiguard that is falling perhaps unable to find the origin point? Well, anyway it doesn't crash the program or anything, so I can still mess with it, but it's one of those things that make you crazy knowing it is happening! =)
#43
01/21/2005 (10:51 am)
FWIW, I have the tank pack and used Mark's AI resources w/o any issues. Post snippets of the console.log where the warnings show up so that we get some context. You also might want to put some debug messages in the scripts to help you narrow down where the issue might be (entering functions, key variables, etc.). Don't forget to remove the old DSOs when making changes to the scripts. I have found that script changes do not automatically show up when there are compiled scripts present.
#44
01/21/2005 (11:21 am)
Thanks Jerry for the response. In regards to the DSOs, already did that and it doesn't change anything, and maybe you might have missed what Fail66 and I are having happen. It's not that the aiguard doesn't work, I have no issures with the basic functioning of the script...it works perfectly, but what IS happening is a second spawn is occuring beneath the surface of the terrain at the same instant that the aiguard respawns at it's origin point, and unless you are in the gui editor and beneath the surface of the terrain, you would never notice it, since it is always beneath the terrain. I have no idea if it effects anything else at all, it is just that I would guess that a falling model would eventually cause some problem. This occurs with any .dts that is used, and as I noted, I do not have the tank pack and so it is, as far as I can tell, not relevant to the second spawn. When I get home this evening I will post the console.log in context, and thanks to all for the help!
#45
Set::add:Object "0" doesn't exist
aiPlayer.cs (236) : Unable to find object: ' ' attempting to call function 'followPath'
aiPlayer.cs (238) : Unable to find object: ' ' attempting to call function 'mountImage'
aiPlayer.cs (239) : Unable to find object: ' ' attempting to call function 'setInventory'
....
any suggestions?
02/01/2005 (9:15 am)
I am recieving the following error in the console log...Set::add:Object "0" doesn't exist
aiPlayer.cs (236) : Unable to find object: ' ' attempting to call function 'followPath'
aiPlayer.cs (238) : Unable to find object: ' ' attempting to call function 'mountImage'
aiPlayer.cs (239) : Unable to find object: ' ' attempting to call function 'setInventory'
....
any suggestions?
#46
I also have issues on respawn, and I don't have the tank pack, I'm using TSE, but I don't think it would
matter much. I just turn off respawn, and it's fine, but it's one kill and done, but thats fine with me. I
would like to figure out how to fix it though, but my biggest thing is, how do you turn off the state text,
like "holding", or "Guarding", those messages above the player, they don't show well :) I'm sure it's a torque
thing and not a resource thing, but maybe could help me out.
Thanks
02/04/2005 (4:27 pm)
First of all, thanks for this great resource. I also have issues on respawn, and I don't have the tank pack, I'm using TSE, but I don't think it would
matter much. I just turn off respawn, and it's fine, but it's one kill and done, but thats fine with me. I
would like to figure out how to fix it though, but my biggest thing is, how do you turn off the state text,
like "holding", or "Guarding", those messages above the player, they don't show well :) I'm sure it's a torque
thing and not a resource thing, but maybe could help me out.
Thanks
#47
You're saying that the script aiPlayer.cs is causing the errors. If you install the AIGuard code following the example then there is no need that I can recall to even load AIPlayer. If you have cross edited the code, then the problem is probably being caused in your datablock where you declare the AIPlayer because it sounds like the object isn't being created.
Tim Ryness,
I haven't tried putting the code into the TSE. I know in plain old TGE the code works fine for several people - with or without the tank pack.
Offhand and without looking into it at all, I'd say the problem is being caused by the TSE automatically respawning the item, as well as the code in AIGuard calling a respawn based off the timer.
I would think that the way to test this theory would be to find the code in the TSE engine scripts that handles the respawning of items and put as check in there to see if the item is a bot (The AIGuard has an isbot variable to check against.) and if it is a bot then to skip the code that auto respawns.
I know it's not an answer to your problem, but maybe it will help you find a fix. I've been working on some other non-Torque stuff for awhile - but I'll see if I can take a deeper look into this problem for you guys.
Also, the messages above their head can be set to their normal AIGuard1, AIGuard2 by commenting out the lines in the 'Think' function that read
I left the lines active to help demonstrate the thought processes going on.
If you are trying to remove the names altogether.... well I haven't tried to do that yet, but I believe there's a resource on the site that tells how to turn them off.
Hope the little bit of info helps.
02/04/2005 (5:35 pm)
Tim Heldna,You're saying that the script aiPlayer.cs is causing the errors. If you install the AIGuard code following the example then there is no need that I can recall to even load AIPlayer. If you have cross edited the code, then the problem is probably being caused in your datablock where you declare the AIPlayer because it sounds like the object isn't being created.
Tim Ryness,
I haven't tried putting the code into the TSE. I know in plain old TGE the code works fine for several people - with or without the tank pack.
Offhand and without looking into it at all, I'd say the problem is being caused by the TSE automatically respawning the item, as well as the code in AIGuard calling a respawn based off the timer.
I would think that the way to test this theory would be to find the code in the TSE engine scripts that handles the respawning of items and put as check in there to see if the item is a bot (The AIGuard has an isbot variable to check against.) and if it is a bot then to skip the code that auto respawns.
I know it's not an answer to your problem, but maybe it will help you find a fix. I've been working on some other non-Torque stuff for awhile - but I'll see if I can take a deeper look into this problem for you guys.
Also, the messages above their head can be set to their normal AIGuard1, AIGuard2 by commenting out the lines in the 'Think' function that read
%objname= %obj.action @ ":"@ %this.attentionlevel @ ":" @ %obj.getdamagelevel() @ ":" @ %obj.getInventory($AI_GUARD_WEAPON @ "Ammo") ; %obj.setshapename(%objname);
I left the lines active to help demonstrate the thought processes going on.
If you are trying to remove the names altogether.... well I haven't tried to do that yet, but I believe there's a resource on the site that tells how to turn them off.
Hope the little bit of info helps.
#48
If it is any help, here is the console log from the time the killed AI guard respawns, I had already remarked out the AIPlayer a while ago, but still have the second respawn.
starter.fps/server/scripts/aiGuard.cs (436): Unable to find object: '' attempting to call function 'getPosition'
starter.fps/server/scripts/aiGuard.cs (440): Unable to find object: '' attempting to call function 'getTransform'
Could not locate texture: starter.fps/data/shapes/player/crossbow
Could not locate texture: starter.fps/data/shapes/player/clip
Could not locate texture: starter.fps/data/shapes/player/crossbow
Could not locate texture: starter.fps/data/shapes/player/clip
Mapping string: Guard2 to index: 3
Mapping string: Holding:5:0:4 to index: 0
Mapping string: Holding:3:0:4 to index: 5
Mapping string: Returning:1:0:4 to index: 6
Mapping string: Guarding:1:0:4 to index: 4
starter.fps/server/scripts/aiGuard.cs (697): Unable to find object: '' attempting to call function 'getPosition'
starter.fps/server/scripts/aiGuard.cs (704): Unable to find object: '' attempting to call function 'getPosition'
starter.fps/server/scripts/aiGuard.cs (114): Unable to find object: '' attempting to call function 'getPosition'
Mapping string: Returning:5:0:4 to index: 10
starter.fps/server/scripts/aiGuard.cs (697): Unable to find object: '' attempting to call function 'getPosition'
starter.fps/server/scripts/aiGuard.cs (704): Unable to find object: '' attempting to call function 'getPosition'
starter.fps/server/scripts/aiGuard.cs (114): Unable to find object: '' attempting to call function 'getPosition'
starter.fps/server/scripts/aiGuard.cs (697): Unable to find object: '' attempting to call function 'getPosition'
starter.fps/server/scripts/aiGuard.cs (704): Unable to find object: '' attempting to call function 'getPosition'
starter.fps/server/scripts/aiGuard.cs (114): Unable to find object: '' attempting to call function 'getPosition'
I've looked at these lines of code, 114, 436,440, 697 & 704. I don't see anything strange, but then again I don't know exactly what I'm looking for. Just thought I'd chime in again ( I've been messing around with other aspects of Torque for the last week or so myself, so I haven't been too concerned).
02/05/2005 (4:24 pm)
Hi Mark, If it is any help, here is the console log from the time the killed AI guard respawns, I had already remarked out the AIPlayer a while ago, but still have the second respawn.
starter.fps/server/scripts/aiGuard.cs (436): Unable to find object: '' attempting to call function 'getPosition'
starter.fps/server/scripts/aiGuard.cs (440): Unable to find object: '' attempting to call function 'getTransform'
Could not locate texture: starter.fps/data/shapes/player/crossbow
Could not locate texture: starter.fps/data/shapes/player/clip
Could not locate texture: starter.fps/data/shapes/player/crossbow
Could not locate texture: starter.fps/data/shapes/player/clip
Mapping string: Guard2 to index: 3
Mapping string: Holding:5:0:4 to index: 0
Mapping string: Holding:3:0:4 to index: 5
Mapping string: Returning:1:0:4 to index: 6
Mapping string: Guarding:1:0:4 to index: 4
starter.fps/server/scripts/aiGuard.cs (697): Unable to find object: '' attempting to call function 'getPosition'
starter.fps/server/scripts/aiGuard.cs (704): Unable to find object: '' attempting to call function 'getPosition'
starter.fps/server/scripts/aiGuard.cs (114): Unable to find object: '' attempting to call function 'getPosition'
Mapping string: Returning:5:0:4 to index: 10
starter.fps/server/scripts/aiGuard.cs (697): Unable to find object: '' attempting to call function 'getPosition'
starter.fps/server/scripts/aiGuard.cs (704): Unable to find object: '' attempting to call function 'getPosition'
starter.fps/server/scripts/aiGuard.cs (114): Unable to find object: '' attempting to call function 'getPosition'
starter.fps/server/scripts/aiGuard.cs (697): Unable to find object: '' attempting to call function 'getPosition'
starter.fps/server/scripts/aiGuard.cs (704): Unable to find object: '' attempting to call function 'getPosition'
starter.fps/server/scripts/aiGuard.cs (114): Unable to find object: '' attempting to call function 'getPosition'
I've looked at these lines of code, 114, 436,440, 697 & 704. I don't see anything strange, but then again I don't know exactly what I'm looking for. Just thought I'd chime in again ( I've been messing around with other aspects of Torque for the last week or so myself, so I haven't been too concerned).
#49
I m following the resource and everything is working fine but I m facing the same problem and errors u mentioned in above post. If you have solve this, i will be appreciate if u can suggest me the same.
Thanx
Ali Shikla
03/07/2005 (3:56 am)
Hi Alan,I m following the resource and everything is working fine but I m facing the same problem and errors u mentioned in above post. If you have solve this, i will be appreciate if u can suggest me the same.
Thanx
Ali Shikla
#50
03/09/2005 (2:50 pm)
I'm getting the same errors it doesn't seem to mess up the way the bot works to much but it clogs the console.
#51
The problem is that when i run the mission again (after having saved it) the bot does not appear and i've got some strange output in the console log :
*************
Compiling starter.fps/server/scripts/player.cs...
starter.fps/server/scripts/player.cs Line: 830 - Syntax error.
>>> Advanced script error report. Line 1659.
>>> Some error context, with ## on sides of error halt:
%client.onDeath(%sourceObject, %sourceClient, %damageType, %location);
}
}
function ##A##rmor::onDamage(%this, %obj, %delta)
{
// This method is invoked by the ShapeBase code whenever the
>>> Error report complete.
Executing starter.fps/server/scripts/player.cs.
starter.fps/server/scripts/player.cs Line: 830 - Syntax error.
>>> Advanced script error report. Line 1659.
>>> Some error context, with ## on sides of error halt:
%client.onDeath(%sourceObject, %sourceClient, %damageType, %location);
}
}
function ##A##rmor::onDamage(%this, %obj, %delta)
{
// This method is invoked by the ShapeBase code whenever the
>>> Error report complete.
Loading compiled script starter.fps/data/shapes/player/player.cs.
Validation required for shape: starter.fps/data/shapes/player/player.dts
Loading compiled script starter.fps/server/scripts/chimneyfire.cs.
Loading compiled script starter.fps/server/scripts/aiPlayer.cs.
Validation required for shape: starter.fps/data/shapes/player/player.dts
Compiling starter.fps/server/scripts/aiguard.cs...
Loading compiled script starter.fps/server/scripts/aiguard.cs.
Validation required for shape: starter.fps/data/shapes/player/player.dts
*** LOADING MISSION: starter.fps/data/missions/stronghold.mis
*** Stage 1 load
*** Stage 2 load
Executing starter.fps/data/missions/stronghold.mis.
*** Mission loaded
Loading Guard entities...
starter.fps/server/scripts/aiguard.cs (350): Unable to instantiate non-conobject class AIGuard.
Set::add: Object "0" doesn't exist
starter.fps/server/scripts/aiguard.cs (366): Unable to find object: '0' attempting to call function 'EquipBot'
starter.fps/server/scripts/aiguard.cs (368): Unable to find object: '0' attempting to call function 'setShapeName'
starter.fps/server/scripts/aiguard.cs (370): Unable to find object: '0' attempting to call function 'setTransform'
starter.fps/server/scripts/aiguard.cs (372): Unable to find object: '0' attempting to call function 'schedule'
Hiding Guard markers...
*************
It seems that the object is not created...
Any help will be greatly appreciated...
Edit : My bad, I copied and pasted from damn windows notepad and so the code was all messed up.....
Plus I've forgotten to add aiguard.cc and compiled only with the .h
What to say .... Great resource !!!!!!!!
03/18/2005 (2:34 pm)
I've installed with no errors the resource, recompiled tge and can place the aimarker in my mission.The problem is that when i run the mission again (after having saved it) the bot does not appear and i've got some strange output in the console log :
*************
Compiling starter.fps/server/scripts/player.cs...
starter.fps/server/scripts/player.cs Line: 830 - Syntax error.
>>> Advanced script error report. Line 1659.
>>> Some error context, with ## on sides of error halt:
%client.onDeath(%sourceObject, %sourceClient, %damageType, %location);
}
}
function ##A##rmor::onDamage(%this, %obj, %delta)
{
// This method is invoked by the ShapeBase code whenever the
>>> Error report complete.
Executing starter.fps/server/scripts/player.cs.
starter.fps/server/scripts/player.cs Line: 830 - Syntax error.
>>> Advanced script error report. Line 1659.
>>> Some error context, with ## on sides of error halt:
%client.onDeath(%sourceObject, %sourceClient, %damageType, %location);
}
}
function ##A##rmor::onDamage(%this, %obj, %delta)
{
// This method is invoked by the ShapeBase code whenever the
>>> Error report complete.
Loading compiled script starter.fps/data/shapes/player/player.cs.
Validation required for shape: starter.fps/data/shapes/player/player.dts
Loading compiled script starter.fps/server/scripts/chimneyfire.cs.
Loading compiled script starter.fps/server/scripts/aiPlayer.cs.
Validation required for shape: starter.fps/data/shapes/player/player.dts
Compiling starter.fps/server/scripts/aiguard.cs...
Loading compiled script starter.fps/server/scripts/aiguard.cs.
Validation required for shape: starter.fps/data/shapes/player/player.dts
*** LOADING MISSION: starter.fps/data/missions/stronghold.mis
*** Stage 1 load
*** Stage 2 load
Executing starter.fps/data/missions/stronghold.mis.
*** Mission loaded
Loading Guard entities...
starter.fps/server/scripts/aiguard.cs (350): Unable to instantiate non-conobject class AIGuard.
Set::add: Object "0" doesn't exist
starter.fps/server/scripts/aiguard.cs (366): Unable to find object: '0' attempting to call function 'EquipBot'
starter.fps/server/scripts/aiguard.cs (368): Unable to find object: '0' attempting to call function 'setShapeName'
starter.fps/server/scripts/aiguard.cs (370): Unable to find object: '0' attempting to call function 'setTransform'
starter.fps/server/scripts/aiguard.cs (372): Unable to find object: '0' attempting to call function 'schedule'
Hiding Guard markers...
*************
It seems that the object is not created...
Any help will be greatly appreciated...
Edit : My bad, I copied and pasted from damn windows notepad and so the code was all messed up.....
Plus I've forgotten to add aiguard.cc and compiled only with the .h
What to say .... Great resource !!!!!!!!
#52
Good to know that its working with u.
Try to kill the AIGuard, let it to respawn.. it will attack on u again.. get out of his range. He will go back to his spawn marker position and at that point check u'r consol.
My Consol is showing these errors :
Mapping string: Attacking:1:80:1192 to index: 9
Mapping string: Attacking:1:80:1291 to index: 10
Mapping string: Dead:1:100:1291 to index: 11
starter.fps/server/scripts/aiguard.cs (443): Unable to find object: '' attempting to call function 'getPosition'
starter.fps/server/scripts/aiguard.cs (447): Unable to find object: '' attempting to call function 'getTransform'
Could not locate texture: starter.fps/data/shapes/player/crossbow
Could not locate texture: starter.fps/data/shapes/player/clip
Could not locate texture: starter.fps/data/shapes/player/crossbow
Could not locate texture: starter.fps/data/shapes/player/clip
Mapping string: Guard1 to index: 12
Mapping string: Attacking:2:0:4 to index: 16
Mapping string: Holding:5:0:4 to index: 17
Mapping string: Attacking:1:0:4 to index: 18
starter.fps/server/scripts/aiguard.cs (704): Unable to find object: '' attempting to call function 'getPosition'
starter.fps/server/scripts/aiguard.cs (711): Unable to find object: '' attempting to call function 'getPosition'
starter.fps/server/scripts/aiguard.cs (121): Unable to find object: '' attempting to call function 'getPosition'
Mapping string: Returning:5:0:4 to index: 19
starter.fps/server/scripts/aiguard.cs (704): Unable to find object: '' attempting to call function 'getPosition'
starter.fps/server/scripts/aiguard.cs (711): Unable to find object: '' attempting to call function 'getPosition'
starter.fps/server/scripts/aiguard.cs (121): Unable to find object: '' attempting to call function 'getPosition'
*-*-*-*-*-*-*-*-*
If anybody could suggest me how can i solve these ?
Thanx
Ali Shikla
03/19/2005 (1:20 am)
@StefenoGood to know that its working with u.
Try to kill the AIGuard, let it to respawn.. it will attack on u again.. get out of his range. He will go back to his spawn marker position and at that point check u'r consol.
My Consol is showing these errors :
Mapping string: Attacking:1:80:1192 to index: 9
Mapping string: Attacking:1:80:1291 to index: 10
Mapping string: Dead:1:100:1291 to index: 11
starter.fps/server/scripts/aiguard.cs (443): Unable to find object: '' attempting to call function 'getPosition'
starter.fps/server/scripts/aiguard.cs (447): Unable to find object: '' attempting to call function 'getTransform'
Could not locate texture: starter.fps/data/shapes/player/crossbow
Could not locate texture: starter.fps/data/shapes/player/clip
Could not locate texture: starter.fps/data/shapes/player/crossbow
Could not locate texture: starter.fps/data/shapes/player/clip
Mapping string: Guard1 to index: 12
Mapping string: Attacking:2:0:4 to index: 16
Mapping string: Holding:5:0:4 to index: 17
Mapping string: Attacking:1:0:4 to index: 18
starter.fps/server/scripts/aiguard.cs (704): Unable to find object: '' attempting to call function 'getPosition'
starter.fps/server/scripts/aiguard.cs (711): Unable to find object: '' attempting to call function 'getPosition'
starter.fps/server/scripts/aiguard.cs (121): Unable to find object: '' attempting to call function 'getPosition'
Mapping string: Returning:5:0:4 to index: 19
starter.fps/server/scripts/aiguard.cs (704): Unable to find object: '' attempting to call function 'getPosition'
starter.fps/server/scripts/aiguard.cs (711): Unable to find object: '' attempting to call function 'getPosition'
starter.fps/server/scripts/aiguard.cs (121): Unable to find object: '' attempting to call function 'getPosition'
*-*-*-*-*-*-*-*-*
If anybody could suggest me how can i solve these ?
Thanx
Ali Shikla
#53
In effect, reproducing the situation, my console shows the same output but the bot is actually returning correctly at its beginning position.
Also the randomize/side step function makes a good work, I trapped the bot in a house and then runned away, well in a few tries it checked for the door, managed to go outside and returned to its respawn.
So the code, apart from those strange consolle output seems to work very well.
Do you have an issue related to that code ? Maybe the bot will not return to the respawn ?
03/19/2005 (6:12 am)
@ ShaanIn effect, reproducing the situation, my console shows the same output but the bot is actually returning correctly at its beginning position.
Also the randomize/side step function makes a good work, I trapped the bot in a house and then runned away, well in a few tries it checked for the door, managed to go outside and returned to its respawn.
So the code, apart from those strange consolle output seems to work very well.
Do you have an issue related to that code ? Maybe the bot will not return to the respawn ?
#54
Could it be used for spiders, rats, goblins, skeletons, wolvess, bears, and others?
Looks as though you use a FSM (simple as it is) which are extensible to many different actions/reactions.
03/22/2005 (4:05 pm)
Would it be possible to use this as a basis for different kind of creature's AI, instead of a humanoid, Could it be used for spiders, rats, goblins, skeletons, wolvess, bears, and others?
Looks as though you use a FSM (simple as it is) which are extensible to many different actions/reactions.
#55
I still get a few console errors in my logs about unable to find textures. I haven't pinned them down yet.
I also get the error message about the unable to find item in player.cs and weapon.cs. I tried hunting this problem down before and came up dry. I think it has to do with the fact that I'm overriding the default function to kill off the player object, and somewhere the internal code is still getting called. And since the object is gone, the error is popping up. That's my best guess at this point.
I won't lie and tell everyone that I'll look into this right away. Truth be told, it will probably be a few weeks before I have any free time to dig into this.
In regards to the above post where nothing is working. The error that says 'Unable to instantiate object..." means that for some reason or the other, the class isn't declared. Any functions under that class will fail as well. This error usually occurs if you skip the step to add the class and recompile the executable.
In regards to Ed Johnson, as far as I know, you should be able to adapt this code to a non-human character. You'd have to follow the tutorials for some of the other people on adding non-human characters, once you figure out how to add them in, then you need to copy the relevant parts of the code from AIGuard into the class script for the non human character.
As for people have problems with multiple respawns, my only guess at this - since I don't get the error - is to go back and check the player.cs file and make sure that it is checking whether the character is a bot or not, and that the appropriate sequence is being followed.
My initial guess is that the bot is getting picked up as a bot and getting wiped out and respawned appropriately by the AIGuard.cs script, but for some reason it is still getting passed on and getting picked up and respawned a second time by player.cs when it sees that the player (ai player in this case) is dead.
I make this my initial guess because if the original object is toasted, and AIguard.cs picks it up and respawns it and deletes it, then when the background respawn object is called then it would be trying to reference a position that has been lost, because the position reference was stored in the original object which has been culled already, causing the respawn to be in an odd location.
That's just a guess. Come to think of it - the console errors and this problem may very well be related to each other. I may be missing a step somewhere in cleaning up the object so that the internal delete and respawns for objects aren't being cancelled.
I know I didn't answer anyones questions with any real answers. But I did want to chime in and let you guys know that I haven't abandoned this. I just haven't had the time to work on this lately.
Mark
03/22/2005 (4:56 pm)
Sorry I've been remiss in answering questions here guys. I haven't been working on anything in Torque for the past couple of months.I still get a few console errors in my logs about unable to find textures. I haven't pinned them down yet.
I also get the error message about the unable to find item in player.cs and weapon.cs. I tried hunting this problem down before and came up dry. I think it has to do with the fact that I'm overriding the default function to kill off the player object, and somewhere the internal code is still getting called. And since the object is gone, the error is popping up. That's my best guess at this point.
I won't lie and tell everyone that I'll look into this right away. Truth be told, it will probably be a few weeks before I have any free time to dig into this.
In regards to the above post where nothing is working. The error that says 'Unable to instantiate object..." means that for some reason or the other, the class isn't declared. Any functions under that class will fail as well. This error usually occurs if you skip the step to add the class and recompile the executable.
In regards to Ed Johnson, as far as I know, you should be able to adapt this code to a non-human character. You'd have to follow the tutorials for some of the other people on adding non-human characters, once you figure out how to add them in, then you need to copy the relevant parts of the code from AIGuard into the class script for the non human character.
As for people have problems with multiple respawns, my only guess at this - since I don't get the error - is to go back and check the player.cs file and make sure that it is checking whether the character is a bot or not, and that the appropriate sequence is being followed.
My initial guess is that the bot is getting picked up as a bot and getting wiped out and respawned appropriately by the AIGuard.cs script, but for some reason it is still getting passed on and getting picked up and respawned a second time by player.cs when it sees that the player (ai player in this case) is dead.
I make this my initial guess because if the original object is toasted, and AIguard.cs picks it up and respawns it and deletes it, then when the background respawn object is called then it would be trying to reference a position that has been lost, because the position reference was stored in the original object which has been culled already, causing the respawn to be in an odd location.
That's just a guess. Come to think of it - the console errors and this problem may very well be related to each other. I may be missing a step somewhere in cleaning up the object so that the internal delete and respawns for objects aren't being cancelled.
I know I didn't answer anyones questions with any real answers. But I did want to chime in and let you guys know that I haven't abandoned this. I just haven't had the time to work on this lately.
Mark
#56
what sould i change if i ant the aiguard to attack bots instead of players?
thanks.
03/24/2005 (5:45 am)
hello,what sould i change if i ant the aiguard to attack bots instead of players?
thanks.
#57
There is an extra level of detail here in that you need the AI player to search for both types of enemies (Real and AI), and then determine which one is closest to attack.
If you take a look at the scripts for the bots in the Navigation code I wrote you'll see exactly what I mean. (Plus with a little cut and paste ability you could take the extra functions out of the ctfbot.cs script and merge it into the AIGuard.cs script.)
03/26/2005 (3:10 pm)
It's a little more complicated than you would think. Because the AI players are objects - not in a client list like the real players. You have to look for them the same way you do for the ammo - or other items.There is an extra level of detail here in that you need the AI player to search for both types of enemies (Real and AI), and then determine which one is closest to attack.
If you take a look at the scripts for the bots in the Navigation code I wrote you'll see exactly what I mean. (Plus with a little cut and paste ability you could take the extra functions out of the ctfbot.cs script and merge it into the AIGuard.cs script.)
#58
My game is supposed to have up to about 200 bots (low poly)... Do you think this is efficient enough to handle that many bots without killing performance too much? And how many polys do you think I can get away with, per bot, if there is nothing else but terrain in the scene, or mission for that matter? It is quite choppy with 10 bravetree girls, but she is 3649 polys...
Thanks for an amazing resource...
I did some math... 10 bots * 3649 polys = 36490 / 150 (ttoal bots) = 243 polys
Make them 200 polys, to account for the ai time... I will have to test this to check and see how choppy it is....
03/31/2005 (2:33 pm)
I just added this to my project... I am using the tutorial.base tutorial, modified to my project, with the bravetree girl as my player (and the bot)... It is hilarious to watch 10 of them run at you at the same time... My game is supposed to have up to about 200 bots (low poly)... Do you think this is efficient enough to handle that many bots without killing performance too much? And how many polys do you think I can get away with, per bot, if there is nothing else but terrain in the scene, or mission for that matter? It is quite choppy with 10 bravetree girls, but she is 3649 polys...
Thanks for an amazing resource...
I did some math... 10 bots * 3649 polys = 36490 / 150 (ttoal bots) = 243 polys
Make them 200 polys, to account for the ai time... I will have to test this to check and see how choppy it is....
#59
The reason I say that I don't think this will work is because the script starts a schedule for each bot to "Think" on. That would mean for 200 bots you'd have 200 schedules triggering, and ultimately they would trip all over themselves and drag your machine to the dirt.
You might want to look into the RPG game pack and maybe hit a few of the forum topics on this because they have to be handling the groups mentality different.
I'd hazard a guess to say that they're using a 'superclass' for a group, and then the superclass handles the toplevel thinking for the group - such as setting destinations - setting targets, etc, probably even scheduling attacking etc...
Depending on what your bots purposes in life are this might be a better fit for you.
(Plus I'm not sure how acceptable looking such a low poly model would look )
03/31/2005 (5:34 pm)
To be truthful, I doubt you'll get what you're looking for out of this script. This one was designed to provide the capability for more intelligent type bots, where you could add to or expand onto their capabilities.The reason I say that I don't think this will work is because the script starts a schedule for each bot to "Think" on. That would mean for 200 bots you'd have 200 schedules triggering, and ultimately they would trip all over themselves and drag your machine to the dirt.
You might want to look into the RPG game pack and maybe hit a few of the forum topics on this because they have to be handling the groups mentality different.
I'd hazard a guess to say that they're using a 'superclass' for a group, and then the superclass handles the toplevel thinking for the group - such as setting destinations - setting targets, etc, probably even scheduling attacking etc...
Depending on what your bots purposes in life are this might be a better fit for you.
(Plus I'm not sure how acceptable looking such a low poly model would look )
#60
Each bot manages it's own thought, but it doesn't schedule itself to think... Instead the aiController tells it to thikn on occasion. Unfortunately, there is no longer attentionlevel 's... but I never liked that funcitonality anyways (no offence)
04/04/2005 (7:03 am)
@Mark: I have implimented an aiController that creates and manages calling the think functions for each of the bots, inclduing seperating them into fairly equal sized groups, so I can cut down on how much thinking is being done at one time, if I need to. Now I just schedule the aiController to think once and it forces my bots to think... Is this what you meant? Each bot manages it's own thought, but it doesn't schedule itself to think... Instead the aiController tells it to thikn on occasion. Unfortunately, there is no longer attentionlevel 's... but I never liked that funcitonality anyways (no offence)

Torque Owner Mark Holcomb