From 86ae5c42486546ec55f60f7952657eceb09127c8 Mon Sep 17 00:00:00 2001 From: Jacob Schmidt Date: Sun, 25 May 2025 14:20:36 -0500 Subject: [PATCH] feat: Implement task rewards and penalties This commit introduces a new task reward and penalty system. The following changes were made: - Added `handleTaskRewards` to `XEH_PREP.hpp` for pre-processing. - Added parameters for equipment, supply, weapon, vehicle, and special rewards to the task definition functions (`fnc_defuse.sqf`, `fnc_destroy.sqf`, `fnc_attack.sqf`, `fnc_hvt.sqf`, `fnc_delivery.sqf`, `fnc_defend.sqf`, `fnc_hostage.sqf`). - Modified task completion logic to handle rewards and penalties using the new `handleTaskRewards` function. - Replaced direct reputation and fund modifications with the new reward system. - Updated documentation to reflect the new reward parameters. --- addons/task/XEH_PREP.hpp | 1 + addons/task/functions/fnc_attack.sqf | 70 +++++++---- addons/task/functions/fnc_defend.sqf | 72 +++++++---- addons/task/functions/fnc_defuse.sqf | 65 ++++++---- addons/task/functions/fnc_delivery.sqf | 71 +++++++---- addons/task/functions/fnc_destroy.sqf | 70 +++++++---- .../task/functions/fnc_handleTaskRewards.sqf | 118 ++++++++++++++++++ addons/task/functions/fnc_hostage.sqf | 79 ++++++++---- addons/task/functions/fnc_hvt.sqf | 74 +++++++---- 9 files changed, 452 insertions(+), 168 deletions(-) create mode 100644 addons/task/functions/fnc_handleTaskRewards.sqf diff --git a/addons/task/XEH_PREP.hpp b/addons/task/XEH_PREP.hpp index 751cb01..b0eeb21 100644 --- a/addons/task/XEH_PREP.hpp +++ b/addons/task/XEH_PREP.hpp @@ -10,6 +10,7 @@ PREP(destroy); PREP(destroyModule); PREP(explosivesModule); PREP(handler); +PREP(handleTaskRewards); PREP(heartBeat); PREP(hostage); PREP(hostageModule); diff --git a/addons/task/functions/fnc_attack.sqf b/addons/task/functions/fnc_attack.sqf index 53490ac..0064d9b 100644 --- a/addons/task/functions/fnc_attack.sqf +++ b/addons/task/functions/fnc_attack.sqf @@ -13,7 +13,12 @@ * 5: Amount of rating the company and player recieve if the task is successful (default: 0) * 6: Should the mission end (MissionSuccess) if the task is successful (default: false) * 7: Should the mission end (MissionFailed) if the task is failed (default: false) - * 8: Amount of time before target(s) escape (default: nil) + * 8: Amount of time before target(s) escape (default: -1) + * 9: Equipment rewards (default: []) + * 10: Supply rewards (default: []) + * 11: Weapon rewards (default: []) + * 12: Vehicle rewards (default: []) + * 13: Special rewards (default: []) * * Return Value: * None @@ -25,7 +30,22 @@ * Public: Yes */ -params [["_taskID", ""], ["_limitFail", -1], ["_limitSuccess", -1], ["_companyFunds", 0], ["_ratingFail", 0], ["_ratingSuccess", 0], ["_endSuccess", false], ["_endFail", false], "_time"]; +params [ + ["_taskID", "", [""]], + ["_limitFail", -1, [0]], + ["_limitSuccess", -1, [0]], + ["_companyFunds", 0, [0]], + ["_ratingFail", 0, [0]], + ["_ratingSuccess", 0, [0]], + ["_endSuccess", false, [false]], + ["_endFail", false, [false]], + ["_time", -1, [0]], + ["_equipmentRewards", [], [[]]], + ["_supplyRewards", [], [[]]], + ["_weaponRewards", [], [[]]], + ["_vehicleRewards", [], [[]]], + ["_specialRewards", [], [[]]] +]; private _result = 0; @@ -43,7 +63,7 @@ waitUntil { private _targetsKilled = ({ !alive _x } count _targets); - if (!isNil "_time") then { + if (_time isNotEqualTo -1) then { private _timeExpired = (floor time - _startTime >= _time); if (_targetsKilled < _limitSuccess && _timeExpired) then { _result = 1; }; @@ -59,35 +79,39 @@ if (_result == 1) then { [_taskID, "FAILED"] call BFUNC(taskSetState); - if (_endFail) then { - ["MissionFail", false] remoteExecCall ["BIS_fnc_endMission", playerSide]; - }; + private _penalties = createHashMap; + _penalties set ["reputation", _ratingFail]; - // ["deduct", _ratingFail] remoteExecCall ["forge_server_rating_fnc_handleRating", 2]; - [_ratingFail] call EFUNC(org,addReputation); - [format ["Task failed: %1 reputation", _ratingFail], "warning", 5, "right"] call EFUNC(misc,notify); + [_taskID, _penalties] call FUNC(handleTaskRewards); - sleep 1; + sleep 1; + + { [_x, _ratingFail] remoteExec ["addRating", -2] } forEach allPlayers; + [format ["Task failed: %1 reputation", _ratingFail], "warning", 5, "right"] call EFUNC(misc,notify); - { [_x, _ratingFail] remoteExec ["addRating", -2] } forEach allPlayers; + if (_endFail) then { ["MissionFail", false] remoteExecCall ["BIS_fnc_endMission", playerSide]; }; } else { { deleteVehicle _x } forEach _targets; - [_taskID, "SUCCEEDED"] call BFUNC(taskSetState); + private _rewards = createHashMap; + _rewards set ["funds", _companyFunds]; + _rewards set ["reputation", _ratingSuccess]; - if (_endSuccess) then { - ["MissionSuccess", true] remoteExecCall ["BIS_fnc_endMission", playerSide]; - }; + if (count _equipmentRewards > 0) then { _rewards set ["equipment", _equipmentRewards]; }; + if (count _supplyRewards > 0) then { _rewards set ["supplies", _supplyRewards]; }; + if (count _weaponRewards > 0) then { _rewards set ["weapons", _weaponRewards]; }; + if (count _vehicleRewards > 0) then { _rewards set ["vehicles", _vehicleRewards]; }; + if (count _specialRewards > 0) then { _rewards set ["special", _specialRewards]; }; + + [_taskID, _rewards] call FUNC(handleTaskRewards); + [_taskID, "SUCCEEDED"] call BIS_fnc_taskSetState; - // ["advance", _ratingSuccess] remoteExecCall ["forge_server_rating_fnc_handleRating", 2]; - [_ratingSuccess] call EFUNC(org,addReputation); - [format ["Task completed: %1 reputation", _ratingSuccess], "success", 5, "right"] call EFUNC(misc,notify); + sleep 1; - sleep 1; + { [_x, _ratingSuccess] remoteExec ["addRating", -2] } forEach allPlayers; - { [_x, _ratingSuccess] remoteExec ["addRating", -2] } forEach allPlayers; - - // ["advance", _companyFunds] remoteExecCall ["forge_server_money_fnc_handleFunds", 2]; - [_companyFunds] call EFUNC(org,addFunds); + [format ["Task completed: %1 reputation", _ratingSuccess], "success", 5, "right"] call EFUNC(misc,notify); [format ["Task completed: %1 funds", _companyFunds], "success", 5, "right"] call EFUNC(misc,notify); + + if (_endSuccess) then { ["MissionSuccess", true] remoteExecCall ["BIS_fnc_endMission", playerSide]; }; }; \ No newline at end of file diff --git a/addons/task/functions/fnc_defend.sqf b/addons/task/functions/fnc_defend.sqf index f36ffa0..53347de 100644 --- a/addons/task/functions/fnc_defend.sqf +++ b/addons/task/functions/fnc_defend.sqf @@ -16,17 +16,39 @@ * 8: Enemy wave count (default: 3) * 9: Time between waves in seconds (default: 300) * 10: Minimum BLUFOR units required in zone (default: 1) + * 11: Equipment rewards (default: []) + * 12: Supply rewards (default: []) + * 13: Weapon rewards (default: []) + * 14: Vehicle rewards (default: []) + * 15: Special rewards (default: []) * * Return Value: * None * * Example: - * ["defend_zone_1", "defend_marker", 900, 500000, -100, 400, false, false, 3, 300, 1] spawn forge_client_task_fnc_defend; + * ["defend_zone_1", "defend_marker", 900, 500000, -100, 400, false, false, 3, 300, 1, ["ItemGPS"], ["FirstAidKit"], ["arifle_MX_F"], ["B_MRAP_01_F"], ["B_UAV_01_F"]] spawn forge_client_task_fnc_defend; * * Public: Yes */ -params [["_taskID", "", [""]], ["_defenseZone", "", [""]], ["_defendTime", 600, [0]], ["_companyFunds", 0, [0]], ["_ratingFail", 0, [0]], ["_ratingSuccess", 0, [0]], ["_endSuccess", false, [false]], ["_endFail", false, [false]], ["_waveCount", 3, [0]], ["_waveCooldown", 300, [0]], ["_minBlufor", 1, [0]]]; +params [ + ["_taskID", "", [""]], + ["_defenseZone", "", [""]], + ["_defendTime", 600, [0]], + ["_companyFunds", 0, [0]], + ["_ratingFail", 0, [0]], + ["_ratingSuccess", 0, [0]], + ["_endSuccess", false, [false]], + ["_endFail", false, [false]], + ["_waveCount", 3, [0]], + ["_waveCooldown", 300, [0]], + ["_minBlufor", 1, [0]], + ["_equipmentRewards", [], [[]]], + ["_supplyRewards", [], [[]]], + ["_weaponRewards", [], [[]]], + ["_vehicleRewards", [], [[]]], + ["_specialRewards", [], [[]]] +]; if (_defenseZone == "" || !(markerShape _defenseZone in ["RECTANGLE", "ELLIPSE"])) exitWith { diag_log format ["ERROR: Invalid defense zone marker: %1", _defenseZone]; }; @@ -39,12 +61,7 @@ private _warningIssued = false; waitUntil { sleep 1; - private _bluforInZone = count (allUnits select { - _x isKindOf "CAManBase" && - {side _x == west} && - {alive _x} - } inAreaArray _defenseZone); - + private _bluforInZone = count (allUnits select { _x isKindOf "CAManBase" && { side _x == west } && { alive _x }} inAreaArray _defenseZone); private _timeElapsed = time - _startTime; if (_bluforInZone < _minBlufor) then { @@ -76,30 +93,37 @@ waitUntil { if (_result == 1) then { [_taskID, "FAILED"] call BFUNC(taskSetState); - if (_endFail) then { - ["MissionFail", false] remoteExecCall ["BIS_fnc_endMission", playerSide]; - }; + private _penalties = createHashMap; + _penalties set ["reputation", _ratingFail]; - // ["deduct", _ratingFail] remoteExecCall ["forge_server_rating_fnc_handleRating", 2]; - [_ratingFail] call EFUNC(org,addReputation); + [_taskID, _penalties] call FUNC(handleTaskRewards); + + sleep 1; + + { [_x, _ratingFail] remoteExec ["addRating", -2] } forEach allPlayers; [format ["Task failed: %1 reputation", _ratingFail], "warning", 5, "right"] call EFUNC(misc,notify); + if (_endFail) then { ["MissionFail", false] remoteExecCall ["BIS_fnc_endMission", playerSide]; }; } else { - [_taskID, "SUCCEEDED"] call BFUNC(taskSetState); + private _rewards = createHashMap; + _rewards set ["funds", _companyFunds]; + _rewards set ["reputation", _ratingSuccess]; - if (_endSuccess) then { - ["MissionSuccess", false] remoteExecCall ["BIS_fnc_endMission", playerSide]; - }; - - // ["advance", _ratingSuccess] remoteExecCall ["forge_server_rating_fnc_handleRating", 2]; - [_ratingSuccess] call EFUNC(org,addReputation); - [format ["Task succeeded: %1 reputation", _ratingSuccess], "success", 5, "right"] call EFUNC(misc,notify); + if (count _equipmentRewards > 0) then { _rewards set ["equipment", _equipmentRewards]; }; + if (count _supplyRewards > 0) then { _rewards set ["supplies", _supplyRewards]; }; + if (count _weaponRewards > 0) then { _rewards set ["weapons", _weaponRewards]; }; + if (count _vehicleRewards > 0) then { _rewards set ["vehicles", _vehicleRewards]; }; + if (count _specialRewards > 0) then { _rewards set ["special", _specialRewards]; }; + + [_taskID, _rewards] call FUNC(handleTaskRewards); + [_taskID, "SUCCEEDED"] call BIS_fnc_taskSetState; sleep 1; { [_x, _ratingSuccess] remoteExec ["addRating", -2] } forEach allPlayers; - // ["advance", _companyFunds] remoteExecCall ["forge_server_money_fnc_handleFunds", 2]; - [_companyFunds] call EFUNC(org,addFunds); - [format ["Task succeeded: %1 funds", _companyFunds], "success", 5, "right"] call EFUNC(misc,notify); + [format ["Task completed: %1 reputation", _ratingSuccess], "success", 5, "right"] call EFUNC(misc,notify); + [format ["Task completed: %1 funds", _companyFunds], "success", 5, "right"] call EFUNC(misc,notify); + + if (_endSuccess) then { ["MissionSuccess", true] remoteExecCall ["BIS_fnc_endMission", playerSide]; }; }; \ No newline at end of file diff --git a/addons/task/functions/fnc_defuse.sqf b/addons/task/functions/fnc_defuse.sqf index 40b2233..f4c29e7 100644 --- a/addons/task/functions/fnc_defuse.sqf +++ b/addons/task/functions/fnc_defuse.sqf @@ -13,6 +13,11 @@ * 5: Amount of rating the company and player recieve if the task is successful (default: 0) * 6: Should the mission end (MissionSuccess) if the task is successful (default: false) * 7: Should the mission end (MissionFailed) if the task is failed (default: false) + * 8: Equipment rewards (default: []) + * 9: Supply rewards (default: []) + * 10: Weapon rewards (default: []) + * 11: Vehicle rewards (default: []) + * 12: Special rewards (default: []) * * Return Value: * None @@ -23,7 +28,21 @@ * Public: Yes */ -params [["_taskID", ""], ["_limitFail", -1], ["_limitSuccess", -1], ["_companyFunds", 0], ["_ratingFail", 0], ["_ratingSuccess", 0], ["_endSuccess", false], ["_endFail", false]]; +params [ + ["_taskID", "", [""]], + ["_limitFail", -1, [0]], + ["_limitSuccess", -1, [0]], + ["_companyFunds", 0, [0]], + ["_ratingFail", 0, [0]], + ["_ratingSuccess", 0, [0]], + ["_endSuccess", false, [false]], + ["_endFail", false, [false]], + ["_equipmentRewards", [], [[]]], + ["_supplyRewards", [], [[]]], + ["_weaponRewards", [], [[]]], + ["_vehicleRewards", [], [[]]], + ["_specialRewards", [], [[]]] +]; private _result = 0; @@ -58,38 +77,42 @@ if (_result == 1) then { [_taskID, "FAILED"] call BFUNC(taskSetState); - if (_endFail) then { - ["MissionFail", false] remoteExecCall ["BIS_fnc_endMission", playerSide]; - }; + private _penalties = createHashMap; + _penalties set ["reputation", _ratingFail]; - // ["deduct", _ratingFail] remoteExecCall ["forge_server_rating_fnc_handleRating", 2]; - [_ratingFail] call EFUNC(org,addReputation); - [format ["Task failed: %1 reputation", _ratingFail], "warning", 5, "right"] call EFUNC(misc,notify); + [_taskID, _penalties] call FUNC(handleTaskRewards); - sleep 1; + sleep 1; + + { [_x, _ratingFail] remoteExec ["addRating", -2] } forEach allPlayers; + [format ["Task failed: %1 reputation", _ratingFail], "warning", 5, "right"] call EFUNC(misc,notify); - { [_x, _ratingFail] remoteExec ["addRating", -2] } forEach allPlayers; + if (_endFail) then { ["MissionFail", false] remoteExecCall ["BIS_fnc_endMission", playerSide]; }; } else { { deleteVehicle _x } forEach _ieds; { deleteVehicle _x } forEach _entities; - [_taskID, "SUCCEEDED"] call BFUNC(taskSetState); + private _rewards = createHashMap; + _rewards set ["funds", _companyFunds]; + _rewards set ["reputation", _ratingSuccess]; - if (_endSuccess) then { - ["MissionSuccess", true] remoteExecCall ["BIS_fnc_endMission", playerSide]; - }; + if (count _equipmentRewards > 0) then { _rewards set ["equipment", _equipmentRewards]; }; + if (count _supplyRewards > 0) then { _rewards set ["supplies", _supplyRewards]; }; + if (count _weaponRewards > 0) then { _rewards set ["weapons", _weaponRewards]; }; + if (count _vehicleRewards > 0) then { _rewards set ["vehicles", _vehicleRewards]; }; + if (count _specialRewards > 0) then { _rewards set ["special", _specialRewards]; }; + + [_taskID, _rewards] call FUNC(handleTaskRewards); + [_taskID, "SUCCEEDED"] call BIS_fnc_taskSetState; - // ["advance", _ratingSuccess] remoteExecCall ["forge_server_rating_fnc_handleRating", 2]; - [_ratingSuccess] call EFUNC(org,addReputation); - [format ["Task completed: %1 reputation", _ratingSuccess], "success", 5, "right"] call EFUNC(misc,notify); + sleep 1; - sleep 1; + { [_x, _ratingSuccess] remoteExec ["addRating", -2] } forEach allPlayers; - { [_x, _ratingSuccess] remoteExec ["addRating", -2] } forEach allPlayers; - - // ["advance", _companyFunds] remoteExecCall ["forge_server_money_fnc_handleFunds", 2]; - [_companyFunds] call EFUNC(org,addFunds); + [format ["Task completed: %1 reputation", _ratingSuccess], "success", 5, "right"] call EFUNC(misc,notify); [format ["Task completed: %1 funds", _companyFunds], "success", 5, "right"] call EFUNC(misc,notify); + + if (_endSuccess) then { ["MissionSuccess", true] remoteExecCall ["BIS_fnc_endMission", playerSide]; }; }; GVAR(defusedCount) = 0; \ No newline at end of file diff --git a/addons/task/functions/fnc_delivery.sqf b/addons/task/functions/fnc_delivery.sqf index 91a122a..a2a969a 100644 --- a/addons/task/functions/fnc_delivery.sqf +++ b/addons/task/functions/fnc_delivery.sqf @@ -14,7 +14,12 @@ * 6: Amount of rating the company and player receive if the task is successful (default: 0) * 7: Should the mission end (MissionSuccess) if the task is successful (default: false) * 8: Should the mission end (MissionFailed) if the task is failed (default: false) - * 9: Amount of time to complete delivery (default: nil) + * 9: Amount of time to complete delivery (default: -1) + * 10: Equipment rewards (default: []) + * 11: Supply rewards (default: []) + * 12: Weapon rewards (default: []) + * 13: Vehicle rewards (default: []) + * 14: Special rewards (default: []) * * Return Value: * None @@ -26,7 +31,23 @@ * Public: Yes */ -params [["_taskID", "", [""]], ["_limitFail", -1, [0]], ["_limitSuccess", -1, [0]], ["_deliveryZone", "", [""]], ["_companyFunds", 0, [0]], ["_ratingFail", 0, [0]], ["_ratingSuccess", 0, [0]], ["_endSuccess", false, [false]], ["_endFail", false, [false]], ["_time", nil, [0]]]; +params [ + ["_taskID", "", [""]], + ["_limitFail", -1, [0]], + ["_limitSuccess", -1, [0]], + ["_deliveryZone", "", [""]], + ["_companyFunds", 0, [0]], + ["_ratingFail", 0, [0]], + ["_ratingSuccess", 0, [0]], + ["_endSuccess", false, [false]], + ["_endFail", false, [false]], + ["_time", -1, [0]], + ["_equipmentRewards", [], [[]]], + ["_supplyRewards", [], [[]]], + ["_weaponRewards", [], [[]]], + ["_vehicleRewards", [], [[]]], + ["_specialRewards", [], [[]]] +]; private _result = 0; @@ -37,7 +58,7 @@ waitUntil { }; private _cargo = GVAR(allCargo) select { (_x getVariable ["assignedTask", ""]) == _taskID }; -private _startTime = if (!isNil "_time") then { floor(time) } else { nil }; +private _startTime = if (_time isNotEqualTo -1) then { floor(time) } else { nil }; waitUntil { sleep 1; @@ -45,7 +66,7 @@ waitUntil { private _cargoDelivered = ({ _x inArea _deliveryZone && (damage _x) < 0.7 } count _cargo); private _cargoDamaged = ({ damage _x >= 0.7 } count _cargo); - if (!isNil "_time") then { + if (_time isNotEqualTo -1) then { private _timeExpired = (floor time - _startTime >= _time); if (_cargoDamaged >= _limitFail) then { _result = 1; }; @@ -62,37 +83,39 @@ waitUntil { if (_result == 1) then { { deleteVehicle _x } forEach _cargo; - [_taskID, "FAILED"] call BFUNC(taskSetState); + private _penalties = createHashMap; + _penalties set ["reputation", _ratingFail]; - if (_endFail) then { - ["MissionFail", false] remoteExecCall ["BIS_fnc_endMission", playerSide]; - }; - - // ["deduct", _ratingFail] remoteExecCall ["forge_server_rating_fnc_handleRating", 2]; - [_ratingFail] call EFUNC(org,addReputation); - [format ["Task failed: %1 reputation", _ratingFail], "warning", 5, "right"] call EFUNC(misc,notify); + [_taskID, _penalties] call FUNC(handleTaskRewards); sleep 1; - + { [_x, _ratingFail] remoteExec ["addRating", -2] } forEach allPlayers; + [format ["Task failed: %1 reputation", _ratingFail], "warning", 5, "right"] call EFUNC(misc,notify); + + if (_endFail) then { ["MissionFail", false] remoteExecCall ["BIS_fnc_endMission", playerSide]; }; } else { { deleteVehicle _x } forEach _cargo; - [_taskID, "SUCCEEDED"] call BFUNC(taskSetState); + private _rewards = createHashMap; + _rewards set ["funds", _companyFunds]; + _rewards set ["reputation", _ratingSuccess]; - if (_endSuccess) then { - ["MissionSuccess", false] remoteExecCall ["BIS_fnc_endMission", playerSide]; - }; - - // ["advance", _ratingSuccess] remoteExecCall ["forge_server_rating_fnc_handleRating", 2]; - [_ratingSuccess] call EFUNC(org,addReputation); - [format ["Task succeeded: %1 reputation", _ratingSuccess], "success", 5, "right"] call EFUNC(misc,notify); + if (count _equipmentRewards > 0) then { _rewards set ["equipment", _equipmentRewards]; }; + if (count _supplyRewards > 0) then { _rewards set ["supplies", _supplyRewards]; }; + if (count _weaponRewards > 0) then { _rewards set ["weapons", _weaponRewards]; }; + if (count _vehicleRewards > 0) then { _rewards set ["vehicles", _vehicleRewards]; }; + if (count _specialRewards > 0) then { _rewards set ["special", _specialRewards]; }; + + [_taskID, _rewards] call FUNC(handleTaskRewards); + [_taskID, "SUCCEEDED"] call BIS_fnc_taskSetState; sleep 1; { [_x, _ratingSuccess] remoteExec ["addRating", -2] } forEach allPlayers; - // ["advance", _companyFunds] remoteExecCall ["forge_server_money_fnc_handleFunds", 2]; - [_companyFunds] call EFUNC(org,addFunds); - [format ["Task succeeded: %1 funds", _companyFunds], "success", 5, "right"] call EFUNC(misc,notify); + [format ["Task completed: %1 reputation", _ratingSuccess], "success", 5, "right"] call EFUNC(misc,notify); + [format ["Task completed: %1 funds", _companyFunds], "success", 5, "right"] call EFUNC(misc,notify); + + if (_endSuccess) then { ["MissionSuccess", true] remoteExecCall ["BIS_fnc_endMission", playerSide]; }; }; \ No newline at end of file diff --git a/addons/task/functions/fnc_destroy.sqf b/addons/task/functions/fnc_destroy.sqf index 530ca23..7b18c0b 100644 --- a/addons/task/functions/fnc_destroy.sqf +++ b/addons/task/functions/fnc_destroy.sqf @@ -13,7 +13,12 @@ * 5: Amount of rating the company and player recieve if the task is successful (default: 0) * 6: Should the mission end (MissionSuccess) if the task is successful (default: false) * 7: Should the mission end (MissionFailed) if the task is failed (default: false) - * 8: Amount of time before target(s) escape (default: nil) + * 8: Amount of time before target(s) escape (default: -1) + * 9: Equipment rewards (default: []) + * 10: Supply rewards (default: []) + * 11: Weapon rewards (default: []) + * 12: Vehicle rewards (default: []) + * 13: Special rewards (default: []) * * Return Value: * None @@ -25,7 +30,22 @@ * Public: Yes */ -params [["_taskID", ""], ["_limitFail", -1], ["_limitSuccess", -1], ["_companyFunds", 0], ["_ratingFail", 0], ["_ratingSuccess", 0], ["_endSuccess", false], ["_endFail", false], "_time"]; +params [ + ["_taskID", "", [""]], + ["_limitFail", -1, [0]], + ["_limitSuccess", -1, [0]], + ["_companyFunds", 0, [0]], + ["_ratingFail", 0, [0]], + ["_ratingSuccess", 0, [0]], + ["_endSuccess", false, [false]], + ["_endFail", false, [false]], + ["_time", -1, [0]], + ["_equipmentRewards", [], [[]]], + ["_supplyRewards", [], [[]]], + ["_weaponRewards", [], [[]]], + ["_vehicleRewards", [], [[]]], + ["_specialRewards", [], [[]]] +]; private _result = 0; @@ -57,37 +77,39 @@ waitUntil { if (_result == 1) then { { deleteVehicle _x } forEach _targets; - [_taskID, "FAILED"] call BFUNC(taskSetState); + private _penalties = createHashMap; + _penalties set ["reputation", _ratingFail]; - if (_endFail) then { - ["MissionFail", false] remoteExecCall ["BIS_fnc_endMission", playerSide]; - }; + [_taskID, _penalties] call FUNC(handleTaskRewards); - // ["deduct", _ratingFail] remoteExecCall ["forge_server_rating_fnc_handleRating", 2]; - [_ratingFail] call EFUNC(org,addReputation); - [format ["Task failed: %1 reputation", _ratingFail], "warning", 5, "right"] call EFUNC(misc,notify); + sleep 1; + + { [_x, _ratingFail] remoteExec ["addRating", -2] } forEach allPlayers; + [format ["Task failed: %1 reputation", _ratingFail], "warning", 5, "right"] call EFUNC(misc,notify); - sleep 1; - - { [_x, _ratingFail] remoteExec ["addRating", -2] } forEach allPlayers; + if (_endFail) then { ["MissionFail", false] remoteExecCall ["BIS_fnc_endMission", playerSide]; }; } else { { deleteVehicle _x } forEach _targets; - [_taskID, "SUCCEEDED"] call BFUNC(taskSetState); + private _rewards = createHashMap; + _rewards set ["funds", _companyFunds]; + _rewards set ["reputation", _ratingSuccess]; - if (_endSuccess) then { - ["MissionSuccess", true] remoteExecCall ["BIS_fnc_endMission", playerSide]; - }; + if (count _equipmentRewards > 0) then { _rewards set ["equipment", _equipmentRewards]; }; + if (count _supplyRewards > 0) then { _rewards set ["supplies", _supplyRewards]; }; + if (count _weaponRewards > 0) then { _rewards set ["weapons", _weaponRewards]; }; + if (count _vehicleRewards > 0) then { _rewards set ["vehicles", _vehicleRewards]; }; + if (count _specialRewards > 0) then { _rewards set ["special", _specialRewards]; }; + + [_taskID, _rewards] call FUNC(handleTaskRewards); + [_taskID, "SUCCEEDED"] call BIS_fnc_taskSetState; - // ["advance", _ratingSuccess] remoteExecCall ["forge_server_rating_fnc_handleRating", 2]; - [_ratingSuccess] call EFUNC(org,addReputation); - [format ["Task completed: %1 reputation", _ratingSuccess], "success", 5, "right"] call EFUNC(misc,notify); + sleep 1; - sleep 1; + { [_x, _ratingSuccess] remoteExec ["addRating", -2] } forEach allPlayers; - { [_x, _ratingSuccess] remoteExec ["addRating", -2] } forEach allPlayers; - - // ["advance", _companyFunds] remoteExecCall ["forge_server_money_fnc_handleFunds", 2]; - [_companyFunds] call EFUNC(org,addFunds); + [format ["Task completed: %1 reputation", _ratingSuccess], "success", 5, "right"] call EFUNC(misc,notify); [format ["Task completed: %1 funds", _companyFunds], "success", 5, "right"] call EFUNC(misc,notify); + + if (_endSuccess) then { ["MissionSuccess", true] remoteExecCall ["BIS_fnc_endMission", playerSide]; }; }; \ No newline at end of file diff --git a/addons/task/functions/fnc_handleTaskRewards.sqf b/addons/task/functions/fnc_handleTaskRewards.sqf new file mode 100644 index 0000000..bc9b314 --- /dev/null +++ b/addons/task/functions/fnc_handleTaskRewards.sqf @@ -0,0 +1,118 @@ +#include "..\script_component.hpp" + +/* + * Author: IDSolutions + * Handles task completion rewards for organizations + * + * Arguments: + * 0: Task ID + * 1: Reward Data + * - funds: Amount of money to award + * - reputation: Amount of reputation to award + * - equipment: Array of equipment classnames to award + * - supplies: Array of supply classnames to award + * - weapons: Array of weapon classnames to award + * - vehicles: Array of vehicle classnames to award + * - special: Array of special item classnames to award + * + * Return Value: + * Success + * + * Example: + * private _rewards = createHashMapFromArray [ + * ["funds", 10000], + * ["reputation", 50], + * ["equipment", ["ItemGPS", "ItemCompass"]], + * ["supplies", ["FirstAidKit", "Medikit"]], + * ["weapons", ["arifle_MX_F"]], + * ["vehicles", ["B_MRAP_01_F"]], + * ["special", ["B_UAV_01_F"]] + * ]; + * ["task_1", _rewards] call forge_client_task_fnc_handleTaskRewards; + * + * Public: No + */ + +params [["_taskID", ""], ["_rewards", createHashMap]]; + +if (_taskID == "") exitWith { + diag_log "ERROR: No task ID provided for rewards"; + false +}; + +private _store = call EFUNC(org,verifyOrgStore); +if (isNil "_store") exitWith { + ["No organization found to receive rewards", "error", 5, "right"] call EFUNC(misc,notify); + false +}; + +private _success = true; +private _funds = _rewards getOrDefault ["funds", 0]; +if (_funds > 0) then { + if !([_funds] call EFUNC(org,addFunds)) then { + diag_log format ["Failed to award funds %1 for task %2", _funds, _taskID]; + _success = false; + }; +}; + +private _reputation = _rewards getOrDefault ["reputation", 0]; +if (_reputation > 0) then { + if !([_reputation] call EFUNC(org,addReputation)) then { + diag_log format ["Failed to award reputation %1 for task %2", _reputation, _taskID]; + _success = false; + }; +}; + +private _fnc_addAssets = { + params ["_type", "_items"]; + { + private _properties = createHashMap; + _properties set ["source", format ["Task Reward: %1", _taskID]]; + _properties set ["acquired", call EFUNC(misc,getSystemTime)]; + + if !([_type, _x, _properties] call EFUNC(org,addAsset)) then { + diag_log format ["Failed to award %1 asset %2 for task %3", _type, _x, _taskID]; + _success = false; + }; + } forEach _items; +}; + +private _equipment = _rewards getOrDefault ["equipment", []]; +if (count _equipment > 0) then { + ["equipment", _equipment] call _fnc_addAssets; +}; + +private _supplies = _rewards getOrDefault ["supplies", []]; +if (count _supplies > 0) then { + ["supply", _supplies] call _fnc_addAssets; +}; + +private _weapons = _rewards getOrDefault ["weapons", []]; +if (count _weapons > 0) then { + ["weapon", _weapons] call _fnc_addAssets; +}; + +private _vehicles = _rewards getOrDefault ["vehicles", []]; +if (count _vehicles > 0) then { + ["vehicle", _vehicles] call _fnc_addAssets; +}; + +private _special = _rewards getOrDefault ["special", []]; +if (count _special > 0) then { + ["special", _special] call _fnc_addAssets; +}; + +if (_success) then { + private _rewardText = "Task Rewards:"; + if (_funds > 0) then { _rewardText = _rewardText + format ["\n- $%1", _funds call EFUNC(misc,formatNumber)]; }; + if (_reputation > 0) then { _rewardText = _rewardText + format ["\n- %1 Reputation", _reputation]; }; + if (count _equipment > 0) then { _rewardText = _rewardText + format ["\n- %1 Equipment Items", count _equipment]; }; + if (count _supplies > 0) then { _rewardText = _rewardText + format ["\n- %1 Supply Items", count _supplies]; }; + if (count _weapons > 0) then { _rewardText = _rewardText + format ["\n- %1 Weapons", count _weapons]; }; + if (count _vehicles > 0) then { _rewardText = _rewardText + format ["\n- %1 Vehicles", count _vehicles]; }; + if (count _special > 0) then { _rewardText = _rewardText + format ["\n- %1 Special Items", count _special]; }; + + [_rewardText, "success", 10, "right"] call EFUNC(misc,notify); +}; + +_success \ No newline at end of file diff --git a/addons/task/functions/fnc_hostage.sqf b/addons/task/functions/fnc_hostage.sqf index feadd78..da68aff 100644 --- a/addons/task/functions/fnc_hostage.sqf +++ b/addons/task/functions/fnc_hostage.sqf @@ -15,8 +15,13 @@ * 7: Subcategory of task (default: [false, true]) * 8: Should the mission end (MissionSuccess) if the task is successful (default: false) * 9: Should the mission end (MissionFailed) if the task is failed (default: false) - * 10: Amount of time before hostage(s) die (default: nil) - * 11: Marker name for the cbrn zone (default: nil) + * 10: Amount of time before hostage(s) die (default: -1) + * 11: Marker name for the cbrn zone (default: "") + * 12: Equipment rewards (default: []) + * 13: Supply rewards (default: []) + * 14: Weapon rewards (default: []) + * 15: Vehicle rewards (default: []) + * 16: Special rewards (default: []) * * Return Value: * None @@ -29,7 +34,25 @@ * Public: Yes */ -params [["_taskID", ""], ["_limitFail", -1], ["_limitSuccess", -1], ["_extZone", ""], ["_companyFunds", 0], ["_ratingFail", 0], ["_ratingSuccess", 0], ["_type", [["_cbrn", false], ["_hostage", true]]], ["_endSuccess", false], ["_endFail", false], "_time", ["_cbrnZone", ""]]; +params [ + ["_taskID", ""], + ["_limitFail", -1], + ["_limitSuccess", -1], + ["_extZone", ""], + ["_companyFunds", 0], + ["_ratingFail", 0], + ["_ratingSuccess", 0], + ["_type", [["_cbrn", false, [false]], ["_hostage", true, [false]]]], + ["_endSuccess", false, [false]], + ["_endFail", false, [false]], + ["_time", -1, [0]], + ["_cbrnZone", "", [""]] + ["_equipmentRewards", [], [[]]], + ["_supplyRewards", [], [[]]], + ["_weaponRewards", [], [[]]], + ["_vehicleRewards", [], [[]]], + ["_specialRewards", [], [[]]] +]; private _cbrn = (_this select 7) select 0; private _hostage = (_this select 7) select 1; @@ -49,7 +72,7 @@ waitUntil { private _hostages = GVAR(allHostages) select { (_x getVariable ["assignedTask", ""]) == _taskID }; private _shooters = GVAR(allShooters) select { (_x getVariable ["assignedTask", ""]) == _taskID }; -private _startTime = if (!isNil "_time") then { floor(time) } else { nil }; +private _startTime = if (_time isNotEqualTo -1) then { floor(time) } else { nil }; waitUntil { sleep 1; @@ -59,7 +82,7 @@ waitUntil { private _hostagesKilled = ({ !alive _x } count _hostages); private _shootersAlive = ({ alive _x } count _shooters); - if (!isNil "_time") then { + if (_time isNotEqualTo -1) then { private _timeExpired = (floor time - _startTime >= _time); if (_hostagesFreed < _limitSuccess && _timeExpired) then { _result = 1; }; @@ -111,38 +134,40 @@ if (_result == 1) then { { deleteVehicle _x } forEach _hostages; { deleteVehicle _x } forEach _shooters; - [_taskID, "FAILED"] call BFUNC(taskSetState); + private _penalties = createHashMap; + _penalties set ["reputation", _ratingFail]; - if (_endFail) then { - ["MissionFail", false] remoteExecCall ["BIS_fnc_endMission", playerSide]; - }; + [_taskID, _penalties] call FUNC(handleTaskRewards); - // ["deduct", _ratingFail] remoteExecCall ["forge_server_rating_fnc_handleRating", 2]; - [_ratingFail] call EFUNC(org,addReputation); - [format ["Task failed: %1 reputation", _ratingFail], "warning", 5, "right"] call EFUNC(misc,notify); + sleep 1; + + { [_x, _ratingFail] remoteExec ["addRating", -2] } forEach allPlayers; + [format ["Task failed: %1 reputation", _ratingFail], "warning", 5, "right"] call EFUNC(misc,notify); - sleep 1; - - { [_x, _ratingFail] remoteExec ["addRating", -2] } forEach allPlayers; + if (_endFail) then { ["MissionFail", false] remoteExecCall ["BIS_fnc_endMission", playerSide]; }; } else { { deleteVehicle _x } forEach _hostages; { deleteVehicle _x } forEach _shooters; - [_taskID, "SUCCEEDED"] call BFUNC(taskSetState); + private _rewards = createHashMap; + _rewards set ["funds", _companyFunds]; + _rewards set ["reputation", _ratingSuccess]; - if (_endSuccess) then { - ["MissionSuccess", true] remoteExecCall ["BIS_fnc_endMission", playerSide]; - }; + if (count _equipmentRewards > 0) then { _rewards set ["equipment", _equipmentRewards]; }; + if (count _supplyRewards > 0) then { _rewards set ["supplies", _supplyRewards]; }; + if (count _weaponRewards > 0) then { _rewards set ["weapons", _weaponRewards]; }; + if (count _vehicleRewards > 0) then { _rewards set ["vehicles", _vehicleRewards]; }; + if (count _specialRewards > 0) then { _rewards set ["special", _specialRewards]; }; + + [_taskID, _rewards] call FUNC(handleTaskRewards); + [_taskID, "SUCCEEDED"] call BIS_fnc_taskSetState; - // ["advance", _ratingSuccess] remoteExecCall ["forge_server_rating_fnc_handleRating", 2]; - [_ratingSuccess] call EFUNC(org,addReputation); - [format ["Task completed: %1 reputation", _ratingSuccess], "success", 5, "right"] call EFUNC(misc,notify); + sleep 1; - sleep 1; + { [_x, _ratingSuccess] remoteExec ["addRating", -2] } forEach allPlayers; - { [_x, _ratingSuccess] remoteExec ["addRating", -2] } forEach allPlayers; - - // ["advance", _companyFunds] remoteExecCall ["forge_server_money_fnc_handleFunds", 2]; - [_companyFunds] call EFUNC(org,addFunds); + [format ["Task completed: %1 reputation", _ratingSuccess], "success", 5, "right"] call EFUNC(misc,notify); [format ["Task completed: %1 funds", _companyFunds], "success", 5, "right"] call EFUNC(misc,notify); + + if (_endSuccess) then { ["MissionSuccess", true] remoteExecCall ["BIS_fnc_endMission", playerSide]; }; }; \ No newline at end of file diff --git a/addons/task/functions/fnc_hvt.sqf b/addons/task/functions/fnc_hvt.sqf index 101ce29..314c641 100644 --- a/addons/task/functions/fnc_hvt.sqf +++ b/addons/task/functions/fnc_hvt.sqf @@ -15,7 +15,12 @@ * 7: Subcategory of task (default: [true, false]) * 8: Should the mission end (MissionSuccess) if the task is successful (default: false) * 9: Should the mission end (MissionFailed) if the task is failed (default: false) - * 10: Amount of time before hvt(s) die (default: nil) + * 10: Amount of time before hvt(s) die (default: -1) + * 11: Equipment rewards (default: []) + * 12: Supply rewards (default: []) + * 13: Weapon rewards (default: []) + * 14: Vehicle rewards (default: []) + * 15: Special rewards (default: []) * * Return Value: * None @@ -29,7 +34,24 @@ * Public: Yes */ -params [["_taskID", ""], ["_limitFail", -1], ["_limitSuccess", -1], ["_extZone", ""], ["_companyFunds", 0], ["_ratingFail", 0], ["_ratingSuccess", 0], ["_type", [["_capture", true], ["_eliminate", false]]], ["_endSuccess", false], ["_endFail", false], "_time"]; +params [ + ["_taskID", "", [""]], + ["_limitFail", -1, [0]], + ["_limitSuccess", -1, [0]], + ["_extZone", "", [""]], + ["_companyFunds", 0, [0]], + ["_ratingFail", 0, [0]], + ["_ratingSuccess", 0, [0]], + ["_type", [["_capture", true, [false]], ["_eliminate", false, [false]]]], + ["_endSuccess", false, [false]], + ["_endFail", false, [false]], + ["_time", -1, [0]], + ["_equipmentRewards", [], [[]]], + ["_supplyRewards", [], [[]]], + ["_weaponRewards", [], [[]]], + ["_vehicleRewards", [], [[]]], + ["_specialRewards", [], [[]]] +]; private _capture = (_this select 7) select 0; private _eliminate = (_this select 7) select 1; @@ -69,37 +91,39 @@ waitUntil { if (_result == 1) then { { deleteVehicle _x } forEach _hvts; - [_taskID, "FAILED"] call BFUNC(taskSetState); + private _penalties = createHashMap; + _penalties set ["reputation", _ratingFail]; - if (_endFail) then { - ["MissionFail", false] remoteExecCall ["BIS_fnc_endMission", playerSide]; - }; + [_taskID, _penalties] call FUNC(handleTaskRewards); - // ["deduct", _ratingFail] remoteExecCall ["forge_server_rating_fnc_handleRating", 2]; - [_ratingFail] call EFUNC(org,addReputation); - [format ["Task failed: %1 reputation", _ratingFail], "warning", 5, "right"] call EFUNC(misc,notify); + sleep 1; + + { [_x, _ratingFail] remoteExec ["addRating", -2] } forEach allPlayers; + [format ["Task failed: %1 reputation", _ratingFail], "warning", 5, "right"] call EFUNC(misc,notify); - sleep 1; - - { [_x, _ratingFail] remoteExec ["addRating", -2] } forEach allPlayers; + if (_endFail) then { ["MissionFail", false] remoteExecCall ["BIS_fnc_endMission", playerSide]; }; } else { { deleteVehicle _x } forEach _hvts; - [_taskID, "SUCCEEDED"] call BFUNC(taskSetState); + private _rewards = createHashMap; + _rewards set ["funds", _companyFunds]; + _rewards set ["reputation", _ratingSuccess]; - if (_endSuccess) then { - ["MissionSuccess", true] remoteExecCall ["BIS_fnc_endMission", playerSide]; - }; + if (count _equipmentRewards > 0) then { _rewards set ["equipment", _equipmentRewards]; }; + if (count _supplyRewards > 0) then { _rewards set ["supplies", _supplyRewards]; }; + if (count _weaponRewards > 0) then { _rewards set ["weapons", _weaponRewards]; }; + if (count _vehicleRewards > 0) then { _rewards set ["vehicles", _vehicleRewards]; }; + if (count _specialRewards > 0) then { _rewards set ["special", _specialRewards]; }; + + [_taskID, _rewards] call FUNC(handleTaskRewards); + [_taskID, "SUCCEEDED"] call BIS_fnc_taskSetState; - // ["advance", _ratingSuccess] remoteExecCall ["forge_server_rating_fnc_handleRating", 2]; - [_ratingSuccess] call EFUNC(org,addReputation); - [format ["Task succeeded: %1 reputation", _ratingSuccess], "success", 5, "right"] call EFUNC(misc,notify); + sleep 1; - sleep 1; + { [_x, _ratingSuccess] remoteExec ["addRating", -2] } forEach allPlayers; - { [_x, _ratingSuccess] remoteExec ["addRating", -2] } forEach allPlayers; - - // ["advance", _companyFunds] remoteExecCall ["forge_server_money_fnc_handleFunds", 2]; - [_companyFunds] call EFUNC(org,addFunds); - [format ["Task succeeded: %1 funds", _companyFunds], "success", 5, "right"] call EFUNC(misc,notify); + [format ["Task completed: %1 reputation", _ratingSuccess], "success", 5, "right"] call EFUNC(misc,notify); + [format ["Task completed: %1 funds", _companyFunds], "success", 5, "right"] call EFUNC(misc,notify); + + if (_endSuccess) then { ["MissionSuccess", true] remoteExecCall ["BIS_fnc_endMission", playerSide]; }; }; \ No newline at end of file