client/addons/store/functions/fnc_handlePurchase.sqf
Jacob Schmidt 55f60dc71f feat: Revamp admin panel, store, and arsenal systems
This commit introduces significant changes to the admin panel, store, and arsenal systems, focusing on improved functionality, UI enhancements, and code optimization.

**Admin Panel:**
- Migrated to a web-based UI for improved user experience and maintainability.
- Implemented dynamic player listing with filtering and search capabilities.
- Added functionality for managing player paygrades, sending messages, and transferring funds.
- Integrated server-side events for handling admin actions.

**Store:**
- Added `handleDelivery` event handler.
- Streamlined product selection and purchase processes.
- Improved handling of organization funds and player balances.
- Refactored code for better readability and maintainability.

**Arsenal:**
- Enhanced initialization process with improved data validation.
- Optimized item unlocking logic.

These changes aim to provide a more robust, user-friendly, and efficient experience for both administrators and players.
2025-05-03 19:33:10 -05:00

76 lines
2.0 KiB
Plaintext

#include "..\script_component.hpp"
/*
* Function: forge_store_fnc_handlePurchase
* Author: J. Schmidt
*
* Description:
* Handles the purchase of an item.
*
* Arguments:
* 0: Price <NUMBER> - The price of the item
*
* Return Value:
* None
*
* Example:
* [1000] call forge_store_fnc_handlePurchase
*
* Public: No
*/
params ["_price"];
private _paymentData = GVAR(activePayment);
private _payment = call compile _paymentData;
private _store = nil;
scopeName "main";
if (count _payment > 3) then {
private _authorizedUIDs = _payment select 3;
if !(getPlayerUID player in _authorizedUIDs) then {
["You are not authorized to use this payment method!", "warning", 3, "right"] call EFUNC(misc,notify);
false breakOut "main";
};
};
if (_payment select 0 == "Organization") then {
_store = call EFUNC(org,verifyOrgStore);
private _org = _store call ["getOrg", []];
private _ownerUID = _org get "owner";
if (getPlayerUID player != _ownerUID) then {
["You do not own this organization!", "warning", 3, "right"] call EFUNC(misc,notify);
false breakOut "main";
};
};
private _varType = toLower (_payment select 2);
private _varName = _payment param [1, "", [""]];
private _balance = switch (_varType) do {
case "organization": { _store call ["getFunds", []] };
case "player": { GETVAR(player,_varName,0) };
case "mission": { GETVAR(missionNamespace,_varName,0) };
default { diag_log "[FORGE Store] Error: Unknown payment type"; 0 };
};
if (_balance < _price) exitWith {
["You do not have enough funds!", "warning", 3, "right"] call EFUNC(misc,notify);
false
};
switch (_varType) do {
case "organization": { _store call ["updateFunds", -_price] };
case "player": {
private _newBalance = _balance - _price;
SETPVAR(player,_varName,_newBalance);
};
case "mission": {
private _newBalance = _balance - _price;
SETPVAR(missionNamespace,_varName,_newBalance);
};
};
true