Jump to content
Sign in to follow this  
Ionflux

Give AI unlimited ammo?

Recommended Posts

Hi everyone,

Is it possible to give some of the AI in my squad unlimited ammo?

Thanks in advance,

Ion :pray:

Edited by Ionflux

Share this post


Link to post
Share on other sites

trini scourge had a post some where on this here is the info

what u can do is use a addeventhandler with setvehicleammo.

this addeventhandler ["fired", {(_this select 0) setvehicleammo 1}]

Share this post


Link to post
Share on other sites

Awesome thanks bud! Will this work for infantry units aswell? :)

*EDIT* - works on infantry

No worries dude got it working :) thanks allot!

Edited by Ionflux

Share this post


Link to post
Share on other sites

Is there a way to do this in a way that does unlimited reloads instead of rounds in the chamber? I want A.I. MANPADs to have unlimited reloads, not exactly a stream of missiles.

Thanks for any assistance.

Share this post


Link to post
Share on other sites
Is there a way to do this in a way that does unlimited reloads instead of rounds in the chamber? I want A.I. MANPADs to have unlimited reloads, not exactly a stream of missiles.

Thanks for any assistance.

this addeventhandler ["Fired",{if (_this select 1=="Strela") then {_this select 0 addMagazine (_this select 5)}}]

Edited by Celery
  • Thanks 1

Share this post


Link to post
Share on other sites

Amazing! Thank you, will try it now.

[Edit] - It's good to go, much appreciated.

Edited by Varkrag

Share this post


Link to post
Share on other sites

Does anybody know a function that returns how much ammo the unit has? I could use it when ammo < 0.5. This way the unit would always reload when needed.

Share this post


Link to post
Share on other sites
Does anybody know a function that returns how much ammo the unit has? I could use it when ammo < 0.5. This way the unit would always reload when needed.

Create a radio trigger set to repeat.

On act.

nul = [player, "m16a4"] execVM "checkammo.sqf"

checkammo.sqf

_unit = _this select 0;
_weapon = _this select 1;

_count = _unit ammo _weapon;

hintsilent format ["You have %1 rounds of ammo in your magazine.", _count];

I used a basic USMC rifleman with the m16a4 rifle. Another command you might want to look at is someammo.

Share this post


Link to post
Share on other sites
Is there a way to do this in a way that does unlimited reloads instead of rounds in the chamber? I want A.I. MANPADs to have unlimited reloads, not exactly a stream of missiles.

_ammo = createTrigger["EmptyDetector",getPos player];
_ammo setTriggerStatements["needReload player == 1", "reload player; player setVehicleAmmo 1", ""];

Share this post


Link to post
Share on other sites
this addeventhandler ["Fired",{if (_this select 1=="Strela") then {_this select 0 addMagazine (_this select 5)}}]

Edit: Nevermind, the reload time of the unit was the problem.

Edited by maturin

Share this post


Link to post
Share on other sites
this addeventhandler ["Fired",{if (_this select 1=="Strela") then {_this select 0 addMagazine (_this select 5)}}]

The above code by Celery gives a Strela unlimited reloads. Would anyone know what i need to do to the above code so it gives unlimited reloads to a static AA or static MG weapon ?

Share this post


Link to post
Share on other sites

Unlimited for everything is as follows without even having to reload,put in units ini

this addEventHandler ["Fired",{[_this select 0,getNumber (configFile/"CfgAmmo"/(_this select 4)/"explosive")] spawn {if (_this select 1==1) then {sleep 0.75};_this select 0 setVehicleAmmo 1}}]

Share this post


Link to post
Share on other sites
Unlimited for everything is as follows without even having to reload,put in units ini

this addEventHandler ["Fired",{[_this select 0,getNumber (configFile/"CfgAmmo"/(_this select 4)/"explosive")] spawn {if (_this select 1==1) then {sleep 0.75};_this select 0 setVehicleAmmo 1}}]

Thanks for your reply Jim I will give that a try mate, but i did still want the reload effect to happen as normal and not just a constant flow of bullets or AA rockets, so this may not be what I'm looking for yet. I'll let you know if its not. Thanks again mate.

Share this post


Link to post
Share on other sites

I ended up putting this script together and thought i would post it for anyone else to use. This reload script will give a player or AI unit unlimited magazine reloads for a static weapon. I'm not an advanced scriptwriter so there is probably an easier way of doing this but this is just what i came up with. I did it this way because i wanted static MG's to still have the reload animation instead of a constant flow of bullets. Some of the script code is for the debug hints which i needed for learning.

staticreload.sqf

// script by PartyHead.
// Unlimited magazine reloads for AI and player units as gunner of a static weapon.
// place the following code in the init field of a static weapon and you or AI units
// will get unlimited magazine reloads.
// _nil = [this] execVM "staticreload.sqf";

//hintSilent "DEBUG\n\nAuto reloading script started.";

_static = _this select 0;

while {true} do
{
   sleep 2;
   //hintSilent "DEBUG\n\nStatic weapons are waiting.";
   if (_static isKindOf "StaticWeapon") then
   {
       waitUntil {((_static emptypositions "gunner") == 0) && (alive _static)};
       _type = typeOf _static;
       _gunner = gunner _static;
       _weapons = weapons _static;
       _weapon = currentWeapon _static;
       _magazines = magazines _static;
       _magazine = currentMagazine _static;
       _magCount = {_x == _magazine} count magazines _static;
       _ammo = ((_static) ammo (_weapon));
       _reload = _magCount - 1;
       _static setVehicleAmmo 1;
       for [{_loop = 0},{_loop >= 0},{_loop = _loop}] do
       {
           _weapon = currentWeapon _static;
           _magazine = currentMagazine _static;
           _magCount = {_x == _magazine} count magazines _static;
           _ammo = ((_static) ammo (_weapon));
           //hintSilent format ["DEBUG\n\nAuto reloading activated.\n\nVehicle: %1.\nGunner: %2.\nWeapons: %3.\nCurrent weapon: %4.\nMagazines: %5.\nRounds: %6.", _type, name _gunner, _weapons, _weapon, _magCount, _ammo];
           if (_magCount <= _reload) then {_static setVehicleAmmo 1};
           sleep 0.01;
           if (!(alive _static) || ((_weapons select 0) != (weapons (vehicle _gunner) select 0)) || ((_static emptypositions "gunner") == 1)) then 
           {
               _loop = -1;
               //hintSilent "DEBUG\n\nAuto reloading deactivated.";
           };
       };
   };
};

Share this post


Link to post
Share on other sites
_ammo = createTrigger["EmptyDetector",getPos player];
_ammo setTriggerStatements["needReload player == 1", "reload player; player setVehicleAmmo 1", ""];

Scifer, it doesnt work in AI.. :( It only works in player how to make it work for AI? TY (sorry for poor english)

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  

×