client/addons/init/functions/fnc_handlePlayerLoad.sqf
Jacob Schmidt c87deec60b
All checks were successful
Build / Build (push) Successful in 26s
Refactor: Organization Funds, Reputation, Tasks, and Player Saving
This commit refactors how organization funds and reputation are handled, updates task completion logic to use the new organization functions, and modifies player saving to include organization data. Additionally, it introduces string serialization/deserialization and fixes a player save loop.

*   **Organization Funds and Reputation:** Replaces direct server calls for handling funds and reputation with calls to the new organization functions (`EFUNC(org,addFunds)` and `EFUNC(org,addReputation)`). This centralizes fund and reputation management within the organization store.
*   **Task Completion Logic:** Updates task completion functions (`fnc_destroy.sqf`, `fnc_attack.sqf`, `fnc_hostage.sqf`, `fnc_hvt.sqf`, `fnc_defuse.sqf`) to use the new organization functions for adding funds and reputation upon task success or failure. Also adds notifications to inform the player of reputation and fund changes.
*   **Player Saving:** Modifies the player saving function (`fnc_playerDBSave.sqf`) to include the player's organization ID in the saved data.
*   **String Serialization/Deserialization:** Adds `serializeString` and `deserializeString` PREP macros to `XEH_PREP.hpp` and uses them in `fnc_handleOrgLoad.sqf` and `fnc_create.sqf` to handle special characters in organization and member names.
*   **Player Save Loop Fix:** Removes unnecessary brackets from the `call FUNC(playerDBSave)` in `fnc_playerSaveLoop.sqf`.
*   **Organization Purchase Verification:** Adds organization ownership verification to `fnc_handlePurchase.sqf` to ensure only the owner can make purchases using organization funds.
*   **Player Initialization:** Updates `fnc_initPlayer.sqf` to retrieve and set the player's organization upon initialization.
2025-04-05 14:16:24 -05:00

125 lines
4.7 KiB
Plaintext

#include "..\script_component.hpp"
/*
* Function: forge_client_init_fnc_handlePlayerLoad
* Author: Creedcoder, J.Schmidt
* Edit: 07.15.2024
* Copyright © 2024 Creedcoder, J.Schmidt, All rights reserved
*
* Do not edit without permission!
*
* This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivative 4.0 International License.
* To view a copy of this license, vist https://creativecommons.org/licenses/by-nc-nd/4.0/ or send a letter to Creative Commons,
* PO Box 1866, Mountain View, CA 94042
*
* [Description]
* Handle player load from DB.
*
* Arguments:
* 0: Data from key [<ARRAY|STRING|NUMBER|BOOL>] (default: [])
*
* Return Value:
* N/A
*
* Examples:
* [[_data]] call forge_client_init_fnc_handlePlayerLoad (Server or Singleplayer Only)
* [[_data]] remoteExecCall ["forge_client_init_fnc_handlePlayerLoad", 2, false] (Multiplayer Only)
*
* Public: Yes
*/
private _data = _this;
private _defaultEmail = "unknown@spearnet.mil";
private _defaultPhoneNumber = "unknown";
if (_data isEqualTo [""]) then {
2 cutText ["No Save Found!", "PLAIN DOWN", 1];
[player] spawn EFUNC(player,firstLogin);
} else {
[format ["Welcome back %1. Your persistent locker, bank, cash and profile have been loaded.", name player], "blue-grey", 5] call EFUNC(misc,notify);
for "_i" from 0 to (count _data - 1) step 2 do {
private _key = _data select _i;
private _value = _data select (_i + 1);
if (_value isEqualType []) then {
_value = _value select 0;
};
switch (_key) do {
case "reputation": {
SETPVAR(player,Reputation,_value);
player addRating _value;
};
case "loadout": {
SETPVAR(player,Loadout,_value);
player setUnitLoadout _value;
};
case "direction": {
SETPVAR(player,Direction,_value);
player setDir _value;
};
case "cash": {
SETPVAR(player,FORGE_Cash,_value);
};
case "bank": {
SETPVAR(player,FORGE_Bank,_value);
};
case "armory_unlocks": {
SETPVAR(player,Armory_Unlocks,_value);
};
case "garage_unlocks": {
SETPVAR(player,Garage_Unlocks,_value);
};
case "locker": {
SETPVAR(player,FORGE_Locker,_value);
};
case "garage": {
SETPVAR(player,FORGE_Garage,_value);
};
case "email": {
SETPVAR(player,FORGE_Email,_value);
};
case "number": {
SETPVAR(player,FORGE_Phone_Number,_value);
};
case "paygrade": {
SETPVAR(player,Paygrade,_value);
};
case "organization": {
SETPVAR(player,FORGE_Organization,_value);
};
case "stance": {
SETPVAR(player,Stance,_value);
player playAction _value;
};
case "holster": {
SETPVAR(player,FORGE_Holster_Weapon,_value);
if (_value) then {
[player] call AFUNC(weaponselect,putWeaponAway);
};
};
case "position": {
SETPVAR(player,Position,_value);
player setPosASL _value;
private _pAlt = ((getPosATLVisual player) select 2);
private _pVelZ = ((velocity player) select 2);
if (_pAlt > 5 && _pVelZ < 0) then {
player setVelocity [0, 0, 0];
player setPosATL [((getPosATLVisual player) select 0), ((getPosATLVisual player) select 1), 1];
hint "You logged off mid air. You were moved to a safe position on the ground.";
};
};
};
};
if (needReload player == 1) then { reload player };
SETPVAR(player,value_loadDone,true);
// ["listrng", GETVAR(player,FORGE_Email,_defaultEmail), "", -1, [], "forge_client_phone_fnc_addOfflineEmail", true] spawn dragonfly_db_fnc_addTask;
["listrng", GETVAR(player,FORGE_Email,_defaultEmail), "", -1, [], "forge_client_phone_fnc_addOfflineEmail", true, netId player] remoteExec ["dragonfly_db_fnc_addTask", 2, false];
// ["listrng", GETVAR(player,FORGE_Phone_Number,_defaultPhoneNumber), "", -1, [], "forge_client_phone_fnc_addOfflineMsg", true] spawn dragonfly_db_fnc_addTask;
["listrng", GETVAR(player,FORGE_Phone_Number,_defaultPhoneNumber), "", -1, [], "forge_client_phone_fnc_addOfflineMsg", true, netId player] remoteExec ["dragonfly_db_fnc_addTask", 2, false];
};