Help in Creating or Spawning Multiple Bots in Starter.FPS
by DavidF215 · in Torque Game Engine · 10/02/2006 (4:09 pm) · 3 replies
This is my first post. Hope it's helpful to someone in the future. I never found a quick guide on where and what code to implement to create multiple bots quickly, so I'm creating one.
QUICK STEPS:
1. If you are currently in a starter.fps game, then completely exit the game for changes to take effect.
2. Open the following file: %TorqueRoot%\SDK\example\starter.fps\server\scripts\aiPlayer.cs.
3. Find this function near line number 223: AIManager::think(%this)
4. Delete this code within the function:
if (!isObject(%this.player))
%this.player = %this.spawn();
5. Add this code in its place:
for (%x=0; %x<10; %x++){
if (!isObject(%this.bot[%x]) && getRealTime()/1000 -%tmr > 2){
%this.bot[%x]=%this.spawn(%x);
//Reset timer
%tmr=getRealTime()/1000;
}
}
6. Find this function, which should be after the "AIManager::think" function: AIManager::spawn(%this)
7. Modify the function definition like so:
AIManager::spawn(%this, %nmbr)
The %nmbr parameter will help in providing a unique name for each Bot.
8. Replace the entire function with this code instead:
%player = AIPlayer::spawn("Orc " @ %nmbr, pickSpawnPoint());
%player.followPath("MissionGroup/Paths/Path1",-1);
%player.mountImage(CrossbowImage,0);
%player.setInventory(CrossbowAmmo,1000);
Note the changes in the first line. First, we call "AIPlayer::spawn" instead of "AIPlayer::spawnOnPath." This modification is not necessary, but it creates some variety in where the bots appear. The second change on the first line is replacing ("Kork","MissionGroup/Paths/Path1") with ("Orc_" @ %nmbr, pickSpawnPoint()). The first parameter creates a unique name for the bot, and the second parameter provides a spawn location for the bots, which cannot be a path.
9. Save the modified script file.
10. Rerun the TorqueDemo executable.
11. Once you are in the game, there is a player spawn point that needs to be moved, otherwise, the dumb bots will be stuck in one of the towers. So press F11 to open the Mission Editor.
12. In the Mission Editor expand the "MissionGroup - SimGroup" container in the right column.
13. Find and expand the "PlayerDropPoints - SimGroup" container.
14. The SpawnSphere of interest is the first one (1428). Click on it to highlight and activate it.
15. Release the camera from the Player object by pressing ALT+C.
16. "Fly" around and find the activated SpawnSphere. It is in a tower that borders the lake. Position the camera so that you can click on the X, Y, and Z axis modifers for the object to move it out of the tower.
17. Once the SpawnSphere is moved out of the tower to a desired location, save the mission: File > SaveMission.
18. Press F11 to exit the Mission Editor.
19. Return the camara to the player's viewpoint by pressing ALT+C again.
20. If any Orc Bots were spawned in the tower, you can either shoot and kill them, or simply restart the Mission.
NOTES
1. Be sure to modify one of the PlayerDropPoints to prevent the bots from being stuck in that tower.
2. Increase or decrease the number of desired Bots by modifying the number "10" in the For loop.
3. The timer code "getRealTime()/1000 -%tmr > 2" is used to prevent Bots from being created atop each other at the spawn points. You can modify the number "2" to increase or decrease the interval.
4. You can create another SimGroup for Bot Drop Points rather than using the PlayerDropPoint locations.
5. The bots are spawned at PlayerDropPoints and are given orders to follow the "Path1" path markers. Alternatively, you can create another path for the Bots to follow, or no path at all.
REMARKS
Programming more detailed AI, which is beyond this quick tutorial, is needed for the bots to shot, retrieve ammo, and move more intelligently. I am still new to Torque scripting (2 weeks), and there could be errors in the code, so let me know of any, and I'll investigate and modify the code.
Good luck
QUICK STEPS:
1. If you are currently in a starter.fps game, then completely exit the game for changes to take effect.
2. Open the following file: %TorqueRoot%\SDK\example\starter.fps\server\scripts\aiPlayer.cs.
3. Find this function near line number 223: AIManager::think(%this)
4. Delete this code within the function:
if (!isObject(%this.player))
%this.player = %this.spawn();
5. Add this code in its place:
for (%x=0; %x<10; %x++){
if (!isObject(%this.bot[%x]) && getRealTime()/1000 -%tmr > 2){
%this.bot[%x]=%this.spawn(%x);
//Reset timer
%tmr=getRealTime()/1000;
}
}
6. Find this function, which should be after the "AIManager::think" function: AIManager::spawn(%this)
7. Modify the function definition like so:
AIManager::spawn(%this, %nmbr)
The %nmbr parameter will help in providing a unique name for each Bot.
8. Replace the entire function with this code instead:
%player = AIPlayer::spawn("Orc " @ %nmbr, pickSpawnPoint());
%player.followPath("MissionGroup/Paths/Path1",-1);
%player.mountImage(CrossbowImage,0);
%player.setInventory(CrossbowAmmo,1000);
Note the changes in the first line. First, we call "AIPlayer::spawn" instead of "AIPlayer::spawnOnPath." This modification is not necessary, but it creates some variety in where the bots appear. The second change on the first line is replacing ("Kork","MissionGroup/Paths/Path1") with ("Orc_" @ %nmbr, pickSpawnPoint()). The first parameter creates a unique name for the bot, and the second parameter provides a spawn location for the bots, which cannot be a path.
9. Save the modified script file.
10. Rerun the TorqueDemo executable.
11. Once you are in the game, there is a player spawn point that needs to be moved, otherwise, the dumb bots will be stuck in one of the towers. So press F11 to open the Mission Editor.
12. In the Mission Editor expand the "MissionGroup - SimGroup" container in the right column.
13. Find and expand the "PlayerDropPoints - SimGroup" container.
14. The SpawnSphere of interest is the first one (1428). Click on it to highlight and activate it.
15. Release the camera from the Player object by pressing ALT+C.
16. "Fly" around and find the activated SpawnSphere. It is in a tower that borders the lake. Position the camera so that you can click on the X, Y, and Z axis modifers for the object to move it out of the tower.
17. Once the SpawnSphere is moved out of the tower to a desired location, save the mission: File > SaveMission.
18. Press F11 to exit the Mission Editor.
19. Return the camara to the player's viewpoint by pressing ALT+C again.
20. If any Orc Bots were spawned in the tower, you can either shoot and kill them, or simply restart the Mission.
NOTES
1. Be sure to modify one of the PlayerDropPoints to prevent the bots from being stuck in that tower.
2. Increase or decrease the number of desired Bots by modifying the number "10" in the For loop.
3. The timer code "getRealTime()/1000 -%tmr > 2" is used to prevent Bots from being created atop each other at the spawn points. You can modify the number "2" to increase or decrease the interval.
4. You can create another SimGroup for Bot Drop Points rather than using the PlayerDropPoint locations.
5. The bots are spawned at PlayerDropPoints and are given orders to follow the "Path1" path markers. Alternatively, you can create another path for the Bots to follow, or no path at all.
REMARKS
Programming more detailed AI, which is beyond this quick tutorial, is needed for the bots to shot, retrieve ammo, and move more intelligently. I am still new to Torque scripting (2 weeks), and there could be errors in the code, so let me know of any, and I'll investigate and modify the code.
Good luck
Torque 3D Owner Morrie