#include "..\script_component.hpp"

/*
 * Author: IDSolutions
 * Handle cash to be given
 *
 * Arguments:
 * 0: Target to add money <OBJECT>
 * 1: Player to remove money <OBJECT>
 *
 * Return Value:
 * N/A
 *
 * Examples:
 * [cursorObject, player] spawn forge_client_money_fnc_giveCashSubmit;
 *
 * Public: Yes
 */

params ["_target", "_player"];

private _amount = parseNumber (ctrlText 1401);
private _playerCash = GETVAR(player,FORGE_Cash,0);
private _targetCash = GETVAR(_target,FORGE_Cash,0);

if (_amount > 0) then {
	if (_amount > _playerCash) exitWith { ["Insufficient cash available.", "warning", 3] call EFUNC(misc,notify) };

	private _newCash = _targetCash + _amount;
	private _formattedAmount =  (_amount) call EFUNC(misc,formatNumber);
	SETPVAR(_target,FORGE_Cash,_newCash);

	["deduct", "Cash", _amount] remoteExecCall ["forge_server_money_fnc_handleMoney", 2];
	[format ["You have received $%2 cash from %1", _player, _formattedAmount], "blue-grey", 3] remoteExecCall [QEFUNC(misc,notify), _target];
} else {
	[format ["Enter a valid amount greater than zero."], "warning", 3] call EFUNC(misc,notify);
};

closeDialog 0;