skotracker

ExileServer_system_money_network_putMoneyRequest

Apr 19th, 2018
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 3.43 KB | None | 0 0
  1. /**
  2.  * ExileServer_system_money_network_putMoneyRequest
  3.  *
  4.  * Exile Mod
  5.  * www.exilemod.com
  6.  * © 2015 Exile Mod Team
  7.  *
  8.  * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.
  9.  * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
  10.  */
  11.  
  12. private["_sessionID","_parameters","_objectNetID","_amount","_newContainerNetID","_player","_playerMoney","_container","_containerMoney","_nearbyPopTabs","_maximumLoad","_maximumPoptabsLoad","_maximumAmmountToAdd","_containerID"];
  13. _sessionID = _this select 0;
  14. _parameters = _this select 1;
  15. _objectNetID = _parameters select 0;
  16. _amount = _parameters select 1;
  17. _newContainerNetID = "";
  18. try
  19. {
  20.     _player = _sessionID call ExileServer_system_session_getPlayerObject;
  21.     if (isNull _player) then
  22.     {
  23.         throw "Non-existent players cannot put money somewhere!";
  24.     };
  25.     if !(alive _player) then
  26.     {
  27.         throw "The dead cannot put money somewhere!";
  28.     };
  29.     if (_amount < 1) then
  30.     {
  31.         throw "Invalid money parameter!";
  32.     };
  33.     _playerMoney = _player getVariable ["ExileMoney", 0];
  34.     if (_amount > _playerMoney) then
  35.     {
  36.         throw "Cannot store money that this player does not have!";
  37.     };
  38.     _container = objectFromNetId _objectNetID;
  39.     if (isNull _container) then
  40.     {
  41.         throw "Cannot store money in non-existent container!";
  42.     };
  43.     if ((_player distance _container) > 10) then
  44.     {
  45.         throw "Cannot store money over long distances!";
  46.     };
  47.     _containerMoney = _container getVariable ["ExileMoney", 0];
  48.     if (_container isKindOf "GroundWeaponHolder") then
  49.     {
  50.         _nearbyPopTabs = nearestObjects [_player, ["Exile_PopTabs"], 3];
  51.         if (_nearbyPopTabs isEqualTo []) then
  52.         {
  53.             _container = createVehicle ["Exile_PopTabs", (getPos _player), [], 0, "CAN_COLLIDE"];
  54.             _container setPosASL (getPosASL _player);
  55.         }
  56.         else
  57.         {
  58.             _container = _nearbyPopTabs select 0;
  59.         };
  60.         _newContainerNetID = netID _container;
  61.     }
  62.     else
  63.     {
  64.         if!(_container isKindOf "man")then
  65.         {
  66.             _maximumLoad = getNumber (configFile >> "CfgVehicles" >> typeOf _container >> "maximumLoad");
  67.             if(_maximumLoad isEqualTo 0)then
  68.             {
  69.                 throw "Invalid container load";
  70.             };
  71.             _maximumPoptabsLoad = _maximumLoad * 40;
  72.             _maximumAmmountToAdd = _maximumPoptabsLoad - _containerMoney;
  73.             if(_amount > _maximumAmmountToAdd)then
  74.             {
  75.                 _amount = _maximumAmmountToAdd;
  76.             };
  77.         };
  78.     };
  79.     _playerMoney = _playerMoney - _amount;
  80.     _player setVariable ["ExileMoney", _playerMoney, true];
  81.     format["setPlayerMoney:%1:%2", _playerMoney, _player getVariable ["ExileDatabaseID", 0]] call ExileServer_system_database_query_fireAndForget;
  82.     _containerMoney = _container getVariable ["ExileMoney", 0];
  83.     _containerMoney = _containerMoney + _amount;
  84.     _container setVariable ["ExileMoney", _containerMoney, true];
  85.     _containerID = _container getVariable ["ExileDatabaseID", -1];
  86.     if (_containerID > -1) then
  87.     {
  88.         if ((getNumber (configFile >> "CfgVehicles" >> (typeOf _container) >> "exileContainer")) isEqualTo 1) then
  89.         {
  90.             format["setContainerMoney:%1:%2", _containerMoney, _containerID] call ExileServer_system_database_query_fireAndForget;
  91.         }
  92.         else
  93.         {
  94.             format["setVehicleMoney:%1:%2", _containerMoney, _containerID] call ExileServer_system_database_query_fireAndForget;
  95.         };
  96.     };
  97. }
  98. catch
  99. {
  100.     _exception call ExileServer_util_log;
  101. };
  102. [_sessionID, "moneyTransactionResponse", [_newContainerNetID, -1 * _amount]] call ExileServer_system_network_send_to;
Add Comment
Please, Sign In to add comment