Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. //Side Specific actions.
  115. switch (playerSide) do {
  116. case west: {
  117. [_vehicle,"cop_offroad",true] spawn life_fnc_vehicleAnimate;
  118. };
  119. case civilian: {
  120. if ((life_veh_shop select 2) isEqualTo "civ" && {_className == "B_Heli_Light_01_F"}) then {
  121. [_vehicle,"civ_littlebird",true] spawn life_fnc_vehicleAnimate;
  122. };
  123. };
  124. case independent: {
  125. [_vehicle,"med_offroad",true] spawn life_fnc_vehicleAnimate;
  126. };
  127. };
  128.  
  129. _vehicle allowDamage true;
  130.  
  131. life_vehicles pushBack _vehicle;
  132.  
  133. //Always handle key management by the server
  134. [getPlayerUID player,playerSide,_vehicle,1] remoteExecCall ["TON_fnc_keyManagement",RSERV];
  135.  
  136. if (_mode) then {
  137. if !(_className in LIFE_SETTINGS(getArray,"vehicleShop_rentalOnly")) then {
  138. if (life_HC_isActive) then {
  139. [(getPlayerUID player),playerSide,_vehicle,_colorIndex] remoteExecCall ["HC_fnc_vehicleCreate",HC_Life];
  140. } else {
  141. [(getPlayerUID player),playerSide,_vehicle,_colorIndex] remoteExecCall ["TON_fnc_vehicleCreate",RSERV];
  142. };
  143. };
  144. };
  145.  
  146. if (LIFE_SETTINGS(getNumber,"player_advancedLog") isEqualTo 1) then {
  147. if (LIFE_SETTINGS(getNumber,"battlEye_friendlyLogging") isEqualTo 1) then {
  148. 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];
  149. } else {
  150. 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];
  151. };
  152. publicVariableServer "advanced_log";
  153. };
  154.  
  155. // The-Programmer
  156. [_mode,_vehicle] spawn max_immat_fnc_vehicleBuyImmatriculation;
  157. _vehicle setVariable ["vehicle_controlTech",0,true];
  158.  
  159. closeDialog 0; //Exit the menu.
  160. true;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement