Advertisement
Marcus_Suridius

fn_vehicleShopBuy.sqf

Feb 8th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.34 KB | None | 0 0
  1. #include "..\..\script_macros.hpp"
  2. /*
  3. File: fn_vehicleShopBuy.sqf
  4. Author: Bryan "Tonic" Boardwine
  5.  
  6. Description:
  7. Does something with vehicle purchasing.
  8. */
  9. private["_mode","_vIndex","_spawnPoints","_className","_purchasePrice","_buyMultiplier","_rentMultiplier","_colorIndex","_spawnPoint","_vehicle","_vehicleList","_shopSide","_licenses","_licensesName","_exit","_initalPrice"];
  10. _mode = _this select 0;
  11. _exit = false;
  12. if ((lbCurSel 2302) isEqualTo -1) exitWith {hint localize "STR_Shop_Veh_DidntPick";closeDialog 0;};
  13. _className = lbData[2302,(lbCurSel 2302)];
  14. _vIndex = lbValue[2302,(lbCurSel 2302)];
  15. _vehicleList = M_CONFIG(getArray,"CarShops",(life_veh_shop select 0),"vehicles");
  16. _shopSide = M_CONFIG(getText,"CarShops",(life_veh_shop select 0),"side");
  17.  
  18. _licenses = switch (playerSide) do {
  19. case civilian: {(M_CONFIG(getArray,"LifeCfgVehicles",_className,"licenses") select 0)};
  20. case west: {(M_CONFIG(getArray,"LifeCfgVehicles",_className,"licenses") select 1)};
  21. case independent: {(M_CONFIG(getArray,"LifeCfgVehicles",_className,"licenses") select 2)};
  22. case east: {(M_CONFIG(getArray,"LifeCfgVehicles",_className,"licenses") select 3)};
  23. };
  24.  
  25. _initalPrice = M_CONFIG(getNumber,"LifeCfgVehicles",_className,"price");
  26.  
  27. switch (playerSide) do {
  28. case civilian: {
  29. _buyMultiplier = LIFE_SETTINGS(getNumber,"vehicle_purchase_multiplier_CIVILIAN");
  30. _rentMultiplier = LIFE_SETTINGS(getNumber,"vehicle_rental_multiplier_CIVILIAN");
  31. };
  32. case west: {
  33. _buyMultiplier = LIFE_SETTINGS(getNumber,"vehicle_purchase_multiplier_COP");
  34. _rentMultiplier = LIFE_SETTINGS(getNumber,"vehicle_rental_multiplier_COP");
  35. };
  36. case independent: {
  37. _buyMultiplier = LIFE_SETTINGS(getNumber,"vehicle_purchase_multiplier_MEDIC");
  38. _rentMultiplier = LIFE_SETTINGS(getNumber,"vehicle_rental_multiplier_MEDIC");
  39. };
  40. case east: {
  41. _buyMultiplier = LIFE_SETTINGS(getNumber,"vehicle_purchase_multiplier_OPFOR");
  42. _rentMultiplier = LIFE_SETTINGS(getNumber,"vehicle_rental_multiplier_OPFOR");
  43. };
  44. };
  45.  
  46. if (_mode) then {
  47. _purchasePrice = round(_initalPrice * _buyMultiplier);
  48. } else {
  49. _purchasePrice = round(_initalPrice * _rentMultiplier);
  50. };
  51. _colorIndex = lbValue[2304,(lbCurSel 2304)];
  52.  
  53. _licensesName = "";
  54. {
  55. if (!(_x isEqualTo "") && {!(LICENSE_VALUE(_x,_shopSide))}) then {
  56. _licensesName = _licensesName + localize M_CONFIG(getText,"Licenses",_x,"displayName") + "<br/>";
  57. _exit = true;
  58. };
  59. } forEach _licenses;
  60.  
  61. if (_exit) exitWith {hint parseText format[(localize "STR_Shop_Veh_NoLicense")+ "<br/><br/>%1",_licensesName];closeDialog 0;};
  62.  
  63. if (_purchasePrice < 0) exitWith {closeDialog 0;}; //Bad price entry
  64. if (CASH < _purchasePrice) exitWith {hint format[localize "STR_Shop_Veh_NotEnough",[_purchasePrice - CASH] call life_fnc_numberText];closeDialog 0;};
  65.  
  66. _spawnPoints = life_veh_shop select 1;
  67. _spawnPoint = "";
  68.  
  69. //Check if there is multiple spawn points and find a suitable spawnpoint.
  70. if (_spawnPoints isEqualType []) then {
  71. //Find an available spawn point.
  72. {if ((nearestObjects[(getMarkerPos _x),["Car","Ship","Air"],5]) isEqualTo []) exitWith {_spawnPoint = _x};} forEach _spawnPoints;
  73. } else {
  74. if ((nearestObjects[(getMarkerPos _spawnPoints),["Car","Ship","Air"],5]) isEqualTo []) exitWith {_spawnPoint = _spawnPoints};
  75. };
  76.  
  77. if (_spawnPoint isEqualTo "") exitWith {hint localize "STR_Shop_Veh_Block";closeDialog 0;};
  78. CASH = CASH - _purchasePrice;
  79. hint format[localize "STR_Shop_Veh_Bought",getText(configFile >> "CfgVehicles" >> _className >> "displayName"),[_purchasePrice] call life_fnc_numberText];
  80.  
  81. //Spawn the vehicle and prep it.
  82. _vehicle = createVehicle [_className, (getMarkerPos _spawnPoint), [], 0, "NONE"];
  83. waitUntil {!isNil "_vehicle" && {!isNull _vehicle}}; //Wait?
  84. _vehicle allowDamage false; //Temp disable damage handling..
  85. _vehicle setPos (getMarkerPos _spawnPoint);
  86. _vehicle setVectorUp (surfaceNormal (getMarkerPos _spawnPoint));
  87. _vehicle setDir (markerDir _spawnPoint);
  88. };
  89.  
  90. _vehicle lock 2;
  91. [_vehicle,_colorIndex] call life_fnc_colorVehicle;
  92. [_vehicle] call life_fnc_clearVehicleAmmo;
  93. [_vehicle,"trunk_in_use",false,true] remoteExecCall ["TON_fnc_setObjVar",RSERV];
  94. [_vehicle,"vehicle_info_owners",[[getPlayerUID player,profileName]],true] remoteExecCall ["TON_fnc_setObjVar",RSERV];
  95. _vehicle disableTIEquipment true; //No Thermals.. They're cheap but addictive.
  96.  
  97. //Side Specific actions.
  98. switch (playerSide) do {
  99. case west: {
  100. [_vehicle,"cop_offroad",true] spawn life_fnc_vehicleAnimate;
  101. };
  102. case civilian: {
  103. if ((life_veh_shop select 2) isEqualTo "civ" && {_className == "B_Heli_Light_01_F"}) then {
  104. [_vehicle,"civ_littlebird",true] spawn life_fnc_vehicleAnimate;
  105. };
  106. };
  107. case independent: {
  108. [_vehicle,"med_offroad",true] spawn life_fnc_vehicleAnimate;
  109. };
  110. };
  111.  
  112. _vehicle allowDamage true;
  113.  
  114. life_vehicles pushBack _vehicle;
  115.  
  116. //Always handle key management by the server
  117. [getPlayerUID player,playerSide,_vehicle,1] remoteExecCall ["TON_fnc_keyManagement",RSERV];
  118.  
  119. if (_mode) then {
  120. if (!(_className in ["B_G_Offroad_01_armed_F","B_MRAP_01_hmg_F"])) then {
  121. if (life_HC_isActive) then {
  122. [(getPlayerUID player),playerSide,_vehicle,_colorIndex] remoteExecCall ["HC_fnc_vehicleCreate",HC_Life];
  123. } else {
  124. [(getPlayerUID player),playerSide,_vehicle,_colorIndex] remoteExecCall ["TON_fnc_vehicleCreate",RSERV];
  125. };
  126. };
  127. };
  128.  
  129. if (LIFE_SETTINGS(getNumber,"player_advancedLog") isEqualTo 1) then {
  130. if (LIFE_SETTINGS(getNumber,"battlEye_friendlyLogging") isEqualTo 1) then {
  131. advanced_log = format ["bought vehicle %1 for £%2. On Hand Cash: £%3 Bank Balance: £%4",_className,[_purchasePrice] call life_fnc_numberText,[CASH] call life_fnc_numberText,[BANK] call life_fnc_numberText];
  132. } else {
  133. advanced_log = format ["%1 - %2 bought vehicle %3 for £%4. On Hand Cash: £%5 Bank Balance £%6",profileName,(getPlayerUID player),_className,[_purchasePrice] call life_fnc_numberText,[CASH] call life_fnc_numberText,[BANK] call life_fnc_numberText];
  134. };
  135. publicVariableServer "advanced_log";
  136. };
  137.  
  138. _vehicle addItemCargoGlobal ["ToolKit", 1];
  139. _vehicle addItemCargoGlobal ["FirstAidKit", 2];
  140.  
  141. [0] call SOCK_fnc_updatePartial;
  142. closeDialog 0; //Exit the menu.
  143. true;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement