PDA

View Full Version : Keeping bots from using a weapon


Postal
6th Oct 2001, 09:35 AM
In a project I am currently working on, we have this knife, but the bots want to use that over any other weapon.

I tried setting the weapon priorty to 1 and adding a rateself so it should only be used if the bot is in bad health and the enemy is very close, but still the bots choose the knife(and stab you as they try to snipe with it)

How could it be set so the bots only use the knife if they have no ammo for any of their better weaps?

Captain Kewl
6th Oct 2001, 09:33 PM
Play around AIRating and the RateSelf function. RateSelf returns AIRating unless you want to return different values under different conditions. The lower the AIRating is, the lower priority the weapon is for the bot.

Magus {DarkMagic}
7th Oct 2001, 12:02 AM
One thing that you may want to do so that the bots dont try to snipe with the knife is to set bMelee=True in the default properties under WeaponAI. That should help keep them from trying to snipe with it, and instead run at you to use it instead.

Postal
7th Oct 2001, 07:28 AM
I have the prioryt set to 1, bmelee is true, and I have the ratself set so the bots should only use it if their health is less then 50 or the enemy distance is less then 250 units

bMeleeWeapon=True

function float RateSelf( out int bUseAltMode )
{
local float EnemyDist, Rating;
local bool bRetreating;
local vector EnemyDir;
local Pawn P;

// by default use regular mode (rockets)
bUseAltMode = 0;
P = Pawn(Owner);
if ( P.Enemy == None ) return AIRating;

EnemyDir = P.Enemy.Location - Owner.Location;
EnemyDist = VSize(EnemyDir);
Rating = AIRating;

// don't pick vest launcher is enemy is too far
if ( EnemyDist > 250 )
{
if ( P.Weapon == self )
{
// only use knifevest if in good tactical situation
if ( (EnemyDist < 250) || (P.Health < 50) ) return Rating;
}
return 0.05 + EnemyDist * 0.001;
}

//Knife is bad if hieght dieference
if ( Owner.Location.Z > P.Enemy.Location.Z + 50)
Rating -= 0.35;
else if ( P.Enemy.Location.Z > Owner.Location.Z + 50)
Rating -= 0.35;

// decide if should use diferent weapon
if ( (EnemyDist > 250) ) Pawn(Owner).SwitchToBestWeapon();
return Rating;
}

Magus {DarkMagic}
7th Oct 2001, 10:05 AM
one thing about your code that does not make sense is this section:
// don't pick vest launcher is enemy is too far
if ( EnemyDist > 250 )
{
if ( P.Weapon == self )
{
// only use knifevest if in good tactical situation
if ( (EnemyDist < 250) || (P.Health < 50) )
return Rating;
}
return 0.05 + EnemyDist * 0.001;
}

You are basicly asking if the distance is greater then 250, and then you ask if there distance is less then 250, which would never be true. Since the distance is already greater then 250.



Well basicly going off what you had, this is what i came up with. I have no idea if it would work or not.

function float RateSelf( out int bUseAltMode )
{
local float EnemyDist,rating,ZAxis;
local vector EnemyDir;

bUseAltMode = 0;

//if no enemy you dont need
if ( (Pawn(Owner) == None) || (Pawn(Owner).Enemy == None) )
return 0;

EnemyDist = VSize(Pawn(Owner).Enemy.Location - Owner.Location);
if ( EnemyDist > 250)
return -2; //dont want weapon if enemy to far away

//goes through rating weapon based off of curtain things
rating = 0.0;
if(Pawn(Owner).Health < 50 )
rating += 0.5;

ZAxis=Pawn(Owner).Location.Z > Pawn(Owner).Enemy.Location.Z;
if( ZAxis >= 50 || ZAxis <= -50)
rating -= 0.70;

return (AIrating + rating);
}