BEAKSBY 11 Posted June 13, 2014 HI All, Currently I have a script that works. It finds the value of a unit killed (vehicle or soldier) by an enemy unit (player or AI) and adds this value to the player who made the kill's account, all based on half the values listed in the _veh array. However I'm expanding this script to also include the value of units inside the vehicle (if it is occupied) as well as the vehicle depending what is killed. So that now I would like the money gained by the _killer (player or AI) to account for empty vehicles, units or a vehicle with the units killed inside. My new script is not working. Is there a problem with the nested _i variables, syntax or misunderstanding of functions? Please help... initServer.sqf { //--- Add killed EH to unit _handle = _x addEventHandler [ "Killed", { _unit = _this select 0; _killer = _this select 1; _handle = _unit getVariable [ "DNA_EH_Killed_Money", -1 ]; _unitValue = 0; _unitsInVehicleSumValue = 0; //--- Check if opposite side is killed by _killer if (side group _killer != side group _unit) then { //--- Determine money value of _unit based on unit class _unitType = typeOf _unit; // array of original price of units _veh = [[1200, "B_MBT_01_TUSK_F"],[900, "B_APC_Tracked_01_rcws_F"],[750, "B_APC_Tracked_01_AA_F"],[600, "I_APC_Wheeled_03_cannon_F"], [300,"B_MRAP_01_gmg_F"],[150,"B_MRAP_01_hmg_F"],[100,"B_G_Offroad_01_armed_F"],[200,"B_static_AT_F"],[200, "B_static_AA_F"],[150,"B_soldier_LAT_F"], [100,"B_G_Soldier_LAT_F"],[25, "B_Soldier_F"],[150,"B_GMG_01_high_F"],[100,"B_HMG_01_high_F"],[1200, "O_MBT_02_cannon_F"],[900, "O_APC_Tracked_02_cannon_F"], [750, "O_APC_Tracked_02_AA_F"],[600, "O_APC_Wheeled_02_rcws_F"],[300,"O_MRAP_02_gmg_F"],[150,"O_MRAP_02_hmg_F"],[100,"O_G_Offroad_01_armed_F"], [200,"O_static_AT_F"],[200, "O_static_AA_F"],[150,"O_soldierU_LAT_F"],[100,"O_G_Soldier_LAT_F"],[150,"O_GMG_01_high_F"],[100,"O_HMG_01_high_F"], [25, "O_Soldier_F"]]; // My notes on units, count and in // units --> Returns an array with all the units in the group or group of the unit. For a destroyed object an empty array is returned. // https://community.bistudio.com/wiki/units // EXAMPLE1: _isInMyGroup = _soldier1 in units player; // EXAMPLE2:_myUnitCount = count units group player; // MY Back-up: _countUnitsInVehicle = count units in group _unitType; // in case count _unitArrayInVehicle; further below does not work // count -->returns number of units in player group // EXAMPLE3:_cnt = count units group player; // https://community.bistudio.com/wiki/count // Checks whether the object is (a subtype) of the given type. Example: vehicle player isKindOf "LandVehicle"; https://community.bistudio.com/wiki/isKindOf if _unitType isKindOf "LandVehicle" then { // obtain count and type of units killed inside as well as the vehicle killed _unitArrayInVehicle = allUnits in units _unitType; // array of units in vehicle _countUnitsInVehicle = count _unitArrayInVehicle; // number of units in vehicle for "_i" from 0 to (count _countUnitsInVehicle)-1 do { // sum value of all units in vehicle _unitInVehicle = _unitArrayInVehicle select _i; for "_i" from 0 to (count _veh)-1 do { // check value for each unit in vehicle if (_unitInVehicle == ((_veh select _i) select 1)) then {_unitsInVehicleSumValue = _unitsInVehicleSumValue + (((_veh select _i) select 0)/2)}; // each unit value is half original price listed above }; }; for "_i" from 0 to (count _veh)-1 do { // also add the value of vehicle killed if (_unitType == ((_veh select _i) select 1)) then {_unitValue = (((_veh select _i) select 0)/2)}; // each unit value is half original price listed above }; _unitValue = _unitValue + _unitsInVehicleSumValue; // total value of vehicle and units killed inside } else { //need to get type of unit killed id not inside a vehicle for "_i" from 0 to (count _veh)-1 do { // value of vehicle killed also if (_unitType == ((_veh select _i) select 1)) then {_unitValue = (((_veh select _i) select 0)/2)}; // each unit value is half original price listed above }; }; //--- Add money to the client [ _unitValue, "DNA_fnc_addMoney", _killer ] call BIS_fnc_MP; }; //--- Remove the event handler _unit removeEventHandler [ "Killed", _handle ]; } ]; //--- Store killed EH handle in unit namespace _x setVariable [ "DNA_EH_Killed_Money", _handle ]; } forEach vehicles + allUnits; // THIS WORKS Createcenter EAST; Createcenter WEST; WEST setFriend [EAST,0]; EAST setFriend [WEST,0]; [west, "WEST1"] call BIS_fnc_addRespawnInventory; [west, "WEST2"] call BIS_fnc_addRespawnInventory; [west, "WEST3"] call BIS_fnc_addRespawnInventory; [east, "EAST1"] call BIS_fnc_addRespawnInventory; [east, "EAST2"] call BIS_fnc_addRespawnInventory; [east, "EAST3"] call BIS_fnc_addRespawnInventory; if (sector1 getVariable 'owner' == WEST) then {[west, "sector1"] call BIS_fnc_addRespawnPosition}; // [west, "Sector2"] call BIS_fnc_addRespawnPosition; [west,[1685,5640,150]] call BIS_fnc_addRespawnPosition; [east,[1685,5640,150]] call BIS_fnc_addRespawnPosition; // [getPos player, WEST, 5] call BIS_fnc_spawnGroup; [] execVM "cleanup.sqf"; ...thanks in-advance, fantastic community! Share this post Link to post Share on other sites
f2k sel 164 Posted June 13, 2014 I'm a bit confused, if you add the eventhandler to units and vehicles why do you need to add the score together in the eventhandler script as each EVH should activate one by one. Share this post Link to post Share on other sites
BEAKSBY 11 Posted June 13, 2014 Hi Again F2k Sel, It does and it doesn't. It does for vehicles that are empty and units outside of vehicles, BUT, when I destroy a vehicle with units inside it only seems to register the vehicle as the kill. I'm trying to reward the _killer with money for both the vehicle and if there are units inside. I'm using _unitType = typeOf _unit; and this seems to only return the vehicle if there are units inside. I think the "Killed" eventHandler is not registering the units inside...at least from the earlier scirpt version I was using. Share this post Link to post Share on other sites
f2k sel 164 Posted June 13, 2014 I just did a little test and it seems to work ok, you will need the mpkilled event handler won't you? https://community.bistudio.com/wiki/addMPEventHandler Share this post Link to post Share on other sites
BEAKSBY 11 Posted June 13, 2014 I just did a little test and it seems to work ok, you will need the mpkilled event handler won't you?https://community.bistudio.com/wiki/addMPEventHandler Did you test in on a LAN for MP? Share this post Link to post Share on other sites
f2k sel 164 Posted June 14, 2014 Just SP only. If it's not working then it's the usual locality issues. If you just do it using the vehicles EVH the you can make an array of the crew rather than use all units to see if they are in the vehicle. _cr=[]; {_cr = _cr + [_x] } foreach crew car; however if they get out then they won't have an eventhandler attached to them. Share this post Link to post Share on other sites
BEAKSBY 11 Posted June 14, 2014 (edited) I still have not found the problem, but my MP game works but none of the do loops or in thenstatements are executing from post#1. I tested with just these lines isolated from the script. if (_unitType isKindOf "LandVehicle") then { // hint format["_unitType %1",_unitType] TESTED & WORKS // obtain count and type of units killed inside as well as the vehicle killed _unitArrayInVehicle = allUnits in units _unitType; // array of units in vehicle _countUnitsInVehicle = count _unitArrayInVehicle; // number of units in vehicle hint format["_unitArrayInVehicle: %1 ",_unitArrayInVehicle ]; //TESTED & DOES NOT WORK }; I'll try crew in the morning. I don't think this line below is working because it is not hinting. _unitArrayInVehicle = allUnits in units _unitType; // array of units in vehicle I simply want the array of units in the vehicle. This was finally resolved with _unitArrayInVehicle = units _unit; Edited June 15, 2014 by BEAKSBY Share this post Link to post Share on other sites