ElectroEsper 14 Posted August 19, 2015 Hi, ok, simply said, I'm working on a "Casualty Counters". Without further due, here is the scripts that make it. Init.sqf apcLosesRU = 0; // rhs_vehclass_apc apcLosesListRU = []; ifvLosesRU = 0; // rhs_vehclass_ifv ifvLosesListRU = []; carLosesRU = 0; // rhs_vehclass_car carLosesListRU = []; truckLosesRU = 0; // rhs_vehclass_truck - RHS_BM21_MSV_01 truckLosesListRU = []; tankLosesRU = 0; // rhs_vehclass_tank tankLosesListRU = []; artilleryLosesRU = 0; // rhs_vehclass_artillery + RHS_BM21_MSV_01 artilleryLosesListRU = []; infantryLosesRU = 0; // man (east) staticLosesRU = 0; // StaticWeapon (east) staticLosesListRU = []; planeLosesRU = 0; // rhs_vehclass_aircraft planeLosesListRU = []; helicopterLosesRU = 0; // rhs_vehclass_helicopter helicopterLosesListRU = []; aaaLosesRU = 0; // rhs_vehclass_aa aaaLosesListRU = []; sleep 0.1; nul = [] execVM "losesCounter\losesTrackerRU.sqf"; nul = [10] execVM "losesCounter\losesTrackerRU_Updates.sqf"; losesTrackerRU.sqf if (!isServer) exitWith {}; //category { //_unit = _this select 0; if (isPlayer _x) exitWith {}; //Checks if dead unit was a player; if it was then the script exits. if (_x isKindOf "Man") then { //Checks if the dead unit was infantry; _x addEventHandler ["killed", { infantryLosesRU = infantryLosesRU + 1; //Add +1 loses to the counter. publicVariable "infantryLosesRU"; //Broadcast the updated variable. //publicVariableServer "infantryLosesRU"; hint format ["%1",infantryLosesRU]; }]; }; if (_x isKindOf "rhs_vehclass_apc") then { //Make sure that the dead unit was a APC; if it was then it checks TRUE. _x addEventHandler ["killed", { apcLosesRU = apcLosesRU + 1; publicVariable "apcLosesRU"; //publicVariableServer "apcLosesRU"; _vehicleType = typeOf _x; //Checks what type of vehicle was killed and create a string; apcLosesListRU pushBack _vehicleType; //Add the unit to the vehicle loses array as a string. publicVariable "apcLosesListRU"; //publicVariableServer "apcLosesListRU"; }]; }; if (_x isKindOf "rhs_vehclass_ifv") then { _x addEventHandler ["killed", { ifvLosesRU = ifvLosesRU + 1; publicVariable "ifvLosesRU"; //publicVariableServer "ifvLosesRU"; _vehicleType = typeOf _x; ifvLosesListRU pushBack _vehicleType; publicVariable "ifvLosesListRU"; //publicVariableServer "ifvLosesListRU"; }]; }; if (_x isKindOf "rhs_vehclass_car") then { _x addEventHandler ["killed", { carLosesRU = carLosesRU + 1; publicVariable "carLosesRU"; //publicVariableServer "carLosesRU"; _vehicleType = typeOf _x; carLosesListRU pushBack _vehicleType; publicVariable "carLosesListRU"; //publicVariableServer "carLosesListRU"; }]; }; if ((_x isKindOf "rhs_vehclass_truck") && (!(_x isKindOf "RHS_BM21_MSV_01"))) then { //Since I want to consider the BM-21 as an artillery but is considered by the game as rhs_vehclass_truck, I have to create a double check to make sure it counted. _x addEventHandler ["killed", { truckLosesRU = truckLosesRU + 1; publicVariable "truckLosesRU"; //publicVariableServer "truckLosesRU"; _vehicleType = typeOf _x; truckLosesListRU pushBack _vehicleType; publicVariable "truckLosesListRU"; //publicVariableServer "truckLosesListRU"; }]; }; if (_x isKindOf "rhs_vehclass_tank") then { _x addEventHandler ["killed", { tankLosesRU = tankLosesRU + 1; publicVariable "tankLosesRU"; //publicVariableServer "tankLosesRU"; _vehicleType = typeOf _x; tankLosesListRU pushBack _vehicleType; publicVariable "tankLosesListRU"; //publicVariableServer "tankLosesListRU"; }]; }; if ((_x isKindOf "rhs_vehclass_artillery") or (_x isKindOf "RHS_BM21_MSV_01")) then { //Since I want to consider the BM-21 as an artillery, I have to create a double check to make sure it is counted. _x addEventHandler ["killed", { artilleryLosesRU = artilleryLosesRU + 1; publicVariable "artilleryLosesRU"; //publicVariableServer "artilleryLosesRU"; _vehicleType = typeOf _x; artilleryLosesListRU pushBack _vehicleType; publicVariable "artilleryLosesListRU"; //publicVariableServer "artilleryLosesListRU"; }]; }; if (_x isKindOf "Static") then { _x addEventHandler ["killed", { staticLosesRU = staticLosesRU + 1; publicVariable "staticLosesRU"; //publicVariableServer "staticLosesRU"; _vehicleType = typeOf _x; staticLosesListRU pushBack _vehicleType; publicVariable "staticLosesListRU"; //publicVariableServer "staticLosesListRU"; }]; }; if (_x isKindOf "rhs_vehclass_aircraft") then { _x addEventHandler ["killed", { planeLosesRU = planeLosesRU + 1; publicVariable "planeLosesRU"; //publicVariableServer "planeLosesRU"; _vehicleType = typeOf _x; planeLosesListRU pushBack _vehicleType; publicVariable "planeLosesListRU"; //publicVariableServer "planeLosesListRU"; }]; }; if (_x isKindOf "rhs_vehclass_helicopter") then { _x addEventHandler ["killed", { helicopterLosesRU = helicopterLosesRU + 1; publicVariable "helicopterLosesRU"; //publicVariableServer "helicopterLosesRU"; _vehicleType = typeOf _x; helicopterLosesListRU pushBack _vehicleType; publicVariable "helicopterLosesListRU"; //publicVariableServer "helicopterLosesListRU"; }]; }; if (_x isKindOf "rhs_vehclass_aa") then { _x addEventHandler ["killed", { aaaLosesRU = aaaLosesRU + 1; publicVariable "aaaLosesRU"; //publicVariableServer "aaaLosesRU"; _vehicleType = typeOf _x; aaaLosesListRU pushBack _vehicleType; publicVariable "aaaLosesListRU"; //publicVariableServer "aaaLosesListRU"; }]; }; }forEach allunits + vehicles; losesTrackerRU_Updates.sqf _timer = _this select 0; //In seconds while{true} do { _apcLosesRU = missionNamespace getVariable "apcLosesRU"; _apcLosesListRU = missionNamespace getVariable "apcLosesListRU"; _ifvLosesRU = missionNamespace getVariable "ifvLosesRU"; _ifvLosesListRU = missionNamespace getVariable "ifvLosesListRU"; _carLosesRU = missionNamespace getVariable "carLosesRU"; _carLosesListRU = missionNamespace getVariable "carLosesListRU"; _truckLosesRU = missionNamespace getVariable "truckLosesRU"; _truckLosesListRU = missionNamespace getVariable "truckLosesListRU"; _tankLosesRU = missionNamespace getVariable "tankLosesRU"; _tankLosesListRU = missionNamespace getVariable "tankLosesListRU"; _artilleryLosesRU = missionNamespace getVariable "artilleryLosesRU"; _artilleryLosesListRU = missionNamespace getVariable "artilleryLosesListRU"; _infantryLosesRU = missionNamespace getVariable "infantryLosesRU"; _staticLosesRU = missionNamespace getVariable "staticLosesRU"; _staticLosesListRU = missionNamespace getVariable "staticLosesListRU"; _planeLosesRU = missionNamespace getVariable "planeLosesRU"; _planeLosesListRU = missionNamespace getVariable "planeLosesListRU"; _helicopterLosesRU = missionNamespace getVariable "helicopterLosesRU"; _helicopterLosesListRU = missionNamespace getVariable "helicopterLosesListRU"; _aaaLosesRU = missionNamespace getVariable "aaaLosesRU"; _aaaLosesListRU = missionNamespace getVariable "aaaLosesListRU"; //paste the variables to .rpt (client-side) diag_log "////////////////////////////////STARTS////////////////////////////////"; diag_log format ["Lost %1 APCs",_apcLosesRU]; diag_log format ["Lost APCs List : %1",_apcLosesListRU]; diag_log format ["Lost %1 IFVs", _ifvLosesRU]; diag_log format ["Lost IFVs List : %1",_ifvLosesListRU]; diag_log format ["Lost %1 Cars", _carLosesRU]; diag_log format ["Lost Cars List : %1",_carLosesListRU]; diag_log format ["Lost %1 Trucks", _truckLosesRU]; diag_log format ["Lost Trucks List : %1",_truckLosesListRU]; diag_log format ["Lost %1 Tanks", _tankLosesRU]; diag_log format ["Lost Tanks List : %1",_tankLosesListRU]; diag_log format ["Lost %1 SPGs/MRLS", _artilleryLosesRU]; diag_log format ["Lost SPGs/MRLS List : %1",_artilleryLosesListRU]; diag_log format ["Lost %1 Men", _infantryLosesRU]; diag_log format ["Lost %1 Static Emplacements", _staticLosesRU]; diag_log format ["Lost Static Emplacements List : %1",_staticLosesListRU]; diag_log format ["Lost %1 Planes", _planeLosesRU]; diag_log format ["Lost Planes List : %1",_planeLosesListRU]; diag_log format ["Lost %1 Helicopters", _helicopterLosesRU]; diag_log format ["Lost Helicopters List : %1",_helicopterLosesListRU]; diag_log format ["Lost %1 Armored Anti-Airs", _aaaLosesRU]; diag_log format ["Lost Armored Anti-Airs List : %1",_aaaLosesListRU]; diag_log "////////////////////////////////FINISHES//////////////////////////////"; sleep _timer; }; So, what do not work, is that Vehicles are not pickup when they get killed/destroyed. Results in .rpt 21:01:11 "////////////////////////////////STARTS////////////////////////////////" 21:01:11 "Lost 0 APCs" 21:01:11 "Lost APCs List : []" 21:01:11 "Lost 0 IFVs" 21:01:11 "Lost IFVs List : []" 21:01:11 "Lost 0 Cars" 21:01:11 "Lost Cars List : []" 21:01:11 "Lost 0 Trucks" 21:01:11 "Lost Trucks List : []" 21:01:11 "Lost 0 Tanks" 21:01:11 "Lost Tanks List : []" 21:01:11 "Lost 0 SPGs/MRLS" 21:01:11 "Lost SPGs/MRLS List : []" 21:01:11 "Lost 14 Men" 21:01:11 "Lost 0 Static Emplacements" 21:01:11 "Lost Static Emplacements List : []" 21:01:11 "Lost 0 Planes" 21:01:11 "Lost Planes List : []" 21:01:11 "Lost 0 Helicopters" 21:01:11 "Lost Helicopters List : []" 21:01:11 "Lost 0 Armored Anti-Airs" 21:01:11 "Lost Armored Anti-Airs List : []" 21:01:11 "////////////////////////////////FINISHES//////////////////////////////" So, the loses detection works just great for infantry. However it do not pick-up the vehicles. Any clue? Thanks in advance! Share this post Link to post Share on other sites
Larrow 2794 Posted August 19, 2015 You can not use _x within the eventHandler as it is undefined there. Use the object passed into the EH in _this select 0 instead. This will account for your type arrays being empty. rhs_vehClass_# are not vehicle classes, they are classes used to sort the vehicle lists in the editor dropdowns. To find the vehicle classes highlight a class in CfgVehicles in the configViewer and look at the bottom line.. For example a "rhs_t80b" will say.. path : configfile >> "CfgVehicles" >> "rhs_t80b" parents : ["rhs_tank_base","Tank_F","Tank","LandVehicle","Land","AllVehicles","All"] So a "rhs_t80b" is a kindof "rhs_tank_base" which in turn is a kind of "Tank_F" which is a "Tank" etc etc. So depending on how broad you need to be, the further up the list you go. If you want to know based on the editor lists rhs_vehClass_# you can but instead of using isKindof, you will need to check their config. e.g if ( getText ( configFile >> "CfgVehicles" >> typeOf _x >> "vehicleClass" ) isEqualTo "rhs_vehclass_tank" ) then { _x addEventHandler ["killed", { tankLosesRU = tankLosesRU + 1; publicVariable "tankLosesRU"; //publicVariableServer "tankLosesRU"; _vehicleType = typeOf ( _this select 0 ); tankLosesListRU pushBack _vehicleType; publicVariable "tankLosesListRU"; //publicVariableServer "tankLosesListRU"; }]; }; 2 Share this post Link to post Share on other sites
ElectroEsper 14 Posted August 19, 2015 No change in results. Could it be that crewed vehicle cannot receive an event-handler? I even tested on having "Tank" as the isKindOf check reference, nothing came-up. Could it have something to do with the crew bailing out before it explodes? Ok, I can make work with what you wrote, the problem seemed to be: }forEach allunits + vehicles; When I seperate the script in "allunits" and "vehicles" part, independant of each others, it works great. Thanks for the help :) Updated losesTrackerRU.sqf if (!isServer) exitWith {}; { //_unit = _this select 0; if (isPlayer _x) exitWith {}; //Checks if dead unit was a player; if it was then the script exits. if (_x isKindOf "Man") then { //Checks if the dead unit was infantry; _x addEventHandler ["killed", { infantryLosesRU = infantryLosesRU + 1; //Add +1 loses to the counter. publicVariable "infantryLosesRU"; //Broadcast the updated variable. //publicVariableServer "infantryLosesRU"; hint format ["%1",infantryLosesRU]; }]; }; }forEach allunits; { if ( getText ( configFile >> "CfgVehicles" >> typeOf _x >> "vehicleClass" ) isEqualTo "rhs_vehclass_apc") then { //Make sure that the dead unit was a APC; if it was then it checks TRUE. _x addEventHandler ["killed", { apcLosesRU = apcLosesRU + 1; publicVariable "apcLosesRU"; //publicVariableServer "apcLosesRU"; _vehicleType = typeOf (_this select 0); //Checks what type of vehicle was killed and create a string; apcLosesListRU pushBack _vehicleType; //Add the unit to the vehicle loses array as a string. publicVariable "apcLosesListRU"; //publicVariableServer "apcLosesListRU"; }]; }; if ( getText ( configFile >> "CfgVehicles" >> typeOf _x >> "vehicleClass" ) isEqualTo "rhs_vehclass_ifv" ) then { _x addEventHandler ["killed", { ifvLosesRU = ifvLosesRU + 1; publicVariable "ifvLosesRU"; //publicVariableServer "ifvLosesRU"; _vehicleType = typeOf (_this select 0); ifvLosesListRU pushBack _vehicleType; publicVariable "ifvLosesListRU"; //publicVariableServer "ifvLosesListRU"; }]; }; if ( getText ( configFile >> "CfgVehicles" >> typeOf _x >> "vehicleClass" ) isEqualTo "rhs_vehclass_car") then { _x addEventHandler ["killed", { carLosesRU = carLosesRU + 1; publicVariable "carLosesRU"; //publicVariableServer "carLosesRU"; _vehicleType = typeOf (_this select 0); carLosesListRU pushBack _vehicleType; publicVariable "carLosesListRU"; //publicVariableServer "carLosesListRU"; }]; }; if (( getText ( configFile >> "CfgVehicles" >> typeOf _x >> "vehicleClass" ) isEqualTo "rhs_vehclass_truck") && (!(_x isKindOf "RHS_BM21_MSV_01"))) then { //Since I want to consider the BM-21 as an artillery but is considered by the game as rhs_vehclass_truck, I have to create a double check to make sure it counted. _x addEventHandler ["killed", { truckLosesRU = truckLosesRU + 1; publicVariable "truckLosesRU"; //publicVariableServer "truckLosesRU"; _vehicleType = typeOf (_this select 0); truckLosesListRU pushBack _vehicleType; publicVariable "truckLosesListRU"; //publicVariableServer "truckLosesListRU"; }]; }; if ( getText ( configFile >> "CfgVehicles" >> typeOf _x >> "vehicleClass" ) isEqualTo "rhs_vehclass_tank") then { _x addEventHandler ["killed", { tankLosesRU = tankLosesRU + 1; publicVariable "tankLosesRU"; //publicVariableServer "tankLosesRU"; _vehicleType = typeOf (_this select 0 ); tankLosesListRU pushBack _vehicleType; publicVariable "tankLosesListRU"; //publicVariableServer "tankLosesListRU"; }]; }; if (( getText ( configFile >> "CfgVehicles" >> typeOf _x >> "vehicleClass" ) isEqualTo "rhs_vehclass_artillery") or (_x isKindOf "RHS_BM21_MSV_01")) then { //Since I want to consider the BM-21 as an artillery, I have to create a double check to make sure it is counted. _x addEventHandler ["killed", { artilleryLosesRU = artilleryLosesRU + 1; publicVariable "artilleryLosesRU"; //publicVariableServer "artilleryLosesRU"; _vehicleType = typeOf (_this select 0); artilleryLosesListRU pushBack _vehicleType; publicVariable "artilleryLosesListRU"; //publicVariableServer "artilleryLosesListRU"; }]; }; if ( getText ( configFile >> "CfgVehicles" >> typeOf _x >> "vehicleClass" ) isEqualTo "Static") then { _x addEventHandler ["killed", { staticLosesRU = staticLosesRU + 1; publicVariable "staticLosesRU"; //publicVariableServer "staticLosesRU"; _vehicleType = typeOf (_this select 0); staticLosesListRU pushBack _vehicleType; publicVariable "staticLosesListRU"; //publicVariableServer "staticLosesListRU"; }]; }; if ( getText ( configFile >> "CfgVehicles" >> typeOf _x >> "vehicleClass" ) isEqualTo "rhs_vehclass_aircraft") then { _x addEventHandler ["killed", { planeLosesRU = planeLosesRU + 1; publicVariable "planeLosesRU"; //publicVariableServer "planeLosesRU"; _vehicleType = typeOf (_this select 0); planeLosesListRU pushBack _vehicleType; publicVariable "planeLosesListRU"; //publicVariableServer "planeLosesListRU"; }]; }; if ( getText ( configFile >> "CfgVehicles" >> typeOf _x >> "vehicleClass" ) isEqualTo "rhs_vehclass_helicopter") then { _x addEventHandler ["killed", { helicopterLosesRU = helicopterLosesRU + 1; publicVariable "helicopterLosesRU"; //publicVariableServer "helicopterLosesRU"; _vehicleType = typeOf (_this select 0); helicopterLosesListRU pushBack _vehicleType; publicVariable "helicopterLosesListRU"; //publicVariableServer "helicopterLosesListRU"; }]; }; if ( getText ( configFile >> "CfgVehicles" >> typeOf _x >> "vehicleClass" ) isEqualTo "rhs_vehclass_aa") then { _x addEventHandler ["killed", { aaaLosesRU = aaaLosesRU + 1; publicVariable "aaaLosesRU"; //publicVariableServer "aaaLosesRU"; _vehicleType = typeOf (_this select 0); aaaLosesListRU pushBack _vehicleType; publicVariable "aaaLosesListRU"; //publicVariableServer "aaaLosesListRU"; }]; }; }forEach vehicles; Results in full glory :P 8:48:31 "////////////////////////////////STARTS////////////////////////////////" 8:48:31 "Lost 0 APCs" 8:48:31 "Lost APCs List : []" 8:48:31 "Lost 1 IFVs" 8:48:31 "Lost IFVs List : ["rhs_bmp1p_msv"]" 8:48:31 "Lost 0 Cars" 8:48:31 "Lost Cars List : []" 8:48:31 "Lost 0 Trucks" 8:48:31 "Lost Trucks List : []" 8:48:31 "Lost 1 Tanks" 8:48:31 "Lost Tanks List : ["rhs_t72bb_tv"]" 8:48:31 "Lost 1 SPGs/MRLS" 8:48:31 "Lost SPGs/MRLS List : ["RHS_BM21_VMF_01"]" 8:48:31 "Lost 24 Men" 8:48:31 "Lost 0 Static Emplacements" 8:48:31 "Lost Static Emplacements List : []" 8:48:31 "Lost 0 Planes" 8:48:31 "Lost Planes List : []" 8:48:31 "Lost 0 Helicopters" 8:48:31 "Lost Helicopters List : []" 8:48:31 "Lost 1 Armored Anti-Airs" 8:48:31 "Lost Armored Anti-Airs List : ["rhs_zsu234_aa"]" 8:48:31 "////////////////////////////////FINISHES//////////////////////////////" Thanks again! Share this post Link to post Share on other sites