Putting more orcs in the game
by Caleb Rogers · in Torque Game Engine · 12/24/2006 (1:27 pm) · 16 replies
I'm not new to programming, but I'm new to Torque, and I'm a bit lost regarding adding more orcs to the game. I can't seem to get it right. I searched for an answer, but didn't really find much. I did find one thread from two years ago and implemented that code with some success. Though, there was still some weird spawning going on. All of my efforts thus far have been focused on one function in the aiPlayer.cs file located in starter.fps/server/scripts.
Here's what I did at first (inside the spawn function):
---------------------------------------------------------------------------------------------
%player = AIPlayer::spawnOnPath("Kork1","MissionGroup/Paths/Path1");
%player.followPath("MissionGroup/Paths/Path1",-1);
%player.mountImage(CrossbowImage,0);
%player.setInventory(CrossbowAmmo,1000);
%player = AIPlayer::spawnOnPath("Kork2","MissionGroup/Paths/Path2");
%player.followPath("MissionGroup/Paths/Path2",-1);
%player.mountImage(CrossbowImage,0);
%player.setInventory(CrossbowAmmo,1000);
return %player;
--------------------------------------------------------------------------------------------------
I had made another path, called Path2, and Kork2 ran around on it just fine. But... after a while, another Kork1 spawned on the same path. I don't know why this happens. So, I went back the the original spawn function (which was commented out at this point) and edited it like so:
------------------------------------------------------------------------------------------------
%player = AIPlayer::spawnOnPath("Kork","MissionGroup/Paths/Path1");
if (isObject(%player))
{
%player.followPath("MissionGroup/Paths/Path1",-1);
%player.mountImage(CrossbowImage,0);
%player.setInventory(CrossbowAmmo,1000);
return %player;
}
else
return 0;
// This is what I Added
%player = AIPlayer::spawnOnPath("Dork","MissionGroup/Paths/Path2");
%player.followPath("MissionGroup/Paths/Path2",-1);
%player.mountImage(CrossbowImage,0);
%player.setInventory(CrossbowAmmo,1000);
return %player;
---------------------------------------------------------------------------------------------------
This spawned Kork, but no Dork. I haven't really found much of an answer in my searching, and my experimentation isn't too fruitful. Though, people are making games, so someone has to know...
Here's what I did at first (inside the spawn function):
---------------------------------------------------------------------------------------------
%player = AIPlayer::spawnOnPath("Kork1","MissionGroup/Paths/Path1");
%player.followPath("MissionGroup/Paths/Path1",-1);
%player.mountImage(CrossbowImage,0);
%player.setInventory(CrossbowAmmo,1000);
%player = AIPlayer::spawnOnPath("Kork2","MissionGroup/Paths/Path2");
%player.followPath("MissionGroup/Paths/Path2",-1);
%player.mountImage(CrossbowImage,0);
%player.setInventory(CrossbowAmmo,1000);
return %player;
--------------------------------------------------------------------------------------------------
I had made another path, called Path2, and Kork2 ran around on it just fine. But... after a while, another Kork1 spawned on the same path. I don't know why this happens. So, I went back the the original spawn function (which was commented out at this point) and edited it like so:
------------------------------------------------------------------------------------------------
%player = AIPlayer::spawnOnPath("Kork","MissionGroup/Paths/Path1");
if (isObject(%player))
{
%player.followPath("MissionGroup/Paths/Path1",-1);
%player.mountImage(CrossbowImage,0);
%player.setInventory(CrossbowAmmo,1000);
return %player;
}
else
return 0;
// This is what I Added
%player = AIPlayer::spawnOnPath("Dork","MissionGroup/Paths/Path2");
%player.followPath("MissionGroup/Paths/Path2",-1);
%player.mountImage(CrossbowImage,0);
%player.setInventory(CrossbowAmmo,1000);
return %player;
---------------------------------------------------------------------------------------------------
This spawned Kork, but no Dork. I haven't really found much of an answer in my searching, and my experimentation isn't too fruitful. Though, people are making games, so someone has to know...
#2
12/24/2006 (5:47 pm)
Well, I looked at that yesterday. Actually, I just glanced at it, and it looked like it needed an engine recompile, so I put it aside for now. Of course, I could be wrong because I didn't look too closely. If that one does need a recompile to work right, can I do what I want to do by scripting?
#3
12/24/2006 (8:11 pm)
You may want look AiGuard again, you drop couple file in engine/game. Add them to the project and recompile. Add cs file and couple line in script you good to go.
#4
12/25/2006 (7:08 am)
I found the AiGuard resource to be super simple to apply. I was totally new to torque when I attempted it, and had it working in just a few minutes. You aren't changing any C++ code. Just adding a couple of files and recompiling. The rest is done in scripts. Take a real good look at it. I think you'll find it easy to implement, and will do what you need.
#5
12/25/2006 (8:50 am)
Well, I'm going to give it a shot. Though, I've gotta upgrade my compiler. Apparently VC 7.0 doesn't like the SDK solution file...
#6
On to the searching...
12/29/2006 (6:05 pm)
OK, I've got visual studio 2005, and I followed the build instructions in the TDN page for TGE 1.4 and VS2005. It didn't work...I got errors. I'm going to search through the forums to see if there's any fix for this. If anyone has a quick fix or maybe a bookmarked link they can pass along, please do.On to the searching...
#7
%player = AIPlayer::spawnOnPath("Kork","MissionGroup/Paths/Path1");
if (isObject(%player))
{
%player.followPath("MissionGroup/Paths/Path1",-1);
%player.mountImage(CrossbowImage,0);
%player.setInventory(CrossbowAmmo,1000);
return %player; //-------HERE-------
}
else
return 0; //------- AND HERE-------
// This is what I Added
%player = AIPlayer::spawnOnPath("Dork","MissionGroup/Paths/Path2");
%player.followPath("MissionGroup/Paths/Path2",-1);
%player.mountImage(CrossbowImage,0);
%player.setInventory(CrossbowAmmo,1000);
return %player;
If this code is run in a function the function would return before reaching the code where you added Dork.
The spawn function was intended to be used once per bot I think. You should upgrade the function to take the player name and the path as parameters, and call the function twice using different input.
P.S. AI Guard is a great starting point for an AI.
12/29/2006 (7:14 pm)
Caleb look at the returns in your first post.%player = AIPlayer::spawnOnPath("Kork","MissionGroup/Paths/Path1");
if (isObject(%player))
{
%player.followPath("MissionGroup/Paths/Path1",-1);
%player.mountImage(CrossbowImage,0);
%player.setInventory(CrossbowAmmo,1000);
return %player; //-------HERE-------
}
else
return 0; //------- AND HERE-------
// This is what I Added
%player = AIPlayer::spawnOnPath("Dork","MissionGroup/Paths/Path2");
%player.followPath("MissionGroup/Paths/Path2",-1);
%player.mountImage(CrossbowImage,0);
%player.setInventory(CrossbowAmmo,1000);
return %player;
If this code is run in a function the function would return before reaching the code where you added Dork.
The spawn function was intended to be used once per bot I think. You should upgrade the function to take the player name and the path as parameters, and call the function twice using different input.
P.S. AI Guard is a great starting point for an AI.
#8
12/29/2006 (7:47 pm)
Thanks, Stephen. I'm working on getting the AI Guard going right now, but thanks for the info on the included function. I've got so much to learn about this engine and Torquescript.
#9
12/29/2006 (8:37 pm)
What you need to know about AIGuard? I use it all the time.
#10
So, after that didn't work, I decided to peek inside the aiguard.cs file. Here's the first thing that stood out:
-----------------------------------------------------------------------------------------------
//The following are global variables used to set the guards basic settings.
$AI_GUARD_ENABLED = false; //Whether Guard bots are loaded during mission loading.
$AI_GUARD_MARKER_HIDE = true; //Turns marker hiding on or off - useful when editing maps.
$AI_GUARD_WEAPON = "Shotgun"; //Which weapon do you want the guard to use
$AI_GUARD_ENDLESS_AMMO = false; //When set to true the guard will replenish its ammo perpetually
$AI_GUARD_WEAPON_USES_AMMO = true; //Set this to false for energy weapons that do not use ammo
$AI_GUARD_SIDESTEP = 50; //This value helps determine how far a bot sidesteps when he is stuck.
-----------------------------------------------------------------------------------------------
So...I need to change the weapon to crossbow and enable and unhide the guard? Are there any other things I need to change that might not stand out so that this guard will work?
12/30/2006 (10:21 am)
Well, Fucifer, the AIGuard isn't quite drop in and go as was suggested. I added the files to the build and had a successful compile. When I run a mission and go into the editor, there is the aiguardmarker where the instructions suggest. But, when I save and reload the mission, my guard is not there. I went through this three times, reading the instructions each time to make sure I didn't overlook anything.So, after that didn't work, I decided to peek inside the aiguard.cs file. Here's the first thing that stood out:
-----------------------------------------------------------------------------------------------
//The following are global variables used to set the guards basic settings.
$AI_GUARD_ENABLED = false; //Whether Guard bots are loaded during mission loading.
$AI_GUARD_MARKER_HIDE = true; //Turns marker hiding on or off - useful when editing maps.
$AI_GUARD_WEAPON = "Shotgun"; //Which weapon do you want the guard to use
$AI_GUARD_ENDLESS_AMMO = false; //When set to true the guard will replenish its ammo perpetually
$AI_GUARD_WEAPON_USES_AMMO = true; //Set this to false for energy weapons that do not use ammo
$AI_GUARD_SIDESTEP = 50; //This value helps determine how far a bot sidesteps when he is stuck.
-----------------------------------------------------------------------------------------------
So...I need to change the weapon to crossbow and enable and unhide the guard? Are there any other things I need to change that might not stand out so that this guard will work?
#11
12/30/2006 (10:47 am)
OK, well, that was what I needed to fix. I placed 3 guards and had three guards. However, there was one oddity. When the guard moved, there was another orc model standing in the same place, sans crossbow. After a moment the crossbow appears as the guard spawns. I tried running through the guard before the crossbow appears, and there's no collision. Is this the respawn rate or something else?
#12
Change the false to true. Otherwise, there isn't a guard shown.
Keep the marker hidden. It's just a spawn sphere.
12/30/2006 (10:51 am)
$AI_GUARD_ENABLED = false; //Whether Guard bots are loaded during mission loading.Change the false to true. Otherwise, there isn't a guard shown.
Keep the marker hidden. It's just a spawn sphere.
#13
Change it to this.
1. Another common misstake is not setup the player.cs file correct in the data/shapes/player folder. Open the player.cs take look at these lines.
You cannot have these lines the same in two different player.cs you will create problem. Here two example.
example 1
example 2
2. Another common problem is not setup the dataBlock for the player correctly. If you using different dts to have various enemies let me know I can walk you threw it. I look at alot resource the AIGuard is the easy one to use.
3. I read and follow new instruction on clean install TGE 1.5.0, it thing work perfectly.
12/30/2006 (4:30 pm)
I assume you knew Torque very well which I should not have. You did not say anything about this, in game.cs did you go to this code section.// Start the AIManager
new ScriptObject(AIManager) {};
MissionCleanup.add(AIManager);
AIManager.think();
}Change it to this.
// Start the AIManager
new ScriptObject(AIManager) {};
MissionCleanup.add(AIManager);
AIManager.think();
AIGuard::LoadEntities();
AIPatrol::LoadEntities();
}1. Another common misstake is not setup the player.cs file correct in the data/shapes/player folder. Open the player.cs take look at these lines.
datablock TSShapeConstructor(PlayerDts)
{
baseShape = "./player.dts";You cannot have these lines the same in two different player.cs you will create problem. Here two example.
example 1
datablock TSShapeConstructor(PlayerDts)
{
baseShape = "./player.dts";example 2
datablock TSShapeConstructor(JillDts)
{
baseShape = "./jill.dts";2. Another common problem is not setup the dataBlock for the player correctly. If you using different dts to have various enemies let me know I can walk you threw it. I look at alot resource the AIGuard is the easy one to use.
3. I read and follow new instruction on clean install TGE 1.5.0, it thing work perfectly.
#14
if you open aiguard.cs go to line 77.
Now if you to the player.cs file in server/scripts you will not see this datablock that because you have not setup yet. Open player.cs file goto line 671 above this line you will see ( I am assume you doing this on clean install if not the lines number will be off).
Now below that add this.
Now you have your datablock setup for the AIGuard, this will inherit everything from the datablock PlayerData(PlayerBody) in the player.cs in server/scripts. Now you can change the dts model and path to whatever you want in the new datablock but the player must be setup in Torque to work.
12/30/2006 (4:49 pm)
"When the guard moved, there was another orc model standing in the same place, sans crossbow. After a moment the crossbow appears as the guard spawns. " I have never had this happen, so I would have to look at the code you add. if you open aiguard.cs go to line 77.
datablock PlayerData(GuardPlayer : PlayerBody)
Now if you to the player.cs file in server/scripts you will not see this datablock that because you have not setup yet. Open player.cs file goto line 671 above this line you will see ( I am assume you doing this on clean install if not the lines number will be off).
maxInv[CrossbowAmmo] = 50; maxInv[Crossbow] = 1; maxInv[Rifle] = 1; };
Now below that add this.
// Orc test for aiguard
datablock PlayerData(GuardPlayer : PlayerBody)
{
shapeFile = "~/data/shapes/player/player.dts";
};
// Orc test for aiguard)Now you have your datablock setup for the AIGuard, this will inherit everything from the datablock PlayerData(PlayerBody) in the player.cs in server/scripts. Now you can change the dts model and path to whatever you want in the new datablock but the player must be setup in Torque to work.
#15
12/30/2006 (4:52 pm)
If you have problems setup your cs file email them to me I will set them up for you.
#16
01/01/2007 (12:19 pm)
Well, I'm messing around with things right now and I've made some progress. It's got some good functionality and I will be using it a lot. I'm sure I'll have more questions later.
Torque Owner Mike Rowley
Mike Rowley