Jump to content
Sign in to follow this  
soolie

Vehicle Config - Ammo

Recommended Posts

I'm working on a Vehicle Service mod. The mod allows you to rearm the player's vehicle. Problem is, you can over add ammo. I'm looking to limit the number of mags you can get by using some kind of variable in the vehicle cfg. 

 

Found this on the setVehicleAmmo wiki "Sets how much ammunition (compared to a full state defined by the vehicle type) the vehicle has."

 

Does anyone know where I can find this info or some other variable pertaining to how much ammo a vehicle's weapons can have?

Share this post


Link to post
Share on other sites

There's a number of ways of coding it, but you could access the "magazines" config entry in each turret, which gives you the default loadout for the vehicle.  Use  BIS_fnc_getTurrets to get an array of the CONFIG paths and then use something like getArray (_x >> "magazines") for your paths to get the magazines that are defaulted to the turret (and by extension vehicle).

 

So you could do something simple like:

fnc_getDefaultVehicleMags = {
    private _magArray = [];
    {
        _magArray pushBack (getArray(_x >> "magazines"));
    } forEach ([_this] call BIS_fnc_getTurrets);
    _magArray
};

diag_log format ["%1",cursorObject call fnc_getDefaultVehicleMags];

And you get a list of all the mags that come with the vehicle (sorted but not nicely yet) :

[[],[""100Rnd_127x99_mag_Tracer_Red"",""100Rnd_127x99_mag_Tracer_Red"",""100Rnd_127x99_mag_Tracer_Red""],[""130Rnd_338_Mag"",""130Rnd_338_Mag"",""130Rnd_338_Mag""],[],[]]

Or maybe something slightly more complex like:

 

fnc_getDefaultVehicleMagsByWeapon = {
    private _weapArray = [];
    {
        _cfgTurret = _x;
        {
            _weapArray pushBack [_x,count getArray (_cfgTurret >> "magazines")]
        } forEach (getArray (_cfgTurret >> "weapons"));
    } forEach ([_this] call BIS_fnc_getTurrets);
    _weapArray
};


diag_log format ["%1",cursorObject call fnc_getDefaultVehicleMagsByWeapon];

And that gives you an array where each element is the weapon and total default mag count:

[[""SportCarHorn"",0],[""HMG_127_LSV_01"",3],[""MMG_02_vehicle"",3]]

Sorry about the double quotes in the strings; diag_log's doing some screwy shit at the moment on my PC.

 

Paste either of those examples in the debug console when you're looking at a vehicle to get a chat output.  There's no error checking and it could prob be optimised etc etc but it's just an example for you.

 

It depends how you need it to work with your menu system but hope that points you in the right direction.

  • Like 1

Share this post


Link to post
Share on other sites

 

There's a number of ways of coding it, but you could access the "magazines" config entry in each turret, which gives you the default loadout for the vehicle.  Use  BIS_fnc_getTurrets to get an array of the CONFIG paths and then use something like getArray (_x >> "magazines") for your paths to get the magazines that are defaulted to the turret (and by extension vehicle).

 

 

I looked for so long, and I already have the turret paths being used. Am taking the turret path, getting the weapon , then using cfgWeapons to get avail ammo for it. I never noticed in the turrets >> magazines that they were the same class (meaning it gets x amount of them).

 

You're a legend, thank you.

Share this post


Link to post
Share on other sites

If anyone can help, I am working on a rearm script that was made before but has a bug,

 

Basically the script looks like this:

_vehicleType = typeOf(cursorObject);
_driverWeapons = (configFile >> "CfgVehicles" >> _vehicleType >> "weapons") call BIS_fnc_GetCfgData;
_driverMagazines = (configFile >> "CfgVehicles" >> _vehicleType >> "magazines") call BIS_fnc_GetCfgData;

_vehicleLoadout = [];
if (count _driverWeapons > 0 || {count _driverMagazines > 0}) then
{
    _vehicleLoadout pushBack [[-1], _driverWeapons, _driverMagazines];
};

_vehicleTurrets = configFile >> "CfgVehicles" >> _vehicleType >> "Turrets";
for "_i" from 0 to (count _vehicleTurrets - 1) do
{
    _turretPath = _vehicleTurrets select _i;
    _turretWeapons = (_turretPath >> "weapons") call BIS_fnc_GetCfgData;
    _turretMagazines = (_turretPath >> "magazines") call BIS_fnc_GetCfgData;

    if (count _turretWeapons > 0 || {count _turretMagazines > 0}) then
    {
        _vehicleLoadout pushBack [[_i], _turretWeapons, _turretMagazines];
    };
};
_vehicleLoadout;

diag_log str(_vehicleLoadout);

The return for it is if used on a tank:

 

13:47:39 "[[[0],[""cannon_125mm"",""LMG_coax""],[""24Rnd_125mm_APFSDS_T_Green"",""12Rnd_125mm_HE_T_Green"",""12Rnd_125mm_HEAT_T_Green"",""2000Rnd_762x51_Belt_Green"",""2000Rnd_762x51_Belt_Green""]]]"
 

Now the problem here is that it's not seeing the other turrets and weapons of the tank, but only what's in [0]

 

Because if you check the magazines this is what there is:

 

[["24Rnd_125mm_APFSDS_T_Green",[0],20,1.00073e+007,2],["12Rnd_125mm_HE_T_Green",[0],10,1.00073e+007,2],["12Rnd_125mm_HEAT_T_Green",[0],11,1.00073e+007,2],["2000Rnd_762x51_Belt_Green",[0],1987,1.00073e+007,2],["2000Rnd_762x51_Belt_Green",[0],2000,1.00073e+007,2],["450Rnd_127x108_Ball",[0,0],398,1.00073e+007,2],["450Rnd_127x108_Ball",[0,0],450,1.00073e+007,2],["SmokeLauncherMag",[0,0],2,1.00073e+007,2]]

 

Any hints on how I can modify it so it shows also [0,0] ?

 

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  

×