Classic Battlefield Modding Wikia
Advertisement

BF2 AI issues (WIP - needs formatting updates)

Will be adding to this as we sift through our notes. Some of these will be single player issues and others general issues.

AT Mine [issue solved]

After increasing the the AT Mine projectile velocity, giving the genericfirearm an aitemplate, and then play-tweaking the aitemplate for several weeks, I had the bots using mines and getting kills. Then one of the patches (1.02 or 1.03) came along, and we started getting CTD's w/ this error msg when bots would lay a mine:

Bf2error.PNG

Add this to the AT Mine genericfirearm:

rem ---BeginComp:ThrownFireComp ---

ObjectTemplate.createComponent ThrownFireComp

ObjectTemplate.fire.altFireInput PIAltFire

Problem solved, CTD's disappeared. Apparently the bots were trying (or thinking about) to use the right click fire, but with no input mapping in the generic firearm, an error would occur. It's likely the same issue would occur w/ the claymore and be fixed the same way.

Giving soldier aitemplate antiaircraft armament [issue solved]

If you want soldiers in BF2 to fire their handweapons at aircraft, you have to give the soldier.aitemplate.armament antiaircraft ability. For example, an AT Soldier:

rem *** at armament ***

aiTemplatePlugIn.create Armament atSoldierArmament

aiTemplatePlugIn.setIsAntiAircraft 1

Then tweaking the individual weapontemplates, you'll have bots shooting at aircraft with various handweapons. But then on occasion you'll get a CTD with LookAtWrapper errors.

With windowed mode, the debugger logs, and Outsider's help, we tracked it down to certain aibehaviors that DICE did not include (not their fault, since their soldiers don't have antiaircraft armament). These need to be added:

rem *** LandingCraftFixed Behaviour setup ***

aiSettings.activateDefaultInterpreter LandingCraftFixed BAPSTLookAtWrapper Full

rem *** ParatrooperFixed Behaviour setup ***

aiSettings.activateDefaultInterpreter ParatrooperFixed BAPSTLookAtWrapper Full

Hold Object [issue not solved]

The use of the GamePlayObjects.ObjectSpawner property objectTemplate.holdObject 1 causes this error when bots try to move the vehicle:

Debug assert.PNG

No solution as of yet.  Just avoid using the holdobject line in SP/COOP modes.

No heatseeking track or lock hud (on target), and no heatseeking track or lock warning sound (for self) [issue solved]

Heatseeking missles must be a secondary (right click) genericfirearm. If assigned as primary firearm, all the said issues will occur.

Bots firing heatseeking missles from a helicopter [issue solved]

See above. The heatseeking weapon must be a secondary (right-click), otherwise bots never get a lock, and won't fire. 

Objects.ai ---> armament must include aiTemplatePlugIn.setIsAntiAircraft 1

Weapons.ai ---> WeaponTemplate.WeaponFire PIAltFire

in \ai\Objects.ai, it was also necessary to change the ai strategic strength settings to: 

aiTemplatePlugIn.setStrategicStrength 0 0

aiTemplatePlugIn.setStrategicStrength 1 2 

Otherwise, the bots would only fire once if it was a cannon, or not at all if it was a missile - they would get a lock, and continue to strafe around you, ad nauseum.

Bots cannot throw/shoot sticky projectiles [issue not solved]

However, they can use them. Assuming the weapon has an aitemplate so the bots can use it, you can make the projectile sticky by replacing the collision comp with stickycollisioncomp:

ObjectTemplate.createComponent StickyCollisionComp

ObjectTemplate.collision.bouncing 1

ObjectTemplate.collision.maxStickAngle 180 

If you can make the incendiary grenade sticky, to be similar to a molotov cocktail, and stick to vehicles as it burns, but the bots rarely use it.   The bots will do the same "run to vehicle, plant it, run away from vehicle" behavior as they do with C4.  Apparently, the StickyCollisionComp triggers that behavior in the AI. The implication is that you cannot have a bot using a sticky weapon from a distance. No solution as of yet.

Better ai spawning off the squadleader

Inside Objects_server.zip /soldiers/Common/common.con

rem the line

ObjectTemplate.setScatterSpawnPositions 1

Why BF2 bots need increased projectile velocity for deployable objects, like mines:

Bots pre-calculate every projectile path before firing. They will not fire a weapon unless the projectile can reach its target.  This is why defensive weapons are difficult for bots to implement correctly. Same issue with trying to get bots to deploy the mortar in Aintent.

DICE solved this problem in BF2142, hence the ability for bots to deploy sentinel guns. Unfortunately, code never made it back into BF2.

weaponTemplate.setSoundSphereRadius - Bots don't hear explosions in the same way as they hear rounds being fired. The hearing system is very basic.

weaponTemplate.allowedDeviation – Probably a way to allow the bots to fire certain weapons (like sniper rifles) with higher accuracy.

Bots weapon issues

  They certainly can do it but they

don't like firing laser-guided's from helicopter pilot positions, but heatseekers are ok. in order to get mine working i had to do a lot of fiddling, and what worked for one did not necessarily work on other vehicles so you might need to mix and match to find the right combination.

