Jump to content
Sign in to follow this  
gc8

ai throwing handgranades

Recommended Posts

hi can you make the AI throw a hand grenade?

I tried code like this: _this fire ["HandGrenadeMuzzle","HandGrenadeMuzzle","HandGrenade_East"];

but the AI doesn't aim at all but just throws the grenade far away.

thanks

Also does anyone know if theres ai mods that does this already?

im just trying to teach the ai to use hand granades ;)

Share this post


Link to post
Share on other sites

UPSMON improves those dumbasses inteligence, it may help. Do you want them to throw at enemies or script them to throw at given place ?

Share this post


Link to post
Share on other sites

at enemy

Share this post


Link to post
Share on other sites

UPSMON.

It's a script pump up the AI's intelligence: flank, use smoke grenade, grenade, mines...

And it add a huge replayability to your missions, because it's very random.

Share this post


Link to post
Share on other sites

Try removing all weapons, then adding grenades to AI.

removeallweapons this; this addmagazine "handgrenade"

That way AI has only the option to use grenades and will happily oblige when enemy is spotted,

Share this post


Link to post
Share on other sites

Made something light and quick but not perfect, the grenades are usually thrown in the right direction but may bounce back off obstacles:

//====================================================================================================================
//   Example mission by
//   Mattar Tharkari
//   Make AI throw grenades
//====================================================================================================================
//  The next event handler adds the grenade throwing action
//    at the correct range 40-60m
//    in the correct direction
//    triggers if the AI is fired on
//    _val is the chance of a throw occuring, 1 in 11 in this case;
//    change (side _x == ****) to EAST or WEST
//    remove the hint - it's only to show detection frequency
//    will only work if AI have grenades - you need to equip them if not.
//====================================================================================================================

{if (side _x == EAST && !(isPlayer _x)) then {
_x addEventHandler ["firedNear", "
 _dir = ((getPosATL (_this select 1) select 0) - (getPosATL (_this select 0) select 0)) atan2 ((getPosATL (_this select 1) select 1) - (getPosATL (_this select 0) select 1));
   _dir = _dir % 360;
     _val = floor(random 11);
_frnd = side (_this select 0);

if (_this select 2 >= 40 && _this select 2 <= 60 && _val == 1 && !(_frnd == side (_this select 1))) then {
 (group (_this select 0)) setFormDir _dir;
   (_this select 0) setDir _dir;
     (_this select 0) fire ['HandGrenadeMuzzle', 'HandGrenadeMuzzle', 'HandGrenade_West'];
       hint format['Shot detected 40m-60m from %1',name (_this select 0)];};
   "];
 };
} forEach allUnits;

Example Mission:

https://dl.dropbox.com/u/37698503/scriptedGnadeThrow.Shapur_BAF.zip

Bullets are disabled in the mission, although there is lots of shooting, it's only the grenades doing the killing

Share this post


Link to post
Share on other sites

Better version of the above that targets nearest enemy (dependant on if they know about the enemy), I suppose you could add to this and change the velocity of the grenade depending on the distance to the enemy. However getting them to throw it as far away as possible is probably a good standard option - grenades are dangerous things in Arma2 lol:

for init.sqf

{if (side _x == EAST && !(isPlayer _x)) then {
_x addEventHandler ["firedNear", "
   _nrstNME = (_this select 0) findNearestEnemy (_this select 0);
    _frnd = side (_this select 0);
     _val = floor(random 11);

if (!(isNull _nrstNME) && _nrstNME distance (_this select 0) >= 40 && _nrstNME distance (_this select 0) <= 60 && _val == 1 && !(_frnd == side (_this select 1))) 
then {
   _dir = ((getPosATL _nrstNME select 0) - (getPosATL (_this select 0) select 0)) atan2 ((getPosATL _nrstNME select 1) - (getPosATL (_this select 0) select 1));
     _dir = _dir % 360;

 (group (_this select 0)) setFormDir _dir;
   (_this select 0) setDir _dir;
     (_this select 0) fire ['HandGrenadeMuzzle', 'HandGrenadeMuzzle', 'HandGrenade_West'];
       hint format['Shot detected 40m-60m from %1',name (_this select 0)];};
   "];
 };
} forEach allUnits;

example mission:

https://dl.dropbox.com/u/37698503/scriptdThrwFNE.Shapur_BAF.zip

Share this post


Link to post
Share on other sites

thanks everyone. I tried UPSMON but the ai didn't throw any grenades in the demo (I wonder at which conditions they do?)

@Mattar_Tharkari your facing same problem as i did with fire command, they always throw it far.. and without aiming.

btw I think arma should have option to roll the grenade too. this would be mostly useful for the player.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×