BEAKSBY 11 Posted June 21, 2014 (edited) HI ALL, I can't figure out what is causing the issue described below. When only a vehicle or vehicle with units are killed the correct vallue is passed to the fn_addMoney function. HOWEVER, when a soldier is killed, not in a vehicle, it's value seems to tripple (or some times double) once passed through to the fn_addMoney function. When I test by killing a soldier with hints, the unitValue values are correct except for inside the fn_addMoney function where is it 0 and the money value shows two or three times the expected value. I can't figure out what's causing the problem. InitServer.sqf 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"],[600,"B_APC_Wheeled_01_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"], [66, "O_crew_F"],[66, "B_crew_F"]]; { //--- Add killed EH to unit FOR VEHICLES AND UNITS IN VEHICLES _handle = _x addEventHandler [ "Killed", { _unit = _this select 0; _killer = _this select 1; _handle = _unit getVariable [ "DNA_EH_Killed_Money", -1 ]; _textvehicle = ""; unitValue=0; if ((side group _killer != side group _unit) && (side _killer != sideEnemy)) then { //--- Check if opposite side is killed by _killer && _Killer is not an renegade if (typeOf vehicle _unit isKindOf "LandVehicle") then { //---condition of vehicles only { __x =_x; { if (( typeof _x) in __x ) then {unitValue = unitValue + (__x select 0)/2}; } foreach crew _unit + [_unit]; } foreach veh; _vehicle = getText (configFile >> "cfgVehicles" >> typeof _unit >> "displayname"); _picture = getText (configFile >> "cfgVehicles" >> typeof _unit >> "picture"); // _textvehicle = parsetext format ["<img size='2' image='%1'/><t size='1.2'><br/> %2 <t size='1'><br/> %3 Crew <t size='0.85'> <br/>Reward %4", _picture,_vehicle,count crew _unit,unitValue]; //hint _textvehicle; }; //--- Add unitValue to the client [ [unitValue, _unit], "DNA_fnc_addMoney", side group _killer ] call BIS_fnc_MP; }; } ]; //--- Store killed EH handle in unit namespace _x setVariable [ "DNA_EH_Killed_Money", _handle ]; m } forEach vehicles; // THIS WORKS { //--- Add killed EH to unit FOR UNITS ONLY (NOT IN VEHICLES) _handle = _x addEventHandler [ "Killed", { _unit = _this select 0; _killer = _this select 1; _handle = _unit getVariable [ "DNA_EH_Killed_Money", -1 ]; unitValue=0; //--- Check if opposite side is killed by _killer if ((side group _killer != side group _unit) && (side _killer != sideEnemy)) then { //--- Check if opposite side is killed by _killer && _Killer is not an renegade if (vehicle _unit == _unit && ) then { //---hint "_unit is NOT in a vehicle" //--- Determine unitValue value of _unit based on unit class for "_i" from 0 to (count veh)-1 do { if (typeOf _unit == ((veh select _i) select 1)) then {unitValue = (((veh select _i) select 0)/2)}; //---each unit value is half original price listed above //--- Add unitValue to the client // hint format ["unitValue1: %1 \n _unit: %2", unitValue1, _unit]; [ [unitValue, _unit], "DNA_fnc_addMoney", side group _killer ] call BIS_fnc_MP; }; }; }; } ]; //--- Store killed EH handle in unit namespace _x setVariable [ "DNA_EH_Killed_Money", _handle ]; } forEach 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; //---parachute respawn point // [east,[1685,5640,150]] call BIS_fnc_addRespawnPosition; //---parachute respawn point // [getPos player, WEST, 5] call BIS_fnc_spawnGroup; [] execVM "cleanup.sqf"; fn_addMoney.sqf private ["_unitValue", "_textvehicle", "_unitType", "_vehicle", "_picture", "_unit", "_money" ]; _unitValue = [ _this, 0, 0, [0] ] call BIS_fnc_param; _unit = _this select 1; //---THIS WORKS //--- Add money to global DNA_Money = DNA_Money + _unitValue; _money = DNA_Money; hint format ["_unitValue: %1 \n _unit: %2 \n _money: %3", _unitValue, _unit, _money]; true Edited June 21, 2014 by BEAKSBY Share this post Link to post Share on other sites
Tajin 349 Posted June 23, 2014 I guess your problem lies here: } foreach crew _unit + [_unit]; If not in a vehicle, then "vehicle player == player". I bet that "crew player" also returns the same as "player". Hence you would count a unit twice when it is on foot. So try changing the line to this: } foreach (crew _unit - [_unit] + [_unit]); That way you can make sure that _unit doesn't occur twice in the array. Share this post Link to post Share on other sites
BEAKSBY 11 Posted June 23, 2014 Thanks Tajin, I think you're right...currently I'm testing this. I'll will let you know the results. Share this post Link to post Share on other sites