by 'itemindex 2' do you mean they are still on the primary fire but selectable there, or is #2 on AltFire?

in the weapon's ai weapon template you might like to try:

WeaponTemplate.WeaponActivate PIWeaponSelect2

and perhaps: WeaponTemplate.WeaponFire PIFire

or if it's on AltFire instead: WeaponTemplate.WeaponFire PIAltFire

...or any combination of those, where applicable.

if one weapon is PIFire and the other is PIAltFire, try giving them both ItemIndex 1 (which is how the plane guns/sidewinders are set up, and can make a difference to the bots) - obviously if both weapons are on PIFire this will cause a CTD so don't do that.

ah, ok. that means there's something about the #2 weapon itself they don't like, if you've tried inputting those previous lines i showed you into their weapons.ai entries. in the past i've had trouble with accelerating weapons (i.e. ones that start slowly and then speed up) - to test if this is the case try increasing its velocity, but this usually only only affects projectiles that launch at speeds of around 60 or lower (obviously not bombs, which are the Indirect 1 type)

other things that may help: try remming out the ObjectTemplate.fire.fireInput PIFire statement if you have it; it is not usually needed and sometimes stops the bots firing

also try remming out the ObjectTemplate.weaponHud.hudName "xxxx" line - it sounds stupid i know, but i have had cases where it made bots start using the weapon all of a sudden when it was removed

finally, in Objects.ai, try changing the strategic strengths from 0 3 - 1 3 to 0 2 - 1 2 or even 0 0 - 1 2

if that doesn't help, i'd need to be able to see the model for myself before i could make any other guesses

Is it better to have the pilot or copilot use the laser guided weapons?


copilot for sure; by default the pilot of a heli can not shoot laser guided missiles. there is a way around that, but involves a bit of fiddling and it's a far from perfect system.  

The bots won't even fire dumbfire rockets from item index 2, even when the item index 1 weapon strengths are on zero.


ah, ok. that means there's something about the #2 weapon itself they don't like, if you've tried inputting those previous lines i showed you into their weapons.ai entries. in the past i've had trouble with accelerating weapons (i.e. ones that start slowly and then speed up) - to test if this is the case try increasing its velocity, but this usually only only affects projectiles that launch at speeds of around 60 or lower (obviously not bombs, which are the Indirect 1 type)

other things that may help: try remming out the ObjectTemplate.fire.fireInput PIFire statement if you have it; it is not usually needed and sometimes stops the bots firing

also try remming out the ObjectTemplate.weaponHud.hudName "xxxx" line - it sounds stupid i know, but i have had cases where it made bots start using the weapon all of a sudden when it was removed

finally, in Objects.ai, try changing the strategic strengths from 0 3 - 1 3 to 0 2 - 1 2 or even 0 0 - 1 2

if that doesn't help, i'd need to be able to see the model for myself before i could make any other guesses  

give the weapon a stupidly high allowedDeviation and shorter reload time just while you're troubleshooting. once you get them actually firing the weapon easily and regularly you can put it back to more realistic values.

another thing i find very helpful with aircraft weapons ai testing is to give the weapon itself a non-3d 3p fire sound, so if they do launch it you can hear it no matter where you are on the map. obviously once testing is finished you set it back to normal again

've found that the weapons.ai values can also make quite a difference, most notably the combination of maxRange, allowedDeviation and fireRate. The following seems to work nicely for Pilot-fired weapons with the DCon AH-64:

Example: Hydra rockets - itemIndex 1 - PIFire

CODE

rem *** Hydras *** weaponTemplate.create ah64_Rockets WeaponTemplate.WeaponFire PIFire weaponTemplate.indirect 0 weaponTemplate.minRange 5.0 weaponTemplate.maxRange 600.0 weaponTemplate.setStrength Infantry    14.0 weaponTemplate.setStrength LightArmour 10.0 weaponTemplate.setStrength HeavyArmour 8.0 weaponTemplate.setStrength NavalArmour 0.0 weaponTemplate.setStrength Helicopter  1.0 weaponTemplate.setStrength Airplane    0.0 weaponTemplate.fireRate 120 weaponTemplate.allowedDeviation 4.0


Example: Hellfires (DCon WireGuided version - not TV or Laser) - itemIndex 2 - PIAltFire

CODE


rem *** Hellfires *** weaponTemplate.create ah64_Hellfires WeaponTemplate.WeaponFire PIAltFire weaponTemplate.indirect 0 weaponTemplate.minRange 5.0 weaponTemplate.maxRange 600.0 weaponTemplate.setStrength Infantry    0.0 weaponTemplate.setStrength LightArmour 18.0 weaponTemplate.setStrength HeavyArmour 16.0 weaponTemplate.setStrength NavalArmour 0.0 weaponTemplate.setStrength Helicopter  0.0 weaponTemplate.setStrength Airplane    0.0 weaponTemplate.fireRate 100 weaponTemplate.allowedDeviation 4.0


Note that fireRate should match the fire rate of the weapon. You might try increasing allowedDeviation in small increments (0.5 - 1.0) to see if it encourages bots to fire (i.e. acceptable targeting/firing conditions occur more often when allowedDevitation has a higher value).

  The problem isn't Item index 2 on pi alt fire, the problem is item index 2 on pi fire.  

