feat: Implement timesheet submission and rating system in bank addon
All checks were successful
Build / Build (push) Successful in 25s

This commit introduces the ability for players to submit timesheets and receive payment based on their rating. It also includes updates to player data handling to incorporate the new rating system.

Key changes include:

- Added `getPlayer` PREP.
- Implemented `BANK::SUBMIT::TIMESHEET` case in `XEH_preInit_server.sqf` to handle timesheet submissions.
- Modified `fnc_initBankStore.sqf` to include rating in player data and update account information.
- Added `submitTimesheet` function to `fnc_initBankStore.sqf` to process timesheet submissions and pay players based on rating.
- Updated `handlePlayerLoad` and `updateAccount` functions in `fnc_initBankStore.sqf` to include rating.
- Added `getRating` function to `fnc_initBankStore.sqf` to retrieve player rating.
- Updated `BANK::HANDLE::PLAYER::LOAD` case in `XEH_preInit_server.sqf` to include rating value.
- Added database saving for reputation.

These changes introduce a new gameplay mechanic and provide a way for players to earn money based on their performance.
This commit is contained in:
Jacob Schmidt 2025-05-11 01:19:58 -05:00
parent fb7c198e56
commit 461a678f8b
4 changed files with 106 additions and 21 deletions

View File

@ -13,15 +13,23 @@ call FUNC(initBankStore);
private _bankStore = call FUNC(verifyBankStore); private _bankStore = call FUNC(verifyBankStore);
_data params [["_uid", "", [""]], ["_amount", 0, [0]]]; _data params [["_uid", "", [""]], ["_amount", 0, [0]]];
if (_uid isEqualTo "" || _amount isEqualTo 0) exitWith { diag_log "[FORGE::Server::Bank::XEH_preInit::handleDeposit] Invalid UID and amount!"; }; if (_uid isEqualTo "" || _amount isEqualTo 0) exitWith { diag_log "[FORGE::Server::Bank::XEH_preInit::handleDeposit] Invalid UID and amount, UID cannot be empty and amount must be greater than 0!"; };
_bankStore call ["deposit", [_uid, _amount]]; _bankStore call ["deposit", [_uid, _amount]];
}; };
case "BANK::SUBMIT::TIMESHEET": {
private _bankStore = call FUNC(verifyBankStore);
_data params [["_uid", "", [""]], ["_rating", 0, [0]]];
if (_uid isEqualTo "" || _rating <= 0) exitWith { diag_log "[FORGE::Server::Bank::XEH_preInit::handleSubmitTimesheet] Invalid UID, UID cannot be empty!"; };
_bankStore call ["submitTimesheet", [_uid, _rating]];
};
case "BANK::TRANSFER": { case "BANK::TRANSFER": {
private _bankStore = call FUNC(verifyBankStore); private _bankStore = call FUNC(verifyBankStore);
_data params [["_fromUid", "", [""]], ["_toUid", "", [""]], ["_amount", 0, [0]]]; _data params [["_fromUid", "", [""]], ["_toUid", "", [""]], ["_amount", 0, [0]]];
if (_fromUid isEqualTo "" || _toUid isEqualTo "" || _amount isEqualTo 0) exitWith { diag_log "[FORGE::Server::Bank::XEH_preInit::handleTransfer] Invalid UIDs and amount!"; }; if (_fromUid isEqualTo "" || _toUid isEqualTo "" || _amount isEqualTo 0) exitWith { diag_log "[FORGE::Server::Bank::XEH_preInit::handleTransfer] Invalid UIDs and amount, UID cannot be empty and amount must be greater than 0!"; };
_bankStore call ["transfer", [_fromUid, _toUid, _amount]]; _bankStore call ["transfer", [_fromUid, _toUid, _amount]];
}; };
@ -51,11 +59,11 @@ call FUNC(initBankStore);
}; };
case "BANK::HANDLE::PLAYER::LOAD": { case "BANK::HANDLE::PLAYER::LOAD": {
private _bankStore = call FUNC(verifyBankStore); private _bankStore = call FUNC(verifyBankStore);
_data params [["_uid", "", [""]], ["_bankValue", 0, [0]], ["_cashValue", 0, [0]]]; _data params [["_uid", "", [""]], ["_bankValue", 0, [0]], ["_cashValue", 0, [0]], ["_ratingValue", 0, [0]]];
if (_uid isEqualTo "") exitWith { diag_log "[FORGE::Server::Bank::XEH_preInit::handlePlayerLoad] Invalid UID, UID cannot be empty!"; }; if (_uid isEqualTo "") exitWith { diag_log "[FORGE::Server::Bank::XEH_preInit::handlePlayerLoad] Invalid UID, UID cannot be empty!"; };
_bankStore call ["handlePlayerLoad", [_uid, _bankValue, _cashValue]]; _bankStore call ["handlePlayerLoad", [_uid, _bankValue, _cashValue, _ratingValue]];
}; };
case "BANK::GET::TRANSACTION::HISTORY": { case "BANK::GET::TRANSACTION::HISTORY": {
private _bankStore = call FUNC(verifyBankStore); private _bankStore = call FUNC(verifyBankStore);

View File

@ -28,36 +28,46 @@ private _bankStore = createHashMapObject [[
true true
}], }],
["handlePlayerLoad", { ["handlePlayerLoad", {
params [["_uid", "", [""]], ["_bankValue", 0, [0]], ["_cashValue", 0, [0]]]; params [["_uid", "", [""]], ["_bankValue", 0, [0]], ["_cashValue", 0, [0]], ["_ratingValue", 0, [0]]];
if (_uid isEqualTo "") exitWith { false }; if (_uid isEqualTo "") exitWith { false };
_self call ["updateAccount", [_uid, _bankValue, _cashValue]]; _self call ["updateAccount", [_uid, _bankValue, _cashValue, _ratingValue]];
diag_log text format ["[FORGE::Server::Bank::Store::handlePlayerLoad] Loaded player data for '%1' - Bank: '%2', Cash: '%3'", _uid, _bankValue, _cashValue]; diag_log text format ["[FORGE::Server::Bank::Store::handlePlayerLoad] Loaded player data for '%1' - Bank: '%2', Cash: '%3', Rating: '%4'", _uid, _bankValue, _cashValue, _ratingValue];
true true
}], }],
["updateAccount", { ["updateAccount", {
params [["_uid", "", [""]], ["_bankValue", 0, [0]], ["_cashValue", 0, [0]], ["_isSave", false, [false]]]; params [["_uid", "", [""]], ["_bankValue", 0, [0]], ["_cashValue", 0, [0]], ["_ratingValue", 0, [0]], ["_isSave", false, [false]]];
if (_uid isEqualTo "") exitWith { false }; if (_uid isEqualTo "") exitWith { false };
private _accounts = _self get "accounts"; private _accounts = _self get "accounts";
private _account = _accounts getOrDefault [_uid, createHashMap]; private _account = _accounts getOrDefault [_uid, createHashMap];
private _player = [_uid] call EFUNC(misc,getPlayer);
_account set ["bank", _bankValue]; _account set ["bank", _bankValue];
_account set ["cash", _cashValue]; _account set ["cash", _cashValue];
_account set ["rating", _ratingValue];
_accounts set [_uid, _account]; _accounts set [_uid, _account];
_self set ["accounts", _accounts]; _self set ["accounts", _accounts];
private _balance = _account getOrDefault ["bank", 0];
private _cash = _account getOrDefault ["cash", 0];
SETPVAR(_player,FORGE_Bank,_balance);
SETPVAR(_player,FORGE_Cash,_cash);
SETPVAR(_player,FORGE_Rating,_ratingValue);
if (_isSave) then { if (_isSave) then {
["hsetid", _uid, "bank", -1, [_bankValue]] call dragonfly_db_fnc_addTask; ["hsetid", _uid, "bank", -1, [_bankValue]] call dragonfly_db_fnc_addTask;
["hsetid", _uid, "cash", -1, [_cashValue]] call dragonfly_db_fnc_addTask; ["hsetid", _uid, "cash", -1, [_cashValue]] call dragonfly_db_fnc_addTask;
["hsetid", _uid, "reputation", -1, [_ratingValue]] call dragonfly_db_fnc_addTask;
}; };
diag_log text format ["[FORGE::Server::Bank::Store::updateAccount] Updated player data for '%1' - Bank: '%2', Cash: '%3'", _uid, _bankValue, _cashValue]; diag_log text format ["[FORGE::Server::Bank::Store::updateAccount] Updated player data for '%1' - Bank: '%2', Cash: '%3', Rating: '%4'", _uid, _bankValue, _cashValue, _ratingValue];
true true
}], }],
@ -81,6 +91,16 @@ private _bankStore = createHashMapObject [[
_account getOrDefault ["cash", 0] _account getOrDefault ["cash", 0]
}], }],
["getRating", {
params [["_uid", "", [""]]];
if (_uid isEqualTo "") exitWith { 0 };
private _accounts = _self get "accounts";
private _account = _accounts getOrDefault [_uid, createHashMap];
_account getOrDefault ["rating", 0]
}],
["deposit", { ["deposit", {
params [["_uid", "", [""]], ["_amount", 0, [0]]]; params [["_uid", "", [""]], ["_amount", 0, [0]]];
@ -90,13 +110,14 @@ private _bankStore = createHashMapObject [[
private _account = _accounts getOrDefault [_uid, createHashMap]; private _account = _accounts getOrDefault [_uid, createHashMap];
private _currentCash = _account getOrDefault ["cash", 0]; private _currentCash = _account getOrDefault ["cash", 0];
private _currentBalance = _account getOrDefault ["bank", 0]; private _currentBalance = _account getOrDefault ["bank", 0];
private _currentRating = _account getOrDefault ["rating", 0];
if (_currentCash < _amount) exitWith { false }; if (_currentCash < _amount) exitWith { false };
private _newBalance = _currentBalance + _amount; private _newBalance = _currentBalance + _amount;
private _newCash = _currentCash - _amount; private _newCash = _currentCash - _amount;
_self call ["updateAccount", [_uid, _newBalance, _newCash, true]]; _self call ["updateAccount", [_uid, _newBalance, _newCash, _currentRating, true]];
private _transactions = _self get "transactions"; private _transactions = _self get "transactions";
@ -105,26 +126,25 @@ private _bankStore = createHashMapObject [[
true true
}], }],
["withdraw", { ["submitTimesheet", {
params [["_uid", "", [""]], ["_amount", 0, [0]]]; params [["_uid", "", [""]], ["_rating", 0, [0]]];
if (_uid isEqualTo "" || _amount <= 0) exitWith { false }; if (_uid isEqualTo "" || _rating <= 0) exitWith { false };
private _accounts = _self get "accounts"; private _accounts = _self get "accounts";
private _account = _accounts getOrDefault [_uid, createHashMap]; private _account = _accounts getOrDefault [_uid, createHashMap];
private _currentBalance = _account getOrDefault ["bank", 0]; private _currentBalance = _account getOrDefault ["bank", 0];
private _currentCash = _account getOrDefault ["cash", 0]; private _currentCash = _account getOrDefault ["cash", 0];
if (_currentBalance < _amount) exitWith { false }; private _payMultiplyer = "MULTIPLYR" call BFUNC(getParamValue);
private _multiplyer = _rating * _payMultiplyer;
private _newBalance = _currentBalance + _multiplyer;
private _newBalance = _currentBalance - _amount; _self call ["updateAccount", [_uid, _newBalance, _currentCash, 0, true]];
private _newCash = _currentCash + _amount;
_self call ["updateAccount", [_uid, _newBalance, _newCash, true]];
private _transactions = _self get "transactions"; private _transactions = _self get "transactions";
_transactions pushBack [_uid, "withdraw", _amount, time]; _transactions pushBack [_uid, "timesheet", _multiplyer, time];
_self set ["transactions", _transactions]; _self set ["transactions", _transactions];
true true
@ -139,11 +159,15 @@ private _bankStore = createHashMapObject [[
private _toAccount = _accounts getOrDefault [_toUid, createHashMap]; private _toAccount = _accounts getOrDefault [_toUid, createHashMap];
private _fromBalance = _fromAccount getOrDefault ["bank", 0]; private _fromBalance = _fromAccount getOrDefault ["bank", 0];
private _toBalance = _toAccount getOrDefault ["bank", 0]; private _toBalance = _toAccount getOrDefault ["bank", 0];
private _fromCash = _fromAccount getOrDefault ["cash", 0];
private _toCash = _toAccount getOrDefault ["cash", 0];
private _fromRating = _fromAccount getOrDefault ["rating", 0];
private _toRating = _toAccount getOrDefault ["rating", 0];
if (_fromBalance < _amount) exitWith { false }; if (_fromBalance < _amount) exitWith { false };
_self call ["updateAccount", [_fromUid, _fromBalance - _amount, 0, true]]; _self call ["updateAccount", [_fromUid, _fromBalance - _amount, _fromCash, _fromRating, true]];
_self call ["updateAccount", [_toUid, _toBalance + _amount, 0, true]]; _self call ["updateAccount", [_toUid, _toBalance + _amount, _toCash, _toRating, true]];
private _transactions = _self get "transactions"; private _transactions = _self get "transactions";
@ -153,6 +177,31 @@ private _bankStore = createHashMapObject [[
true true
}], }],
["withdraw", {
params [["_uid", "", [""]], ["_amount", 0, [0]]];
if (_uid isEqualTo "" || _amount <= 0) exitWith { false };
private _accounts = _self get "accounts";
private _account = _accounts getOrDefault [_uid, createHashMap];
private _currentBalance = _account getOrDefault ["bank", 0];
private _currentCash = _account getOrDefault ["cash", 0];
private _currentRating = _account getOrDefault ["rating", 0];
if (_currentBalance < _amount) exitWith { false };
private _newBalance = _currentBalance - _amount;
private _newCash = _currentCash + _amount;
_self call ["updateAccount", [_uid, _newBalance, _newCash, _currentRating, true]];
private _transactions = _self get "transactions";
_transactions pushBack [_uid, "withdraw", _amount, time];
_self set ["transactions", _transactions];
true
}],
["getTransactionHistory", { ["getTransactionHistory", {
params [["_uid", "", [""]], ["_limit", 10, [0]]]; params [["_uid", "", [""]], ["_limit", 10, [0]]];

View File

@ -1,4 +1,5 @@
PREP(cargoToPairs); PREP(cargoToPairs);
PREP(getPlayer);
PREP(playSound); PREP(playSound);
PREP(playerGroup2Server); PREP(playerGroup2Server);
PREP(redirectClient2Server); PREP(redirectClient2Server);

View File

@ -0,0 +1,27 @@
#include "..\script_component.hpp"
/*
* Author: IDSolutions
* Gets a player object by UID.
*
* Arguments:
* 0: Player UID <STRING>
*
* Return Value:
* Player object or objNull if not found <OBJECT>
*
* Example:
* ["76561198012345678"] call forge_crate_common_fnc_getPlayer
*
* Public: Yes
*/
params ["_uid"];
private _player = objNull;
{
if ((getPlayerUID _x) isEqualTo _uid) exitWith { _player = _x; };
} forEach allPlayers;
_player