Search the Community
Showing results for tags 'rankID'.
Found 1 result
-
[Solved] change unit in global array if unit is killed
sarogahtyp posted a topic in ARMA 3 - MISSION EDITING & SCRIPTING
Hey guys, I ve to fight a bug in Sarogahtyps Spawn Script Creator - SSSC and thats the problem: I ve a main array which is called globalLeaderArray. There in I store group leaders. My problem is that when one of that group leaders die then it auto leaves the group and I cant get the group later to handle it in my caching parts of the script. Now I thought about to add a killed EH to store the new group leader (after the old has been killed) in globalLeaderArray. The following code has 2 functions fnc_mark_leaders initially pushs a leader in the global array and fnc_add_killed_EH adds an EH to that leader which changes the leader object in the global array if the leader dies. Because I use fnc_add_killed_EH inside of the EH itself there is some kind of recursive structure in it and I d like to know if that could work. Also I think its a bit complex for only change one object in an array so I wonder if someone knows a neater way to do that. fnc_mark_leaders = { params [["_unit", objNull, [objNull]]]; if (isNull _unit) exitWith {true}; private _leader = leader _unit; if (isNil "globalLeaderArray") then { globalLeaderArray =[]; }; if (!(_leader in globalLeaderArray)) then { _lead_index = globalLeaderArray pushBack _leader; _leader setVariable["lead_info", [_lead_index, (group _leader)]]; _leader call fnc_add_killed_EH; }; }; fnc_add_killed_EH = { params ["_leader"]; _leader addEventHandler ["killed", { params ["_old_leader"]; _lead_info = _old_leader getVariable "lead_info"; _lead_index = _lead_info select 0; _group = _lead_info select 1; _new_leader = _group call fnc_get_highest; _group selectLeader _new_leader; globalLeaderArray set [_lead_index, _new_leader]; _new_leader setVariable["lead_info", [_lead_index, _group]]; _new_leader call fnc_add_killed_EH; }]; }; EDIT: function to get the highest ranked and highest rated unit in group. with that I dont need to wait until engine changed the leader itsself. fnc_get_highest = { params ["_group"]; private _highest_rank = 0; private _highest_rating = -99999; private ["_highest_rank_array"]; //select the highest ranked units found (last element is ranked highest) _highest_rank_array = ((units _group) select {alive _x}) select { _rank = rankID _x; _highest_rank = _highest_rank max _rank; (_highest_rank == _rank) }; // reverse array to have highest ranked units at array start reverse _highest_rank_array; // cut the array after last unit with the highest rank { if(rankID _x < _highest_rank) exitWith {_highest_rank_array resize _forEachIndex}; } forEach _highest_rank_array; //exit if only one unit has the highest rank if(count _highest_rank_array == 1) exitWith { (_highest_rank_array select 0) }; //select the highest ranked unit whith the highest rating (last element is rated highest) _highest_rank_array = _highest_rank_array select { _rating = rating _x; _highest_rating = _highest_rating max _rating; (_highest_rating == _rating) }; //return the last element because its the highest ranked an the highest rated unit in group (_highest_rank_array select ((count _highest_rank_array) - 1)) };- 10 replies
-
- addEventHandler
- killed
-
(and 3 more)
Tagged with: