Guest User

fn_vehicleShopBuy.sqf

a guest
Aug 8th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.89 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.  
  10. params [["_mode",true,[true]]];
  11.  
  12. if ((lbCurSel 2302) isEqualTo -1) exitWith {hint localize "STR_Shop_Veh_DidntPick";closeDialog 0;};
  13.  
  14. private _className = lbData[2302,(lbCurSel 2302)];
  15. private _vIndex = lbValue[2302,(lbCurSel 2302)];
  16. private _vehicleList = M_CONFIG(getArray,"CarShops",(life_veh_shop select 0),"vehicles");
  17. private _shopSide = M_CONFIG(getText,"CarShops",(life_veh_shop select 0),"side");
  18.  
  19.  
  20. private _initalPrice = M_CONFIG(getNumber,"LifeCfgVehicles",_className,"price");
  21.  
  22. private "_buyMultiplier";
  23. private "_rentMultiplier";
  24.  
  25. switch (playerSide) do {
  26. case civilian: {
  27. _buyMultiplier = LIFE_SETTINGS(getNumber,"vehicle_purchase_multiplier_CIVILIAN");
  28. _rentMultiplier = LIFE_SETTINGS(getNumber,"vehicle_rental_multiplier_CIVILIAN");
  29. };
  30. case west: {
  31. _buyMultiplier = LIFE_SETTINGS(getNumber,"vehicle_purchase_multiplier_COP");
  32. _rentMultiplier = LIFE_SETTINGS(getNumber,"vehicle_rental_multiplier_COP");
  33. };
  34. case independent: {
  35. _buyMultiplier = LIFE_SETTINGS(getNumber,"vehicle_purchase_multiplier_MEDIC");
  36. _rentMultiplier = LIFE_SETTINGS(getNumber,"vehicle_rental_multiplier_MEDIC");
  37. };
  38. case east: {
  39. _buyMultiplier = LIFE_SETTINGS(getNumber,"vehicle_purchase_multiplier_OPFOR");
  40. _rentMultiplier = LIFE_SETTINGS(getNumber,"vehicle_rental_multiplier_OPFOR");
  41. };
  42. };
  43.  
  44. private "_purchasePrice";
  45.  
  46. if (_mode) then {
  47. _purchasePrice = round(_initalPrice * _buyMultiplier);
  48. } else {
  49. _purchasePrice = round(_initalPrice * _rentMultiplier);
  50. };
  51.  
  52. private _conditions = M_CONFIG(getText,"LifeCfgVehicles",_className,"conditions");
  53.  
  54. if !([_conditions] call life_fnc_levelCheck) exitWith {hint localize "STR_Shop_Veh_NoLicense";};
  55.  
  56. private _colorIndex = lbValue[2304,(lbCurSel 2304)];
  57.  
  58. if (_purchasePrice < 0) exitWith {closeDialog 0;}; //Bad price entry
  59. if (CASH < _purchasePrice) exitWith {hint format [localize "STR_Shop_Veh_NotEnough",[_purchasePrice - CASH] call life_fnc_numberText];closeDialog 0;};
  60.  
  61. private _spawnPoints = life_veh_shop select 1;
  62. private _spawnPoint = "";
  63.  
  64. if ((life_veh_shop select 0) == "med_air_hs") then {
  65. if (nearestObjects[(getMarkerPos _spawnPoints),["Air"],35] isEqualTo []) exitWith {_spawnPoint = _spawnPoints};
  66. } else {
  67. //Check if there is multiple spawn points and find a suitable spawnpoint.
  68. if (_spawnPoints isEqualType []) then {
  69. //Find an available spawn point.
  70. {
  71. if ((nearestObjects[(getMarkerPos _x),["Car","Ship","Air"],5]) isEqualTo []) exitWith {_spawnPoint = _x};
  72. true
  73. } count _spawnPoints;
  74. } else {
  75. if (nearestObjects[(getMarkerPos _spawnPoints),["Car","Ship","Air"],5] isEqualTo []) exitWith {_spawnPoint = _spawnPoints};
  76. };
  77. };
  78.  
  79.  
  80. if (_spawnPoint isEqualTo "") exitWith {hint localize "STR_Shop_Veh_Block"; closeDialog 0;};
  81. CASH = CASH - _purchasePrice;
  82. [0] call SOCK_fnc_updatePartial;
  83. hint format [localize "STR_Shop_Veh_Bought",getText(configFile >> "CfgVehicles" >> _className >> "displayName"),[_purchasePrice] call life_fnc_numberText];
  84.  
  85. //Spawn the vehicle and prep it.
  86.  
  87. private "_vehicle";
  88.  
  89. if ((life_veh_shop select 0) == "med_air_hs") then {
  90. _vehicle = createVehicle [_className,[0,0,999],[], 0, "NONE"];
  91. waitUntil {!isNil "_vehicle" && {!isNull _vehicle}}; //Wait?
  92. _vehicle allowDamage false;
  93. _hs = nearestObjects[getMarkerPos _spawnPoint,["Land_Hospital_side2_F"],50] select 0;
  94. _vehicle setPosATL (_hs modelToWorld [-0.4,-4,12.65]);
  95. sleep 0.6;
  96. } else {
  97. _vehicle = createVehicle [_className, (getMarkerPos _spawnPoint), [], 0, "NONE"];
  98. waitUntil {!isNil "_vehicle" && {!isNull _vehicle}}; //Wait?
  99. _vehicle allowDamage false; //Temp disable damage handling..
  100. _vehicle setPos (getMarkerPos _spawnPoint);
  101. _vehicle setVectorUp (surfaceNormal (getMarkerPos _spawnPoint));
  102. _vehicle setDir (markerDir _spawnPoint);
  103. };
  104.  
  105. _vehicle lock 2;
  106.  
  107. [_vehicle,_colorIndex] call life_fnc_colorVehicle;
  108. [_vehicle] call life_fnc_clearVehicleAmmo;
  109. [_vehicle,"trunk_in_use",false,true] remoteExecCall ["TON_fnc_setObjVar",RSERV];
  110. [_vehicle,"vehicle_info_owners",[[getPlayerUID player,profileName]],true] remoteExecCall ["TON_fnc_setObjVar",RSERV];
  111.  
  112. _vehicle disableTIEquipment true; //No Thermals.. They're cheap but addictive.
  113.  
  114. _select1 = selectRandom ["A","B","C","D","E","F","G","H","J","K","L","M","N","O","P","R","S","T","U","W","X","Y","Z"];
  115. _select2 = selectRandom ["A","B","C","D","E","F","G","H","J","K","L","M","N","O","P","R","S","T","U","W","X","Y","Z"];
  116. _select3 = selectRandom ["A","B","C","D","E","F","G","H","J","K","L","M","N","O","P","R","S","T","U","W","X","Y","Z"];
  117. _select4 = selectRandom ["1","2","3","4","5","6","7","8","9","0"];
  118. _select5 = selectRandom ["1","2","3","4","5","6","7","8","9","0"];
  119. _select6 = selectRandom ["1","2","3","4","5","6","7","8","9","0"];
  120. private _plate = format["%1%2%3 %4%5%6",_select1,_select2,_select3,_select4,_select5,_select6];
  121. _vehicle setPlateNumber _plate;
  122.  
  123. //Side Specific actions.
  124. switch (playerSide) do {
  125. case west: {
  126. [_vehicle,"cop_offroad",true] spawn life_fnc_vehicleAnimate;
  127. };
  128. case civilian: {
  129. if ((life_veh_shop select 2) isEqualTo "civ" && {_className == "B_Heli_Light_01_F"}) then {
  130. [_vehicle,"civ_littlebird",true] spawn life_fnc_vehicleAnimate;
  131. };
  132. };
  133. case independent: {
  134. [_vehicle,"med_offroad",true] spawn life_fnc_vehicleAnimate;
  135. };
  136. };
  137.  
  138. _vehicle allowDamage true;
  139.  
  140. life_vehicles pushBack _vehicle;
  141.  
  142. //Always handle key management by the server
  143. [getPlayerUID player,playerSide,_vehicle,1] remoteExecCall ["TON_fnc_keyManagement",RSERV];
  144.  
  145. if (_mode) then {
  146. if !(_className in LIFE_SETTINGS(getArray,"vehicleShop_rentalOnly")) then {
  147. if (life_HC_isActive) then {
  148. [(getPlayerUID player),playerSide,_vehicle,_colorIndex,_plate] remoteExecCall ["HC_fnc_vehicleCreate",HC_Life];
  149. } else {
  150. [(getPlayerUID player),playerSide,_vehicle,_colorIndex,_plate] remoteExecCall ["TON_fnc_vehicleCreate",RSERV];
  151. };
  152. };
  153. };
  154.  
  155. if (LIFE_SETTINGS(getNumber,"player_advancedLog") isEqualTo 1) then {
  156. if (LIFE_SETTINGS(getNumber,"battlEye_friendlyLogging") isEqualTo 1) then {
  157. advanced_log = format [localize "STR_DL_AL_boughtVehicle_BEF",_className,[_purchasePrice] call life_fnc_numberText,[CASH] call life_fnc_numberText,[BANK] call life_fnc_numberText];
  158. } else {
  159. advanced_log = format [localize "STR_DL_AL_boughtVehicle",profileName,(getPlayerUID player),_className,[_purchasePrice] call life_fnc_numberText,[CASH] call life_fnc_numberText,[BANK] call life_fnc_numberText];
  160. };
  161. publicVariableServer "advanced_log";
  162. };
  163.  
  164. closeDialog 0; //Exit the menu.
  165. true;
Add Comment
Please, Sign In to add comment