Bot AI firing, another try...
by Josef Jahn · in Torque Game Engine · 03/12/2003 (7:58 am) · 15 replies
There have been 2 threads about this topic, but none yielded any answer so I'm trying it again:
Has anyone got the bots to shoot with HEAD?
This code....
Any Ideas? I'm pretty desperate about this, and welcome all thoughts and suggestions.
Has anyone got the bots to shoot with HEAD?
This code....
const char *WeaponSlot = Con::getVariable("$WeaponSlot");
S32 slot = dAtoi(WeaponSlot);
// shoot trigger
movePtr->trigger[slot] = true;...does not work. Yes, I commented out the trigger state replication at the bottom of getAIMove. And yes, the bots have a mounted weapon + ammo.Any Ideas? I'm pretty desperate about this, and welcome all thoughts and suggestions.
#2
03/12/2003 (10:14 am)
Of course I did. The code snippet I quoted was taken from his code!
#3
Couple things to check: Make sure %player.setScanningPlayers(true); is in the bot script. Probably best in the spawning function for that bot. Also make sure the weapon is automatic on fire not semi-auto or fires on triggerUp or something.
03/12/2003 (10:35 am)
I'm using the HEAD version and haven't had problems with bots firing. I started with the Jimomighty/Stefan aiPlayer code files. They've been modified a little, but worked before I made changes.Couple things to check: Make sure %player.setScanningPlayers(true); is in the bot script. Probably best in the spawning function for that bot. Also make sure the weapon is automatic on fire not semi-auto or fires on triggerUp or something.
#4
I'm not using the scanningPlayers stuff though, as this only works for clients and not other bots (He browses thought the client list..)
All I do is set the aim target to a certain object (which works fine)
The C-code for setting the trigger in the move state is definitely being called, yet no shot. I also checked whether something might call ceaseFire (at least that's what it's called in my code), but everything looks fine.
So the bottom line is: The move contains the triggers properly set, but the firing doesn't get executed somewhere in shapeImage.cc
03/12/2003 (10:42 am)
Check, and check.I'm not using the scanningPlayers stuff though, as this only works for clients and not other bots (He browses thought the client list..)
All I do is set the aim target to a certain object (which works fine)
The C-code for setting the trigger in the move state is definitely being called, yet no shot. I also checked whether something might call ceaseFire (at least that's what it's called in my code), but everything looks fine.
So the bottom line is: The move contains the triggers properly set, but the firing doesn't get executed somewhere in shapeImage.cc
#5
My current bot code/script is a cluster f*. I need to go thru all of it and get that path finding stuff integrated :)
I'll post here again when I look at forcing the bots to fire unless someone can help sooner.
03/12/2003 (11:44 am)
ahhh, trying to get bots firing on other bots. I've only tried that with the older bots (now aiclient.cc) not the current aiplayer bots. I haven't tried manually (thru script) setting the bots to fire and stop fire with this newer code yet. I will be soon tho. The way I have bots working now makes it almost too hard once they "see" the player. They cloak, jumpjet, and rain a firestorm of gunfire on my player before I know what's going on.My current bot code/script is a cluster f*. I need to go thru all of it and get that path finding stuff integrated :)
I'll post here again when I look at forcing the bots to fire unless someone can help sooner.
#6
03/12/2003 (11:47 am)
Firing on other bots is not really the problem, you just have to modify Beffy's stuff to look through all player's not clients. Getting them squeeze the trigger is what driving me nuts. I't even more frustrating now that I know that others succeeded...
#7
03/12/2003 (12:09 pm)
Is your current aiplayer.cc file already customized quite a bit? If it's not, I'd take a look at it for you, compare it to what I have and see if I can get it to work. I guess if bots won't fire at all, I could also look at a unmodified version of the HEAD, drop the aiplayer files in and see if I can make them work.
#8
This is my ONLY modification to aiplayer.cc:
..in getAIMove()
and of course the functions that set these variables..
Yes, the weapon slot is 0, so trigger[0] is bein set true.
The bots get loaded up with weapon and ammo on spawn like this:
And just for reference, my reloadWeapon code:
The debug output says the reloading works ok, the player has 1 M4Image and 30 bullets for it. The same code is used for human players as well, and works without a problem.
setting movePtr->trigger[2] works fine and results in a jump, but movePtr->trigger[0] doesn't shoot.
Can you see something in there? If not, I'd be more than happy to send you my aiplayer.cc...
03/12/2003 (12:20 pm)
Here's something interesting: The bots DO jump!This is my ONLY modification to aiplayer.cc:
..in getAIMove()
// for Jimomighty's functions
if (mModeFire) {
const char *WeaponSlot = Con::getVariable("$WeaponSlot");
S32 slot = dAtoi(WeaponSlot);
if (slot < ShapeBase::MaxMountedImages) {
if (getMountedImage(slot)) {
if (!movePtr->trigger[slot]) {
//Con::warnf(ConsoleLogEntry::General, "Slot:");
//Con::warnf(ConsoleLogEntry::General, WeaponSlot);
// shoot trigger
movePtr->trigger[slot] = true;
}
}
}
}
if (mModeJump) {
if (canJump()) {
if (!movePtr->trigger[2]) {
movePtr->trigger[2] = true;
}
}
}
// end Jimomighty stuffand of course the functions that set these variables..
void AIPlayer::fireWeapon(bool enable) { // Jimomighty
// Fire the seclected weapon.
if(enable)
{
mModeFire = true;
throwCallback( "onShoot" );
}
else
{
mModeFire = false;
throwCallback( "onUnshoot" );
}
}
void AIPlayer::doJump(bool enable) { // Jimomighty
if(enable)
{
mModeJump = true;
mJump = true;
throwCallback( "onJump" );
}
else
{
mModeJump = false;
mJump = false;
throwCallback( "onUnjump" );
}
}
void AIPlayer::doJump() { // Jimomighty
doJump(true);
}Yes, the weapon slot is 0, so trigger[0] is bein set true.
The bots get loaded up with weapon and ammo on spawn like this:
%player.mountImage(M4Image, $WeaponSlot); %weapon = %player.getMountedImage($WeaponSlot); %player.setInventory(%weapon.magazine, 4); BOT_reloadWeapon(%player);
And just for reference, my reloadWeapon code:
function BOT_reloadWeapon(%player)
{
echo ("--[BOT WEAPON RELOAD]-----------------------------------");
%weapon = %player.getMountedImage($WeaponSlot);
echo ("weapon " @ %weapon);
echo ("weapon ammo type: " @ %weapon.ammo);
echo ("weapon magazine type: " @ %weapon.magazine);
echo ("weapon magazine capacity: " @ %weapon.magazine.magazineContents);
echo ("player ammo before reload: " @ %player.getInventory(%weapon.ammo));
echo ("player magazines before reload: " @ %player.getInventory(%weapon.magazine));
//Don't reload if we don't have any ammo
if (%player.getInventory(%weapon.magazine) <= 0)
return;
//Refilling bullets to max
%player.setInventory(%weapon.ammo, %weapon.magazine.magazineContents);
//Reduce magazine count by one
%newMags = %player.getInventory(%weapon.magazine) - 1;
if (%newMags < 0)
%newMags = 0;
%player.setInventory(%weapon.magazine, %newMags);
echo ("player ammo after reload: " @ %player.getInventory(%weapon.ammo));
echo ("player magazines after reload: " @ %player.getInventory(%weapon.magazine));
echo ("--------------------------------------------------------");
serverPlay3D(%weapon.reloadSound,%player.getTransform());
}The debug output says the reloading works ok, the player has 1 M4Image and 30 bullets for it. The same code is used for human players as well, and works without a problem.
setting movePtr->trigger[2] works fine and results in a jump, but movePtr->trigger[0] doesn't shoot.
Can you see something in there? If not, I'd be more than happy to send you my aiplayer.cc...
#9
if (slot < ShapeBase::MaxMountedImages) {
instead of:
if (slot >= 0 && slot < ShapeBase::MaxMountedImages) {
Doesn't seem like that should matter. Maybe try making the bot "use" the weapon after setting the inventory like this:
%player.use(WeaponItemName);
I guess it could also be the reloading. I can try dropping in your aiplayer.cc file and see if it works for me. At least you'd know if the problem was c-code or script side.
sabrecyd@yahoo.com
03/12/2003 (12:41 pm)
I just see the one line change (besides the comments): if (slot < ShapeBase::MaxMountedImages) {
instead of:
if (slot >= 0 && slot < ShapeBase::MaxMountedImages) {
Doesn't seem like that should matter. Maybe try making the bot "use" the weapon after setting the inventory like this:
%player.use(WeaponItemName);
I guess it could also be the reloading. I can try dropping in your aiplayer.cc file and see if it works for me. At least you'd know if the problem was c-code or script side.
sabrecyd@yahoo.com
#10
Oh another thought: I do NOT have the processTick stuff in there. In Beffy's code, it calls attackTarget which in turn does fireWeapon. But I don't see how this makes any difference, because the move is added properly on every getAIMove anyway...
03/12/2003 (12:47 pm)
I removed that because I thought that maybe this was the culprit, which it wasn't.Oh another thought: I do NOT have the processTick stuff in there. In Beffy's code, it calls attackTarget which in turn does fireWeapon. But I don't see how this makes any difference, because the move is added properly on every getAIMove anyway...
#11
Edit: Of course I'm using the scan setting so it makes sense. I'll take a look at the files you sent.
03/12/2003 (1:09 pm)
I think that's a problem. I just took out the processTick part to try it and my bots wouldn't fire anymore.Edit: Of course I'm using the scan setting so it makes sense. I'll take a look at the files you sent.
#12
And what I heard was "click-click-click-click-....", so the trigger state is indeed working.
What the hell is it that I'm too blind to see?
The bot has the weapon "AK47". The weapon's image "AK47Image" is mounted correctly. He has 30 shots of "AK47Bullet" loaded and ready. See:
I even dumped the ammo count twice in different locations just to make sure. Yet all I get on the image is the dryfire state. I probably don't have to add that the weapon works perfectly for human players, and that nothing terribly fundamental has been changed from the example "Rifle".
I'm sure the solution is simple, short, and makes look like the idiot I am.
03/13/2003 (2:56 pm)
Ok, after comparing my aiplayer.cc with Sabrecyd's (thanks btw!) and not finding any problem with the trigger code, I got the bright idea of inserting a dryfire sound to the weapon my bot is holding.And what I heard was "click-click-click-click-....", so the trigger state is indeed working.
What the hell is it that I'm too blind to see?
The bot has the weapon "AK47". The weapon's image "AK47Image" is mounted correctly. He has 30 shots of "AK47Bullet" loaded and ready. See:
==>aiplayer::spawnplayer(); --[BOT WEAPON RELOAD]----------------------------------- weapon 154 weapon ammo type: AK47Bullet weapon magazine type: AK47Magazine weapon magazine capacity: 30 player ammo before reload: player magazines before reload: 4 player ammo after reload: 30 player magazines after reload: 3 -------------------------------------------------------- Initial Ammo Count: 30
I even dumped the ammo count twice in different locations just to make sure. Yet all I get on the image is the dryfire state. I probably don't have to add that the weapon works perfectly for human players, and that nothing terribly fundamental has been changed from the example "Rifle".
I'm sure the solution is simple, short, and makes look like the idiot I am.
#13
I have absolutely *no* clue what I did. I mean, I even checked out an older version of the script + C code and this one also works all of a sudden. I'm now using basically the same code as Beffy. Even his original stuff works now, and there's no apparent reason why (or rather, why not)
BTW, I have the automated .DSO deletion in the code, so it was not a case of old versions of compiled script code.
Thanks for all the help. Although it didn't directly solve the mystery, it did help me find out that all that was missing was ammo for the weapon, although the inventory count said otherwise.
Anyways, thanks for your patience ;)
03/14/2003 (12:23 pm)
Heh, I got the bots firing.I have absolutely *no* clue what I did. I mean, I even checked out an older version of the script + C code and this one also works all of a sudden. I'm now using basically the same code as Beffy. Even his original stuff works now, and there's no apparent reason why (or rather, why not)
BTW, I have the automated .DSO deletion in the code, so it was not a case of old versions of compiled script code.
Thanks for all the help. Although it didn't directly solve the mystery, it did help me find out that all that was missing was ammo for the weapon, although the inventory count said otherwise.
Anyways, thanks for your patience ;)
#14
03/14/2003 (1:52 pm)
Glad you got that working :) I was wondering what else could be wrong with it.
#15
03/15/2003 (11:39 am)
As a small thank-you, here's a screenshot of a squad of bots firing. Note the different casings. Oh, bots wielding a sniper rifle are super-deadly. A very distant gunshot, a "Zzzzup!", and bang you're dead. Wheee!
Torque Owner Gilles Jr Lafrance
tork.zenkel.com