Jump to content
froggyluv

subSkill Array Problem

Recommended Posts

 So what im trying to do now is apply sub skill bonuses to the AI of the players squad via various parameters but my code isnt working:

 

 

 

hint "Raising Power!";  //sk or Squad Kills is a global variable im using which reflects good effort by the players units.


_i = [0.3,0.4,0.5,0.6,0.8,0.9]; These are the aimingaccuracy values I'd like to assign based off of sk(Squad KIlls)


_novice = _i select 0;

_bAverage = _i select 1;

_average = _ i select 2;

_aAverage = _i select 3;

_vgood = _i select 4;

_elite = _i select 5;

_myArray = "_novice","bAverage", "_average", "_aAverage", "_vGood", "elite";

if (sk < 40) then { _myArray this select 0};

if (sk >= 40 && < 80) then {_myArray this select 1};

if (sk >=80 && < 120) then {_myArray this select 2};

if (sk >= 120 && > 160) then {_myArray this select 3};

if (sk >= 160 && < 200) then {_myArray this select 4};

if (sk >= 200) then {_myArray this select 5};


{_x setSkill ["aimingaccuracy", _x];}
             forEach units group player;

\\ I get lost here as to what variable will cover this and Ive tried quite a few but left _x as a placeholder

                                        

 




 
 

Share this post


Link to post
Share on other sites


hint "Raising Power!"; //sk or Squad Kills is a global variable im using which reflects good effort by the players units.

_i = [0.3,0.4,0.5,0.6,0.8,0.9]; //These are the aimingaccuracy values I'd like to assign based off of sk(Squad KIlls)

call {

if (sk < 40) exitwith {{_x setSkill ["aimingaccuracy", _i this select 0];} forEach units group player;};

if (sk >= 40 && < 80) exitwith {{_x setSkill ["aimingaccuracy", _i this select 1];} forEach units group player;};

if (sk >=80 && < 120) exitwith {{_x setSkill ["aimingaccuracy", _i this select 2];} forEach units group player;};

if (sk >= 120 && > 160) exitwith {{_x setSkill ["aimingaccuracy", _i this select 3];} forEach units group player;};

if (sk >= 160 && < 200) exitwith {{_x setSkill ["aimingaccuracy", _i this select 4];} forEach units group player;};

{_x setSkill ["aimingaccuracy", _i this select 5];} forEach units group player;

};

//I get lost here as to what variable will cover this and Ive tried quite a few but left _x as a placeholder

Share this post


Link to post
Share on other sites

 I started with something similar to that dimon except I didnt know to use call or 'exitWith' rather than 'Then' -but im still getting a 'Generic error in expression
 

 

C:\Users\Greg\Documents\Arma 3\missions\Locations.Altis\raise.sqf, line 5
 6:39:05 Error in expression <ith {{_x setSkill ["aimingaccuracy", _i this select 0];} forEach units group pla>
 6:39:05   Error position: <this select 0];} forEach units group pla>
 6:39:05   Error Missing ]
 6:39:05 File C:\Users\Greg\Documents\Arma 3\missions\Locations.Altis\raise.sqf, line 6
 6:39:05 Error in expression <ith {{_x setSkill ["aimingaccuracy", _i this select 0];} forEach units group pla>
 6:39:05   Error position: <this select 0];} forEach units group pla>

 

  • Like 1

Share this post


Link to post
Share on other sites

_i this select x doesn't make sense, I guess it's supposed to be _i select 0
 
I don't think sk >=80 && < 120 will work either; sk is greater than 80, and which variable is less than 120?
 
I'd do it like this:

_skill = switch true do {
    case (sk < 40):   { 0.3 };
    case (sk < 80):   { 0.4 };
    case (sk < 120):  { 0.5 };
    case (sk < 160):  { 0.6 };
    case (sk < 200):  { 0.8 };
    case (sk >= 200): { 0.9 };
};
{    _x setSkill ["aimingaccuracy", _skill]
    } forEach units group player;
  • Like 2

Share this post


Link to post
Share on other sites

 Ahh so thats how Switch/Do -stopping the code if that case is met -brilliant!

 

 Thanks again Greenfist :)