same deal. make the weapon ai really super easy for them, to give the bots every opportunity to use the weapon. then once you've narrowed down the fault and fixed it, you can tighten up their accuracy again

i've even had bots use specialToggleWeaponInput on AltFire before (fire on primary, and hit alt fire to switch between weapons) without any dramas too. as long as they can select and fire the weapon, they will use it whenever the chance arises  

I got my co-pilot bot to use the laser guided ATGM's by setting it up like this...



CODE

rem * ATGM * weaponTemplate.create Apache_Hellfire_ai weaponTemplate.indirect 0 weaponTemplate.minRange 5.0 weaponTemplate.maxRange 375.0 weaponTemplate.WeaponFire PIFire WeaponTemplate.WeaponActivate PIWeaponSelect2 weaponTemplate.setStrength Infantry    0.0 weaponTemplate.setStrength LightArmour 5.0 weaponTemplate.setStrength HeavyArmour 25.0 weaponTemplate.setStrength NavalArmour 0.0 weaponTemplate.setStrength Helicopter  0.0 weaponTemplate.setStrength Airplane    0.0 weaponTemplate.allowedDeviation 5.0


Like you, I want them to fire all weapons with the PIFire. He also uses the gun just fine and I didn't add the WeaponFire or WeaponActivate.

The other thing that might effect this is what clivewil mentioned and that's the ObjectTemplate.specialToggleWeaponInput PIAltFire code. I added that because it was the only way for me to switch weapons (other then with the keyboard). No idea if it effects what they want.

I also donot have ObjectTemplate.fire.fireInput PIAltFire added under the weapons rem ---BeginComp:MultiFireComp --- lines.

as i mentioned before, this varies from vehicle to vehicle. i have some that work fine without it, and others that are virtually identical that won't work unless that line is present. at the end of the day you need to swap in/out various combinations until you find one they are comfortable with

with a poorly configured weapon ai setup, sometimes they are able to fire but rarely; this is most obvious with rapid or continuous fire weapons like machine guns etc. - if you find they send off one shell and then stop, the bot is virtually saying 'hey i want to use this weapon against that target, but i don't quite understand it'

if of course they don't even fire one round, then perhaps selection or weighting is the problem, instead of fire control

This is my weapons.ai template. Even with this template, the littlebird still uses the gun and never uses the rockets. The grenade launcher template is for the co-pilot.



CODE

rem * Rockets* weaponTemplate.create AH6_Rockets WeaponTemplate.WeaponActivate PIWeaponSelect2 WeaponTemplate.WeaponFire PIFire weaponTemplate.indirect 0 weaponTemplate.minRange 5.0 weaponTemplate.maxRange 500.0 weaponTemplate.setStrength Infantry    7.0 weaponTemplate.setStrength LightArmour 6.0 weaponTemplate.setStrength HeavyArmour 9.0 weaponTemplate.setStrength NavalArmour 0.0 weaponTemplate.setStrength Helicopter  8.0 weaponTemplate.setStrength Airplane    0.0 weaponTemplate.allowedDeviation 50 weaponTemplate.fireRate 300

rem * Cannon * weaponTemplate.create AH6_machinegun weaponTemplate.indirect 0 weaponTemplate.minRange 5.0 weaponTemplate.maxRange 500.0 weaponTemplate.setStrength Infantry    0.0 weaponTemplate.setStrength LightArmour 0.0 weaponTemplate.setStrength HeavyArmour 0.0 weaponTemplate.setStrength NavalArmour 0.0 weaponTemplate.setStrength Helicopter  0.0 weaponTemplate.setStrength Airplane    0.0 weaponTemplate.allowedDeviation 15 weaponTemplate.fireRate 900

rem * Rockets* weaponTemplate.create AH6_Grenade_Launcher WeaponTemplate.WeaponActivate PIAltFire WeaponTemplate.WeaponFire PIFire weaponTemplate.indirect 0 weaponTemplate.minRange 5.0 weaponTemplate.maxRange 160.0 weaponTemplate.setStrength Infantry    8.0 weaponTemplate.setStrength LightArmour 6.0 weaponTemplate.setStrength HeavyArmour 3.0 weaponTemplate.setStrength NavalArmour 0.0 weaponTemplate.setStrength Helicopter  0.0 weaponTemplate.setStrength Airplane    0.0 weaponTemplate.allowedDeviation 15.0


2 pilot weapons should be easy for bots to use, i suggest looking a vanilla jet setup.


The jet ai type uses the fire3d ai setup while the helicopter ai type uses helifire3d. The Helifire3d allows the bot to fly the helicopter like a helicopter, how ever, it seems to be incomplete, hence all the problems associated around helicopters.

i've never had any problems with weapons for heli pilots, laser guided are the only tricky ones to setup.

The only problems i have are associated with intem index2 on PIFire. No other fire type has this problem except for helicopters. Turns out the dice ai devs were too lazy to spend the extra week coding to finish the helicopter ai.

Advertisement