Welcome to the Iron Front Fan Forums!
Sign up Latest Topics
 
 
 


Reply
  Author   Comment  
Santa Six

Avatar / Picture

Colonel
Registered:
Posts: 360
Reply with quote  #1 
Can someone cough up a script that-?

  1. checks if unit is AI
  2. checks if unit is out of ammo
  3. rearms AI unit to default gear
  4. loop
Unless it already exist. Can I get a link?
0
Rydygier

Avatar / Picture

IFR Team
Registered:
Posts: 179
Reply with quote  #2 
In general logic could look like this:

while {(true)} do//works constantly
{
sleep 5;//how long wait before re-check avoid too low values due to CPU load

{
if not (isPlayer _x) then//if AI
{
if not (someAmmo _x) then//if has no more ammo of any kind
{
_unit = _x;
_mags = getArray (configFile >> "CfgVehicles" >> (typeOf _x) >> "magazines");//obtaining default unit's ammo loadout

{
_unit addMagazine _x
}
foreach _mags
}
}
}
foreach AllUnits//for all units on foot
};


Perhaps will work as is, not tested though. Note, that units most probably must be out of any kind of ammo to rearm. If "mags" like flares or smoke grenades shouldn't be counted, things get more complicated... And sorry about lacking tabs. Code wrapping sucks here.
0
Rydygier

Avatar / Picture

IFR Team
Registered:
Posts: 179
Reply with quote  #3 
Unless you simply want, so AI will always have an ammo (always can shoot). Then you can replenish to default rounds count current magazine by using _unit setVehicleAmmo 1 after each shot. This can be done via "Fired" event handler eg like this:

while {(true)} do
{
sleep 5;//how long wait before re-check

{
if not (isPlayer _x) then//if AI
{
if (isNil {_x getVariable "FEH_added"}) then//if EH not added yet
{
_eh = _x addEventHandler ["Fired",{(_this select 0) setVehicleAmmo 1}];//adding event handler
_x setVariable ["FEH_added",_eh];//marking the unit so EH will be added only once per unit
}
}
}
foreach AllUnits//for all units on foot try for (AllUnits + Vehicles) if you want this also for vehicles
};


Note however, that event handler stays on dead bodies until body is present on map. Could be used some body cleaning script or scripted removing EH from dead body to avoid unnecessary CPU load.
0
Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Easily create a Forum Website with Website Toolbox.