Share this post


Link to post
Share on other sites

 I started with something similar to that dimon except I didnt know to use call or 'exitWith' rather than 'Then' -but im still getting a 'Generic error in expression

 

hint "Raising Power!"; //sk or Squad Kills is a global variable im using which reflects good effort by the players units.


_i = [0.3,0.4,0.5,0.6,0.8,0.9]; //These are the aimingaccuracy values I'd like to assign based off of sk(Squad KIlls)
call {
    if (sk < 40) exitwith {{_x setSkill ["aimingaccuracy", _i select 0];} forEach units group player;};

    if (sk >= 40 && < 80) exitwith {{_x setSkill ["aimingaccuracy", _i select 1];} forEach units group player;};

    if (sk >=80 && < 120) exitwith {{_x setSkill ["aimingaccuracy", _i select 2];} forEach units group player;};

    if (sk >= 120 && > 160) exitwith {{_x setSkill ["aimingaccuracy", _i select 3];} forEach units group player;};

    if (sk >= 160 && < 200) exitwith {{_x setSkill ["aimingaccuracy", _i select 4];} forEach units group player;};

    {_x setSkill ["aimingaccuracy", _i select 5];} forEach units group player;
};
//I get lost here as to what variable will cover this and Ive tried quite a few but left _x as a placeholder

Share this post


Link to post
Share on other sites
{
_x addEventHandler ["Killed", {call fnc_death}];
} forEach allUnits;

