LordGolias / antistasi

Antistasi improved, a mod for the game Arma 3.
BSD 3-Clause "New" or "Revised" License
31 stars 18 forks source link

RHS Units -No HR or Cost Deduction on Squad Spawning #198

Closed Nibbles01 closed 5 years ago

Nibbles01 commented 5 years ago

I found that there was no HR or cost being deducted from my pool when recruiting whole squads via the commander spawning menu... although I tested with RHS this also seems to be the case in Vanilla.

Nibbles01 commented 5 years ago

The offending code originally looked like this:

private _cost = 0;
private _costHR = 0;
private _hr = AS_P("hr");
private _resourcesFIA = AS_P("resourcesFIA");

if !(_grouptype in AS_FIACustomSquad_types) then {
    ([_grouptype] call AS_fnc_getFIASquadCost) params ["_cost", "_hr"];
    _isInfantry = true;
} else {
    ([_grouptype] call AS_fnc_FIACustomSquad_cost) params ["_cost", "_hr"];
};

There are two problems with this: 1) The function return value (after "params []") seems to be attempting to overwrite the global _hr value of the FIA (from AS_P("hr"), rather than the _costHR value of the squad itself. This I will assume is a typo and is easy to fix.

2) I do not know if this function call and return style is valid. I was not able to find documentation of this type of use, which leads me to suspect it is bad practice if it is indeed functional at all... I was able to correct the issue by defining an intermediary array in this local function context and using a function return style that is more comfortable to me and more well documented generally.

I do not claim this is the best way, but the problem is resolved by the following changes.

private _isInfantry = false;
private _cost = 0;
private _costHR = 0;
private _hr = AS_P("hr");
private _resourcesFIA = AS_P("resourcesFIA");

if !(_grouptype in AS_FIACustomSquad_types) then {
    _resultarray = ([_grouptype] call AS_fnc_getFIASquadCost);
    _cost = _resultarray select 0;
    _costHR = _resultarray select 1;
    _isInfantry = true;
} else {
    _resultarray = ([_grouptype] call AS_fnc_FIACustomSquad_cost);
    _cost = _resultarray select 0;
    _costHR = _resultarray select 1;
};
Nibbles01 commented 5 years ago

Closed... already fixed by @LordGolias in commit 1646b7ed104b622fc77a2df991afe9b7b4427bcb of Dev branch. Nevermind! It turns out that syntax is valid after all.