#include "..\script_component.hpp" /* * Function: forge_store_fnc_handlePurchase * Author: J. Schmidt * * Description: * Handles the purchase of an item. * * Arguments: * 0: Price - 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; 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 { private _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 = _payment select 2; private _balance = switch (_varType) do { case "organization": { private _store = call EFUNC(org,verifyOrgStore); _store call ["getFunds", []]; }; case "player": { player getVariable [_payment select 1, 0] }; case "mission": { missionNamespace getVariable [_payment select 1, 0] }; default { 0 }; }; if (_balance < _price) exitWith { ["You do not have enough funds!", "warning", 3, "right"] call EFUNC(misc,notify); false }; switch (_varType) do { case "organization": { private _store = call EFUNC(org,verifyOrgStore); _store call ["updateFunds", -_price]; }; case "player": { player setVariable [_payment select 1, (_balance - _price), true]; }; case "mission": { missionNamespace setVariable [_payment select 1, (_balance - _price), true]; }; }; true