- Expanded README.md to detail economy addon functionalities including refueling, medical services, and service charges. - Updated XEH_PREP.hpp to include initSEconomyStore preparation. - Modified XEH_postInit.sqf to ensure MEconomyStore initializes only if not nil. - Adjusted XEH_preInit.sqf to initialize SEconomyStore correctly. - Updated config.cpp to include forge_server_common as a required addon. - Enhanced fnc_initFEconomyStore.sqf to manage fuel refueling sessions and organization charges. - Improved fnc_initMEconomyStore.sqf to handle medical billing and fallback to organization funds. - Created fnc_initSEconomyStore.sqf for organization-funded service charges and repairs. - Updated org.rs and org.rs service layer to support member debt recording and organization fund charging. - Added ECONOMY_USAGE_GUIDE.md for comprehensive documentation on economy functionalities. - Updated MODULE_REFERENCE.md and README.md to include links to the new economy guide.
107 lines
4.2 KiB
Plaintext
107 lines
4.2 KiB
Plaintext
#include "..\script_component.hpp"
|
|
|
|
/*
|
|
* File: fnc_initFEconomyStore.sqf
|
|
* Author: IDSolutions
|
|
* Date: 2025-12-20
|
|
* Last Update: 2026-01-03
|
|
* Public: No
|
|
*
|
|
* Description:
|
|
* Initializes the fuel economy store. Active refueling sessions remain
|
|
* server-local; payment is routed through the organization extension hot
|
|
* cache.
|
|
*
|
|
* Parameter(s):
|
|
* N/A
|
|
*
|
|
* Returns:
|
|
* Fuel economy store object [HASHMAP OBJECT]
|
|
*
|
|
* Example(s):
|
|
* call forge_server_economy_fnc_initFEconomyStore
|
|
*/
|
|
|
|
#pragma hemtt ignore_variables ["_self"]
|
|
GVAR(FEconomyStore) = createHashMapObject [[
|
|
["#type", "IFuelEconomy"],
|
|
["#create", {
|
|
GVAR(FuelCost) = 5;
|
|
_self set ["fuelRegistry", createHashMap];
|
|
|
|
["INFO", "Fuel Store Initialized!", nil, nil] call EFUNC(common,log);
|
|
}],
|
|
["start", {
|
|
params ["_source", "_target", "_unit"];
|
|
|
|
private _index = netId _target;
|
|
private _uid = getPlayerUID _unit;
|
|
private _fuelRegistry = _self getOrDefault ["fuelRegistry", createHashMap];
|
|
|
|
_fuelRegistry set [_index, createHashMapFromArray [
|
|
["uid", _uid],
|
|
["initialFuel", fuel _target]
|
|
]];
|
|
SETVAR(_target,liters,0);
|
|
}],
|
|
["rollbackFuel", {
|
|
params [["_target", objNull, [objNull]], ["_initialFuel", 0, [0]]];
|
|
|
|
if (isNull _target) exitWith { false };
|
|
|
|
_target setFuel (_initialFuel max 0 min 1);
|
|
SETVAR(_target,liters,0);
|
|
true
|
|
}],
|
|
["stop", {
|
|
params ["_source", "_target"];
|
|
|
|
private _index = netId _target;
|
|
private _fuelRegistry = _self getOrDefault ["fuelRegistry", createHashMap];
|
|
private _session = _fuelRegistry getOrDefault [_index, createHashMap];
|
|
if (_session isEqualType "") then {
|
|
_session = createHashMapFromArray [["uid", _session], ["initialFuel", fuel _target]];
|
|
};
|
|
|
|
private _uid = _session getOrDefault ["uid", ""];
|
|
private _initialFuel = _session getOrDefault ["initialFuel", fuel _target];
|
|
private _player = [_uid] call EFUNC(common,getPlayer);
|
|
|
|
private _totalLiters = GETVAR(_target,liters,0);
|
|
private _totalCost = _totalLiters * GVAR(FuelCost);
|
|
private _formattedTotalCost = [_totalCost] call EFUNC(common,formatNumber);
|
|
private _formattedTotalLiters = _totalLiters toFixed 2;
|
|
|
|
if (isNull _player || { _uid isEqualTo "" }) exitWith {
|
|
["WARNING", format ["Unable to resolve refueling player for vehicle %1.", _index], nil, nil] call EFUNC(common,log);
|
|
_self call ["rollbackFuel", [_target, _initialFuel]];
|
|
_fuelRegistry deleteAt _index;
|
|
};
|
|
|
|
if (_totalCost <= 0) exitWith {
|
|
[CRPC(notifications,recieveNotification), ["info", "Refueling", format ["Refueling complete: %1L", _formattedTotalLiters]], _player] call CFUNC(targetEvent);
|
|
_fuelRegistry deleteAt _index;
|
|
};
|
|
|
|
if (isNil QGVAR(SEconomyStore)) exitWith {
|
|
["ERROR", "Service economy store unavailable for refueling charge.", nil, nil] call EFUNC(common,log);
|
|
[CRPC(notifications,recieveNotification), ["danger", "Refueling", "Organization billing is unavailable. Refueling was not completed."], _player] call CFUNC(targetEvent);
|
|
_self call ["rollbackFuel", [_target, _initialFuel]];
|
|
_fuelRegistry deleteAt _index;
|
|
};
|
|
|
|
private _chargeResult = GVAR(SEconomyStore) call ["chargeOrg", [_player, _totalCost, "Refueling"]];
|
|
if !(_chargeResult getOrDefault ["success", false]) exitWith {
|
|
[CRPC(notifications,recieveNotification), ["danger", "Refueling", _chargeResult getOrDefault ["message", "Organization funds cannot cover this refuel. Refueling was not completed."]], _player] call CFUNC(targetEvent);
|
|
_self call ["rollbackFuel", [_target, _initialFuel]];
|
|
_fuelRegistry deleteAt _index;
|
|
};
|
|
|
|
[CRPC(notifications,recieveNotification), ["info", "Refueling", format ["Refueling complete: %1L<br />Organization charged $%2.", _formattedTotalLiters, _formattedTotalCost]], _player] call CFUNC(targetEvent);
|
|
_fuelRegistry deleteAt _index;
|
|
}]
|
|
]];
|
|
|
|
SETMVAR(FORGE_FEconomyStore,GVAR(FEconomyStore));
|
|
GVAR(FEconomyStore)
|