Friendly AI Marker
by Maximillian Brewer · 01/11/2009 (9:47 pm) · 33 comments
Download Code File
** Works with TGE 1.5.2 and TGEA 1.7.1 **
To implement the Friendly AI Marker just follow the simple steps below:
1. Make backups of you dev folder and game.cs file
2. Download the code file - aiMarker.cs
3. Copy aiMarker.cs into yourGame/server/scripts (make sure the file is still called aiMarker.cs)
4. Open up game.cs in the server/scripts folder and do the following...
Find:
and place the following beneath it:
In startGame function
Replace this:
with the following:
5. Now run you deleteDSOs.bat file, and launch your game mision...in the World Creator, you should see FriendlyAIMarker under Shapes/AiMarker.
Just drag this marker to were you wish to spawn you AI from. Then, save and play!
----------------------------------------------------------------------------------------------------------------------------------------
For any help with this, just post a comment, and I will help ASAP!
** Works with TGE 1.5.2 and TGEA 1.7.1 **
To implement the Friendly AI Marker just follow the simple steps below:
1. Make backups of you dev folder and game.cs file
2. Download the code file - aiMarker.cs
3. Copy aiMarker.cs into yourGame/server/scripts (make sure the file is still called aiMarker.cs)
4. Open up game.cs in the server/scripts folder and do the following...
Find:
exec("./aiPlayer.cs");and place the following beneath it:
exec("./aiMarker.cs");In startGame function
Replace this:
// Start the AIManager
new ScriptObject(AIManager) {};
MissionCleanup.add(AIManager);
AIManager.think();with the following:
AIPlayer::LoadEntities(); AIPlayer::LoadFriendlyEntities();
5. Now run you deleteDSOs.bat file, and launch your game mision...in the World Creator, you should see FriendlyAIMarker under Shapes/AiMarker.
Just drag this marker to were you wish to spawn you AI from. Then, save and play!
----------------------------------------------------------------------------------------------------------------------------------------
For any help with this, just post a comment, and I will help ASAP!
#2
01/13/2009 (6:40 pm)
where can i download the "aimarker.cs" code?
#3
Download: http://files.filefront.com/aiMarkercs/;12968944;/fileinfo.html
From Ross
PS. I will update the resource to include the download link :)
01/14/2009 (12:56 am)
@Meison With the update of this site, it seems that no resources that used to have downloadable files have them anymore, they must have been lost or something, but here is a link to a download to the file on filefront.Download: http://files.filefront.com/aiMarkercs/;12968944;/fileinfo.html
From Ross
PS. I will update the resource to include the download link :)
#5
01/15/2009 (12:41 am)
The code file is now downloadable via the Download Code File link
#6
01/20/2009 (1:57 pm)
Is this for the TGEA or TGB?
#7
01/22/2009 (9:27 am)
works with 1.7.1
#8
@Deepscratch Thats for testing it in TGEA, I will update the Resource saying that it is compatible with TGE/A
01/23/2009 (7:39 pm)
@Raqual This was made for use with TGE, so TGEA should work, but I don't think TGB would, because TGE is 3D engine, and TGB is 2D@Deepscratch Thats for testing it in TGEA, I will update the Resource saying that it is compatible with TGE/A
#9
02/12/2009 (9:56 am)
After weeks of trying to get AI to spawn, this worked perfectly :) However how do i go about changing the AI character models? They AI automatically defaults to theplayer character model. I would like to use some skeleton models i have! If anyone could help me out i would love you long time!
#10
Then back in aiMarker.cs edit the bold line to read what it says :)
02/12/2009 (11:00 pm)
@Tom: To change the model that the friendlyAiMarker will spawn, simply go to server/scripts/player.cs and find:datablock PlayerData(PlayerBody)Then, just copy the whole of that datablock directly below it, changing the line in bold:
className = Armor; [b]shapeFile = "~/data/shapes/YOUR NEW PLAYER MODEL.dts";[/b] cameraMaxDist = 3; computeCRC = true;and also chandge your new datablock's name from PlayerBody -> PlayerBody2
Then back in aiMarker.cs edit the bold line to read what it says :)
datablock PlayerData([b]FriendlyAI : PlayerBody2[/b])
{
shootingDelay = 100;
};
#11
I guess what im really asking is where in the aiMarker code do i add these things? I also noticed since the aiMarker is being used, aiPlayer is not? Ive tried to impliment other ai bots like killer kork, and aiguard, and none of thsoe work for me. like i cant get anything to spawn. You resource seems the most solid.
Im doing this for a school project, any help would be appreciated!
02/17/2009 (1:30 pm)
Another question for you Max. How would i go about making these AI NPC's attack? Your code works perfect for me in terms on spawning the ai, id just like to impliment some AI behavior now. I guess what im really asking is where in the aiMarker code do i add these things? I also noticed since the aiMarker is being used, aiPlayer is not? Ive tried to impliment other ai bots like killer kork, and aiguard, and none of thsoe work for me. like i cant get anything to spawn. You resource seems the most solid.
Im doing this for a school project, any help would be appreciated!
#12
As you might relise, this is just an edited version of the Improved Ai Guard Unit (search it) which is a resource on how to spawn attacking Units.
If you wish to use both at the same time, you will need to go through me aiMArker.cs file and rename the functions:
eg. from
because otherwise if you use my resource with improved Ai Unit, you have 2 script files defining the same functions :)
From Max
PS. If you can't get this working:
a) I'll take a look at getting both my resource and the Improved Ai Guard Unit working, and give you a link to the new aiMarker.cs
b) Take a look at the Improved Ai Guard Unit, and at the bottom of the comments, Twisted Jenius mentions a marker editor, look at that.
02/17/2009 (11:38 pm)
@ Tom: I made this Friendly NPC as a way to have both attacking and non-attacking NPC's. But even i failed at my own game.As you might relise, this is just an edited version of the Improved Ai Guard Unit (search it) which is a resource on how to spawn attacking Units.
If you wish to use both at the same time, you will need to go through me aiMArker.cs file and rename the functions:
eg. from
function SpawnPlayerto
function SpawnFriendlyPlayer
because otherwise if you use my resource with improved Ai Unit, you have 2 script files defining the same functions :)
From Max
PS. If you can't get this working:
a) I'll take a look at getting both my resource and the Improved Ai Guard Unit working, and give you a link to the new aiMarker.cs
b) Take a look at the Improved Ai Guard Unit, and at the bottom of the comments, Twisted Jenius mentions a marker editor, look at that.
#13
Im gonna try it out, and ill let you know how it ends up.
02/18/2009 (10:17 am)
Ill check this out Max, thank you very much :D Me and another team member from class have been trying to get this to work. AI is tough, but im sure once we figure this out it will be alot easier in the future.Im gonna try it out, and ill let you know how it ends up.
#14
see when i had both running, the AI guards would spawn as Your AI Markers. So they would just stand there and now attack. However when i disabled AI Marker, the Ai guards attacked me. It seems that the Ai guards will default to the "FriendlyAI" datablock
What do you suspect the problem is? Id really like to have NPC's that dont attack as well.
Ill work on this soem mroe, maybe i can come up with soemthing.
02/18/2009 (11:42 pm)
well the AI guard works...but only if i disable your AI Marker. Hmmsee when i had both running, the AI guards would spawn as Your AI Markers. So they would just stand there and now attack. However when i disabled AI Marker, the Ai guards attacked me. It seems that the Ai guards will default to the "FriendlyAI" datablock
What do you suspect the problem is? Id really like to have NPC's that dont attack as well.
Ill work on this soem mroe, maybe i can come up with soemthing.
#15
I will try and get my marker working with the Ai Guard (improved) as i require to do this to finish the expansion to a game of mine (Ork Warfare) and if so, i will post a reply here :)
Also, which country do you live in, because i live in Australia, and i think you live in America somewhere, so it makes talking difficult (i'm asleep when you are awake)
From Max
02/19/2009 (1:57 am)
@ TomI will try and get my marker working with the Ai Guard (improved) as i require to do this to finish the expansion to a game of mine (Ork Warfare) and if so, i will post a reply here :)
Also, which country do you live in, because i live in Australia, and i think you live in America somewhere, so it makes talking difficult (i'm asleep when you are awake)
From Max
#16
I changed the name of a few functions, and have successfully run both my Marker resource and the improved guard.
just go into aiMarker.cs and delete it all, and replace with this (copy and paste):
That will deffinatly work!
from max
02/19/2009 (2:11 am)
WAAHOOOO!!!!!!!!!!!I changed the name of a few functions, and have successfully run both my Marker resource and the improved guard.
just go into aiMarker.cs and delete it all, and replace with this (copy and paste):
// This file defines a marker that can be placed in the game through
// drag-and-drop, which on load, will spawn the WelcomePlayer
//-----------------------------------------------------------------------------
$AI_PLAYER_ENABLED = true;
datablock ItemData(FriendlyAIMarker)
{
//This shape will be listed under the Shapes in the mission editor
category = "AIMarker";
// Basic Item properties
// Basic shape file to use as a marker in the editor.
shapeFile = "~/data/shapes/markers/octahedron.dts";
mass = 1;
friction = 1;
elasticity = 0.3;
};
datablock PlayerData(FriendlyAI : PlayerBody)
{
shootingDelay = 100;
};
function AIPlayer::LoadFriendlyEntities()
{
//checks to see if the entities are to be processed.
if ($AI_PLAYER_ENABLED == true)
{
echo("Loading AIPlayer entities...");
%position = "0 0 0";
%radius = 100000.0;
InitContainerRadiusSearch(%position, %radius, $TypeMasks::ItemObjectType);
%i=0;
while ((%targetObject = containerSearchNext()) != 0)
{
if (%targetobject.getDataBlock().getName() $= "FriendlyAIMarker")
{
%i++;
%player = AIPlayer::spawnFriendAtMarker("Kork" @ %i, %targetobject);
%targetobject.sethidden(true);
}
}
}
else
{
echo("Patrol entities disabled...");
}
}
//-----------------------------------------------------------------------------
// AIPlayer static functions
//-----------------------------------------------------------------------------
function AIPlayer::spawnFriend(%name, %obj)
{
// Create the demo player object
%player = new AIPlayer() {
dataBlock = FriendlyAI;
//This value is set to true for AIPlayers, it is referenced in player.cs
//to help handle respawning bots properly.
isbot=true;
//These variables are set for each bot, this is done on a per bot basis
//because the fov and attention level for each bot will be adjusted during
//the game.
//FOV = Bot's field of vision in degrees. (180 deg. means everything in front of the bot)
//attentionlevel = The bot's attention level is raised or lowered based on how near targets
//are and whether targets are visible or not.
fov=$AI_PLAYER_FOV;
attentionlevel = $AI_PLAYER_MAX_ATTENTION/2;
//The following line allows gives access to the markers dynamic variables and it's spawn position.
marker = %obj;
//The pathname variable is a dynamic variable set during map editing.
//This allows the designer to attach each bot to a seperate path
path = %obj.pathname;
botname = %name;
};
MissionCleanup.add(%player);
//The following set of if-then statements trap to see if the marker has a dynamic variable
//called respawn. (Set during map editing.)
//If it does then the players respawn flag is set accordingly true or false
//as stated by the variable.
//If there is no respawn variable set, then the flag is set to the default global value
if (%obj.respawn $= "" )
{
%player.respawn=$AI_PLAYER_DEFAULTRESPAWN;
}
else
{
if (%obj.respawn == true)
%player.respawn=true;
else
%player.respawn=false;
}
//Calls equipbot - to set the AIPlayers initial inventory
%player.EquipBot(%player);
%player.setShapeName(%name);
%player.setTransform(%obj.gettransform());
%player.followPath(%obj.pathname,-1);
return %player;
}
function AIPlayer::spawnFriendAtMarker(%name,%obj)
{
// Spawn a player and place him on the first node of the path
if (!isObject(%obj))
return;
%player = AIPlayer::spawnFriend(%name, %obj);
return %player;
}That will deffinatly work!
from max
#17
Yes im in America here hehe. Its the morning here right now, so you are probably in bed now lol.
So what changes did you make? I noticed that you changed AIPlayer::spawnFriendAtMarker.
Thanks for you help on all this stuff too, you deserve much praise for this resource.
02/19/2009 (9:27 am)
Nice Max! I finnaly got the AI guard fully working last night after some animation issues. Its gonna be great having both yours and Twisted' resource running at once!Yes im in America here hehe. Its the morning here right now, so you are probably in bed now lol.
So what changes did you make? I noticed that you changed AIPlayer::spawnFriendAtMarker.
Thanks for you help on all this stuff too, you deserve much praise for this resource.
#18
Basically, the problem was that because my resource is an edit of his (basically, i just took out all the parts which called the attack sequence)when you have both Twisted resource and my resource running, his new aiplayer.cs file had the functions: SpawnAtMarker and Spawn...etc. and so did my aiMarker.cs
So the fix was to change the functiosn in mine from spawnAtMarker to spawnFriendAtMarker, and then when the functions meantioned spawnAtMarker, just change that to spawnFriendAtMarker :) <- if you look at the new aimarker.cs file you will see ;)
From Max
Ps. Just wondering...what is you project on (i think you said it was a school project)
02/19/2009 (9:41 pm)
@ Tom:Basically, the problem was that because my resource is an edit of his (basically, i just took out all the parts which called the attack sequence)when you have both Twisted resource and my resource running, his new aiplayer.cs file had the functions: SpawnAtMarker and Spawn...etc. and so did my aiMarker.cs
So the fix was to change the functiosn in mine from spawnAtMarker to spawnFriendAtMarker, and then when the functions meantioned spawnAtMarker, just change that to spawnFriendAtMarker :) <- if you look at the new aimarker.cs file you will see ;)
From Max
Ps. Just wondering...what is you project on (i think you said it was a school project)
#19
Well I have two classes right now. One is to take the torque FPS Demo and pretty much Mod it and make your own game. Each week has objectives, and certain things that need to be in your game. This week i needed Ai and i also need to make a vehicle that the player can get in.
My other class is the Mid-Term Project Class. In this class you pick any engine of your choice, and you go through the whole game design process. You start the with Game design docs, tech docs, asset lists etc. Then you move from Alfa, Beta, and then the Gold stage. Right now we are in beta. Next week int he end of the semester so our game level should be done.
If you are interested when im am done i cangive you a copy of it so you can see everything in action. I think this year ill graduate with my bachelors of science and game and computer simulation.
02/19/2009 (10:28 pm)
Ah very cool Max! Works perfectly!Well I have two classes right now. One is to take the torque FPS Demo and pretty much Mod it and make your own game. Each week has objectives, and certain things that need to be in your game. This week i needed Ai and i also need to make a vehicle that the player can get in.
My other class is the Mid-Term Project Class. In this class you pick any engine of your choice, and you go through the whole game design process. You start the with Game design docs, tech docs, asset lists etc. Then you move from Alfa, Beta, and then the Gold stage. Right now we are in beta. Next week int he end of the semester so our game level should be done.
If you are interested when im am done i cangive you a copy of it so you can see everything in action. I think this year ill graduate with my bachelors of science and game and computer simulation.
#20
I would be very interested ina copy of your game/project once it's complete.
Also, if you are still working out how to add a drivable car to your FPS, thencheck out my other resource "How to add a drivable car to your FPS" (just search it here on GG.com)
From Max
PS. Did yoyu say your Bachelor or science and game and computer simulation, as in you are at Uni? Because if so, it is funny that i am helping you, when i'm only 13!
02/19/2009 (11:48 pm)
Well Tom,I would be very interested ina copy of your game/project once it's complete.
Also, if you are still working out how to add a drivable car to your FPS, thencheck out my other resource "How to add a drivable car to your FPS" (just search it here on GG.com)
From Max
PS. Did yoyu say your Bachelor or science and game and computer simulation, as in you are at Uni? Because if so, it is funny that i am helping you, when i'm only 13!

Torque Owner Maximillian Brewer