client/addons/service/functions/fnc_refuel.sqf
Jacob Schmidt d474b3676a
All checks were successful
Build / Build (push) Successful in 28s
Refactor: Standardize function descriptions and variable handling
This commit refactors several client-side functions to improve code consistency and readability.

- Standardizes function descriptions by removing redundant "Function: forge_client..." prefixes and "[Description]" sections, focusing on concise descriptions of the function's purpose.
- Updates variable handling in arsenal functions to use GVAR and EGVARS for default values, improving consistency and reducing code duplication.
- Removes the bank init function as it is no longer needed.
- Adds a done variable to the preinit file.
2025-05-25 11:30:26 -05:00

70 lines
1.8 KiB
Plaintext

#include "..\script_component.hpp"
/*
* Author: IDSolutions
* Refuels the vehicle
*
* Arguments:
* 0: Vehicle <OBJECT> - The vehicle to refuel
* 1: Vehicle Type <STRING> - The classname of vehicle to refuel
*
* Return Value:
* None
*
* Example:
* [vehicle, "B_APC_Tracked_01_CRV_F"] call forge_client_service_fnc_refuel;
*
* Public: No
*/
params ["_veh", "_vehType"];
private _store = missionNamespace getVariable ["FORGE_ORG_STORE_REG", createHashMap];
private _org = _store call ["getOrg", []];
if (_org isEqualTo nil) exitWith {
["You are not in an organization!", "warning", 3] call EFUNC(misc,notify);
};
private _orgFunds = _org get "funds";
private _fnc_calculateFuelCost = {
params ["_currentFuel", "_fuelPrice"];
private _fuelNeeded = 1 - _currentFuel;
private _cost = _fuelNeeded * _fuelPrice;
[_fuelNeeded, _cost]
};
private _fnc_refuelVehicle = {
params ["_vehicle", "_fuelNeeded", "_fuelPrice"];
private _fuelAdded = 0;
private _refuelRate = 0.01;
private _refuelInterval = 0.1;
while { fuel _vehicle < 0.99 && _fuelAdded < _fuelNeeded } do {
_vehicle setFuel ((fuel _vehicle) + _refuelRate);
_fuelAdded = _fuelAdded + _refuelRate;
uiSleep _refuelInterval;
};
_fuelAdded
};
private _currentFuel = fuel _veh;
private _fuelPrice = "FUEL_COST" call BFUNC(getParamValue);
private _fuelDetails = [_currentFuel, _fuelPrice] call _fnc_calculateFuelCost;
_fuelDetails params ["_fuelNeeded", "_estimatedCost"];
if (_orgFunds < _estimatedCost) exitWith {
["Insufficient organization funds for refueling.", "warning", 3] call EFUNC(misc,notify);
};
_veh vehicleChat "Refueling...";
private _fuelAdded = [_veh, _fuelNeeded, _fuelPrice] call _fnc_refuelVehicle;
private _fuelCost = _fuelAdded * _fuelPrice;
_veh vehicleChat format ["%1 Refueled.", _vehType];
_fuelCost