AIPlayer Questions - Populating missions with different bots
by Nick Zafiris · in Torque Game Engine · 05/12/2004 (1:39 pm) · 12 replies
Hello everyone,
I bought the Torque engine about a month ago and its about time I make my first post. It's impressive how I've managed to learn many things about the engine just by searching the site and reading resources and threads.
Here I go. I got a basic flat level with a few interiors and I can get a few bots to spawn and do basic things like move here and there arm and shoot.
I've also applied the AI Extensions resource and got it working.
Now, what if I want to have 2 or more different kinds of enemies, for example some ogres, some goblins and some trolls, would I need 3 different spawn functions within aiplayer.cs.
Or would I create 3 different script files, one for each enemy type? Where would they be called from?
Also, how would I go about populating the level with lets say 10 of each? If I have predefined spawnspheres which have names would I have to manualy spawn each enemy to it's own sphere? I dont really want to have them appear completely in random.
Thanks in advance for your help,
Nick
I bought the Torque engine about a month ago and its about time I make my first post. It's impressive how I've managed to learn many things about the engine just by searching the site and reading resources and threads.
Here I go. I got a basic flat level with a few interiors and I can get a few bots to spawn and do basic things like move here and there arm and shoot.
I've also applied the AI Extensions resource and got it working.
Now, what if I want to have 2 or more different kinds of enemies, for example some ogres, some goblins and some trolls, would I need 3 different spawn functions within aiplayer.cs.
Or would I create 3 different script files, one for each enemy type? Where would they be called from?
Also, how would I go about populating the level with lets say 10 of each? If I have predefined spawnspheres which have names would I have to manualy spawn each enemy to it's own sphere? I dont really want to have them appear completely in random.
Thanks in advance for your help,
Nick
#2
So currently the spawn function is like this:
"function AIPlayer::spawn(%name,%spawnPoint)
Should I create a third parameter on the function, or just pass the creature type as a global?
And what would be the best place to call the AIPlayer::spawn function from? AIManager?
I'm really trying to find out how it flows.
Also, to fill the level with many creatures, would a for loop be the best approach?
Thanks again. I'm sure other noobs will find this info usefull too.
Nick
05/12/2004 (10:49 pm)
Thanks Stephen!So currently the spawn function is like this:
"function AIPlayer::spawn(%name,%spawnPoint)
Should I create a third parameter on the function, or just pass the creature type as a global?
And what would be the best place to call the AIPlayer::spawn function from? AIManager?
I'm really trying to find out how it flows.
Also, to fill the level with many creatures, would a for loop be the best approach?
Thanks again. I'm sure other noobs will find this info usefull too.
Nick
#3
Here's what I got so far.
function AIPlayer::spawn(%name,%spawnPoint)
{
// Create the Ogre player object
if (%name $= "Ogre")
{
%ogre = new AiPlayer()
{
dataBlock = DemoPlayer;
path = "";
};
MissionCleanup.add(%ogre);
%ogre.setShapeName(%name);
%ogre.setTransform(pickSpawnPointOgre());
%ogre.followPath("MissionGroup/newPaths/newPath",-1);
%ogre.mountImage(CrossbowImage,0);
%ogre.setInventory(CrossbowAmmo,1000);
}
// Create the Kork player object
if (%name $= "Kork")
{
%kork = new AiPlayer()
{
dataBlock = DemoPlayer;
path = "";
};
MissionCleanup.add(%kork);
%kork.setShapeName(%name);
%kork.setTransform(%spawnPoint);
%kork.followPath("MissionGroup/Paths/Path1",-1);
%kork.mountImage(CrossbowImage,0);
%kork.setInventory(CrossbowAmmo,1000);
}
//return %player;
}
function AIManager::spawn(%this){
%ogre = AIPlayer::spawnOnPath("Ogre","MissionGroup/newPaths/newPath");
%kork = AIPlayer::spawnOnPath("Kork","MissionGroup/Paths/Path1");
//return %player;
}
The spawnOnPath function is intact.
Am I on the right track or am I doing something wrong? If anyone could help I'd appreciate it.
Nick
05/13/2004 (11:29 pm)
I've managed to spawn 2 different types of bots and run in circles in 2 seperate paths. I know I'm using the same model but that's ok for now.Here's what I got so far.
function AIPlayer::spawn(%name,%spawnPoint)
{
// Create the Ogre player object
if (%name $= "Ogre")
{
%ogre = new AiPlayer()
{
dataBlock = DemoPlayer;
path = "";
};
MissionCleanup.add(%ogre);
%ogre.setShapeName(%name);
%ogre.setTransform(pickSpawnPointOgre());
%ogre.followPath("MissionGroup/newPaths/newPath",-1);
%ogre.mountImage(CrossbowImage,0);
%ogre.setInventory(CrossbowAmmo,1000);
}
// Create the Kork player object
if (%name $= "Kork")
{
%kork = new AiPlayer()
{
dataBlock = DemoPlayer;
path = "";
};
MissionCleanup.add(%kork);
%kork.setShapeName(%name);
%kork.setTransform(%spawnPoint);
%kork.followPath("MissionGroup/Paths/Path1",-1);
%kork.mountImage(CrossbowImage,0);
%kork.setInventory(CrossbowAmmo,1000);
}
//return %player;
}
function AIManager::spawn(%this){
%ogre = AIPlayer::spawnOnPath("Ogre","MissionGroup/newPaths/newPath");
%kork = AIPlayer::spawnOnPath("Kork","MissionGroup/Paths/Path1");
//return %player;
}
The spawnOnPath function is intact.
Am I on the right track or am I doing something wrong? If anyone could help I'd appreciate it.
Nick
#4
Good luck!
-s
05/14/2004 (11:01 am)
That looks about right! There are a couple of ways to do it, but that works!Good luck!
-s
#5
this means you are using the same datablock. The only thing
that changes is your Variable Name which is irrelavent.
Or maybe i just understood your statement wrong:
Hmmm... wonder if i should Submit... hehe...
05/17/2004 (3:10 am)
I think what you're doing is wrong...%ogre = new AiPlayer()and
%kork = new AiPlayer()
this means you are using the same datablock. The only thing
that changes is your Variable Name which is irrelavent.
Or maybe i just understood your statement wrong:
Quote:
I know I'm using the same model but that's ok for now.
Hmmm... wonder if i should Submit... hehe...
#6
I wanted to keep the learning process simple by having one datablock for now.
Basically I'm trying to figure out how to pass the type of the creature to the spawn function. So far all tutorials assume you have an ogre. What if I have many other types.
Would I use global variables? Or is it better to have a seperate .cs file for each one (troll.cs, dragon.cs, etc.)?
The "return %player" confuses me.
Thanks,
Nick
05/17/2004 (3:23 am)
Hey thanks for the reply!I wanted to keep the learning process simple by having one datablock for now.
Basically I'm trying to figure out how to pass the type of the creature to the spawn function. So far all tutorials assume you have an ogre. What if I have many other types.
Would I use global variables? Or is it better to have a seperate .cs file for each one (troll.cs, dragon.cs, etc.)?
The "return %player" confuses me.
Thanks,
Nick
#7
If I remeber correctly, what they had was in:
realmwars
|-->example
_____|-->realmwars
__________|-->data
_______________|-->shapes
____________________|-->player
____________________|-->orc
____________________|-->elf
"_" are spaces.
r/Alex
05/17/2004 (4:16 am)
Its been a while since I played around with the game AI but last year, I did some stuff with AI and I followed how RealmWars did it which is to create different directories and .cs files for each type of model. If I remeber correctly, what they had was in:
realmwars
|-->example
_____|-->realmwars
__________|-->data
_______________|-->shapes
____________________|-->player
____________________|-->orc
____________________|-->elf
"_" are spaces.
r/Alex
#8
Cheers,
Shane
07/09/2004 (3:44 am)
Nick: Hey, did u get anywhere on this? You've a couple of months jump on me with Torque, so i'm only arriving at this problem with my game! Any help would be great.Cheers,
Shane
#9
My code above will get you a couple bots and you can also read this thread where many useful ideas are presented.
I decided to stop working on this since a few guys are currently working on making a very robust AI pack. I'm waiting for that to be released.
So currently I'm going through the book to learn a little bit more about the inner workings of Torque and at the same time trying to make my first level using Hammer.
Regards,
Nick
07/09/2004 (4:36 am)
Shane,My code above will get you a couple bots and you can also read this thread where many useful ideas are presented.
I decided to stop working on this since a few guys are currently working on making a very robust AI pack. I'm waiting for that to be released.
So currently I'm going through the book to learn a little bit more about the inner workings of Torque and at the same time trying to make my first level using Hammer.
Regards,
Nick
#10
But i may have to get back to figuring this out later on, i took the make your own AI file route, (cc,h,cs).
I did have 2 separate AI (models/datablocks) awhile back, but one spawned on aimanager and one with the ctrl-b bind and could never get the both of then to spawn with the aimanager.
Going through the engine code in aiplayer.h ,right away it says #ifndef _PLAYER_H_
#include "game/player.h"
#endif
so my next step would be to create a second player.cc and .h (haven't tried yet) it really dont make any sense to me (the default AI).
My biggest problem is the script (i still dont know it very well), I'm sure what we are trying to do could be manipulated in script, all the same i would rather have AI totally separate from player.
Eventually i will Figure this out.
07/09/2004 (5:19 am)
The default AI dont make much sense to me either, i was working on this too, but stopped with the AI extensions resource update also, be cause of the future aipack.But i may have to get back to figuring this out later on, i took the make your own AI file route, (cc,h,cs).
I did have 2 separate AI (models/datablocks) awhile back, but one spawned on aimanager and one with the ctrl-b bind and could never get the both of then to spawn with the aimanager.
Going through the engine code in aiplayer.h ,right away it says #ifndef _PLAYER_H_
#include "game/player.h"
#endif
so my next step would be to create a second player.cc and .h (haven't tried yet) it really dont make any sense to me (the default AI).
My biggest problem is the script (i still dont know it very well), I'm sure what we are trying to do could be manipulated in script, all the same i would rather have AI totally separate from player.
Eventually i will Figure this out.
#11
07/09/2004 (7:54 am)
The default AI is very simple; at least, aiPlayer is. It's just a class that acts like Player but moves where you tell it to. AIConnection is a class which acts like a GameConnection but just sits there - it's a dummy for book-keeping. And the AIMove stuff is ued to let the AIPlayer class subclass properly.
#12
id like to see the AIPlayer running its never ending marathon until the player gets in its site range then open up on the player and if the AI kills the player go back to running the marathon.
But i also know why it doesn't, because its a simple AI. So the reason i resort to resources. Heh
07/09/2004 (4:42 pm)
Ive never really messed with AI or Player stuff before other then just changing variables, The best way for me to learn is by example.id like to see the AIPlayer running its never ending marathon until the player gets in its site range then open up on the player and if the AI kills the player go back to running the marathon.
But i also know why it doesn't, because its a simple AI. So the reason i resort to resources. Heh
Torque Owner Stephen Clark
For the spawning together, here's what you do. Do NOT reselect the spawnPoint, and each time you spawn a guy add a random ammount to the spawnpoint.
easy peasy!
-s