fnc_death = {


_group =  units group player;
_target = _this select 0;
_killer = _this select 1;
_distance = _killer distance _target;
_SF = _killer skillFinal "aimingAccuracy"; //// Need _killer's initial subskill number
if ((_killer in _group) && ( side group _target isEqualTo East)) then {


hint format["%1 Well Done %1!! +20 Command", name _killer]

    ;

Sk = Sk + 20;
rep = rep + 50;
tSk = tSk + 20;
trep = trep + 50
};

if ((_killer in _group) &&  (_distance > 250)) then {
 hintc format ["Great shot %1", name _killer];
 
_killer setSkill ["aimingAccuracy",_sf +.1];//// Add small bonus to _killer's accuracy
};
   

_sf is to gather the units current "aimingAccuracy" and then add .1 per kill. As is, its subtracting from an inital .34 to .22 on 1st hit and so on. Am I not properly gathering the current subSkill? Strangely if I add '+1' it does ramp up their accuracy but the fractions create a minus..

 

EDIT: Nevermind seem to have gotten it sorted. Whatever you add is relative to its starting value and it can get wonky at times :p

Share this post


Link to post
Share on other sites

Script to lower all subSkills working great until I tried to exempt certain classes such as Snipers, Marksmen etc

 

 

sleep 1;
if (!isServer) exitWith {};

_exempt =["B_sniper_F", "B_ghillie_ard_F","B_sniper_F","B_ghillie_lsh_F","B_ghillie_sard_F","B_soldier_M_F","B_recon_M_F","B_G_Soldier_M_F","B_Recon_Sharpshooter_F","B_Sharpshooter_F","B_CTRG_Sharphooter_F", "B_G_Sharpshooter_F","B_recon_LAT_F","B_recon_exp_F", "B_recon_medic_F","B_recon_TL_F","B_recon_JTAC_F","B_spotter_F","B_Story_SF_Captain_F", "B_Story_Protagonist_F"];




 
        {              

               if (_x in _exempt) exitwith {};               //////Newly badly working code in red
               if (side _x isEqualTo WEST)   then
            {    _SfaA =_x skillFinal "aimingAccuracy";
                                _sFx = _sFaA * .1;
                _SfsD = _x skillFinal "spotDistance";
                                _sFxb = _SfSd * .7;
                _SfsT = _x skillfinal "spotTime";
                                _sFxc = _SfsT * .8;
                _Sfcou = _x skillFinal "courage";
                              _sFxd = _Sfcou * .8;
                _Sfcom = _x skillFinal "commanding";
                              _sFxe = _Sfcom * .9;
                _SfGen = _x skillFinal "general";
                              _sFxf = _SfGen * .8;
                              
                                
                _x setspeedmode "FULL";
                
                _x setskill ["spotDistance",_sFxb];
                _x setskill ["spotTime",_sFxc];
                _x setskill ["courage",_sFxd];
                _x setskill ["commanding",_sFxe];
                _x setskill ["general",_sFxf];
                _x setskill ["aimingAccuracy",_sFx];

            };
        } forEach allUnits;

 

 

 

 

 Its not recognizing those units and still applying the modifier to them. Tried defining _exempt variable inside bracket as well but no success.

Share this post


Link to post
Share on other sites

if (!(typeOf _x in _exempt) && (side _x isEqualTo WEST)) then { ...

 

exitWith will end the whole foreach thing, not just that one unit.

Share this post


Link to post
Share on other sites

 Haha, oh jeez..

 

 Thanks again for the syntaxical rescue Greenfist

 

 :P

Share this post


Link to post
Share on other sites

 The adventure continues.

 

 Need a way to get a numerical average of a groups total subSkill such as AimingAccuracy

 

 Yes i know this codes gobblegook but hopefully you can see direction im trying to go - need an array built with each group unit's aimingAccuracy push in, added to a total and then averaged out

 

 // Need AimingAccuracies averaged into 1 value

{_array =[];
 _group = group _x;
 _aiming = _x skillFinal "AimingAccuracy";

 (_array select 0) pushBack [_aiming];

  _countArray = count _array;
 
 _avgAiming = from select 0 to select _countArray/_countArray;
  } foreach units _group;

 Hint str _avgAiming;

Share this post


Link to post
Share on other sites

 The adventure continues.

 

 Need a way to get a numerical average of a groups total subSkill such as AimingAccuracy

 

 Yes i know this codes gobblegook but hopefully you can see direction im trying to go - need an array built with each group unit's aimingAccuracy push in, added to a total and then averaged out

 

 // Need AimingAccuracies averaged into 1 value

{_array =[];

 _group = group _x;

 _aiming = _x skillFinal "AimingAccuracy";

 (_array select 0) pushBack [_aiming];

  _countArray = count _array;

 

 _avgAiming = from select 0 to select _countArray/_countArray;

  } foreach units _group;

 Hint str _avgAiming;

 

Not entirely sure what you want, but, to obtain the arithmetic mean for the 'aimingAccuracy' values of a group:

_group = group player; 
_count = 0; 
_skill = "AimingAccuracy"; 
 
{ 
 _count = _count + (_x skillFinal _skill); 
} foreach units _group; 
 
_average = _count/(count (units _group));
  • Like 1

Share this post


Link to post
Share on other sites

Keep it simple © 

private _ski = {if (sk > _x) exitWith {_forEachIndex}} forEach [200, 160, 120, 80, 40, -1]; //skill index: elite = 0 ... novice = 5
private _skb = [0.9, 0.8, 0.6, 0.5, 0.4, 0.3] select _ski;  // skill boost:  elite = 0.9 ... novice = 0.3

{	_x setSkill ["aimingaccuracy", _skb]
} forEach (units player);

Or even simplier:

private _skb = {if (sk > _x) exitWith {[0.9, 0.8, 0.6, 0.5, 0.4, 0.3] select _forEachIndex}} forEach [200, 160, 120, 80, 40, -1];

{	_x setSkill ["aimingaccuracy", _skb]
} forEach (units player);

UPD: Fixed units enumeration

  • Like 1

Share this post


Link to post
Share on other sites

 

 Something bizarre is happening with this old script that always worked perfectly before. That being if I have a unit with a low aimingAccuracy subskill like 0.03 and then want to add a 0.05 bonus to it after every successful kill -the math goes wonky. Sometimes it adds, sometimes it subtracts and the results wildly vary such as jumping from, 0.11665 to .86 after a kill. Really seems like it happens the most with any values under 0.2 and/or with long decimals such as .255555. With long decimals, sometimes the bonus adds itself to the farthest right digits such as:

 

 aimingAccuracy .0255555 + (bonus) 0.03 = .0255558 or will subtract .0255552 and seems to happen randomly

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

×