Unlimited Ammo Problems
by N.K. · in Torque Game Engine · 04/26/2009 (4:42 pm) · 4 replies
Hey,
I wanted to give my AI bots unlimited ammo so I created a function AddBots(%num) with the following lines
for(%i =0;%i < %num; %i++) {
%bot = new AiBot() {
datablock = PlayerBody;};
%spawn = pickSpawnPoint();
%bot.setTransform(%spawn);
%bot.mountImage(crossbowimage, 0);
%bot.setInventory(crossbowammo, 100000);
}
The problem is that despite setting a very large number for the crossbowammo, the bots run out of ammo after about 5 mins of almost continuous shooting. Is there some limit on the maximum ammo that can be assigned to a bot or is there something wrong with my code?
Cheers
I wanted to give my AI bots unlimited ammo so I created a function AddBots(%num) with the following lines
for(%i =0;%i < %num; %i++) {
%bot = new AiBot() {
datablock = PlayerBody;};
%spawn = pickSpawnPoint();
%bot.setTransform(%spawn);
%bot.mountImage(crossbowimage, 0);
%bot.setInventory(crossbowammo, 100000);
}
The problem is that despite setting a very large number for the crossbowammo, the bots run out of ammo after about 5 mins of almost continuous shooting. Is there some limit on the maximum ammo that can be assigned to a bot or is there something wrong with my code?
Cheers
About the author
#2
The weapon will no longer decrease the ammo when fired.
04/27/2009 (4:20 am)
You could make a bot only weapon.. basically a copy of the weapon you want to use.. then in the on fire function remove these lines(bottom of crossbow.cs is an example in the CrossbowImage::onFire function):// Decrement inventory ammo. The image's ammo state is update // automatically by the ammo inventory hooks. %obj.decInventory(%this.ammo,1);
The weapon will no longer decrease the ammo when fired.
#3
04/27/2009 (4:56 am)
Quote:adjust the max inventory settingThat's in the datablock by the way, and it looks like from your spawn function that you're simply using the standard PlayerBody datablock -- which is limited to 50 CrossbowAmmo. So if you want bots to have different limits than players you'll need to use a derived datablock and inheritance for you bots.
#4
04/27/2009 (5:25 pm)
or, you could do the decrement inventory ammo like this:// Decrement inventory ammo. The image's ammo state is update
// automatically by the ammo inventory hooks.
if(!%obj.client.isAiControlled()) // only decrement if the player is NOT a bot...
%obj.decInventory(%this.ammo,1);
Torque 3D Owner Camel Taylor