Advertisement
Guest User

Untitled

a guest
Feb 8th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.57 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.  
  65. //Check if there is multiple spawn points and find a suitable spawnpoint.
  66. if (_spawnPoints isEqualType []) then {
  67. //Find an available spawn point.
  68. {
  69. if ((nearestObjects[(getMarkerPos _x),["Car","Ship","Air"],5]) isEqualTo []) exitWith {_spawnPoint = _x};
  70. true
  71. } count _spawnPoints;
  72. } else {
  73. if (nearestObjects[(getMarkerPos _spawnPoints),["Car","Ship","Air"],5] isEqualTo []) exitWith {_spawnPoint = _spawnPoints};
  74. };
  75.  
  76.  
  77.  
  78. if (_spawnPoint isEqualTo "") exitWith {hint localize "STR_Shop_Veh_Block"; closeDialog 0;};
  79. CASH = CASH - _purchasePrice;
  80. [0] call SOCK_fnc_updatePartial;
  81. hint format [localize "STR_Shop_Veh_Bought",getText(configFile >> "CfgVehicles" >> _className >> "displayName"),[_purchasePrice] call life_fnc_numberText];
  82.  
  83. //Spawn the vehicle and prep it.
  84.  
  85. private "_vehicle";
  86.  
  87.  
  88. _vehicle = createVehicle [_className, (getMarkerPos _spawnPoint), [], 0, "NONE"];
  89. waitUntil {!isNil "_vehicle" && {!isNull _vehicle}}; //Wait?
  90. _vehicle allowDamage false; //Temp disable damage handling..
  91. _vehicle setPos (getMarkerPos _spawnPoint);
  92. _vehicle setVectorUp (surfaceNormal (getMarkerPos _spawnPoint));
  93. _vehicle setDir (markerDir _spawnPoint);
  94.  
  95.  
  96. _vehicle lock 2;
  97.  
  98. [_vehicle,_colorIndex] call life_fnc_colorVehicle;
  99. [_vehicle] call life_fnc_clearVehicleAmmo;
  100. [_vehicle,"trunk_in_use",false,true] remoteExecCall ["TON_fnc_setObjVar",RSERV];
  101. [_vehicle,"vehicle_info_owners",[[getPlayerUID player,profileName]],true] remoteExecCall ["TON_fnc_setObjVar",RSERV];
  102.  
  103. _vehicle disableTIEquipment true; //No Thermals.. They're cheap but addictive.
  104.  
  105. //Side Specific actions.
  106. switch (playerSide) do {
  107. case west: {
  108. [_vehicle,"cop_offroad",true] spawn life_fnc_vehicleAnimate;
  109. };
  110. case civilian: {
  111. if ((life_veh_shop select 2) isEqualTo "civ" && {_className == "B_Heli_Light_01_F"}) then {
  112. [_vehicle,"civ_littlebird",true] spawn life_fnc_vehicleAnimate;
  113. };
  114. };
  115. case independent: {
  116. [_vehicle,"med_offroad",true] spawn life_fnc_vehicleAnimate;
  117. };
  118. };
  119.  
  120. _vehicle allowDamage true;
  121.  
  122. life_vehicles pushBack _vehicle;
  123.  
  124. //Always handle key management by the server
  125. [getPlayerUID player,playerSide,_vehicle,1] remoteExecCall ["TON_fnc_keyManagement",RSERV];
  126.  
  127. if (_mode) then {
  128. if !(_className in LIFE_SETTINGS(getArray,"vehicleShop_rentalOnly")) then {
  129. if (life_HC_isActive) then {
  130. [(getPlayerUID player),playerSide,_vehicle,_colorIndex] remoteExecCall ["HC_fnc_vehicleCreate",HC_Life];
  131. } else {
  132. [(getPlayerUID player),playerSide,_vehicle,_colorIndex] remoteExecCall ["TON_fnc_vehicleCreate",RSERV];
  133. };
  134. };
  135. };
  136.  
  137. if (LIFE_SETTINGS(getNumber,"player_advancedLog") isEqualTo 1) then {
  138. if (LIFE_SETTINGS(getNumber,"battlEye_friendlyLogging") isEqualTo 1) then {
  139. 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];
  140. } else {
  141. 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];
  142. };
  143. publicVariableServer "advanced_log";
  144. };
  145.  
  146. closeDialog 0; //Exit the menu.
  147. true;
  148. [] call life_fnc_hudUpdate;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement