Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 6.44 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. if ((time - life_action_delay) < 0.2) exitWith {hint localize "STR_NOTF_ActionDelay";};
  14. life_action_delay = time;
  15.  
  16. private _className = lbData[2302,(lbCurSel 2302)];
  17. private _vIndex = lbValue[2302,(lbCurSel 2302)];
  18. private _vehicleList = M_CONFIG(getArray,"CarShops",(life_veh_shop select 0),"vehicles");
  19. private _shopSide = M_CONFIG(getText,"CarShops",(life_veh_shop select 0),"side");
  20.  
  21.  
  22. private _initalPrice = M_CONFIG(getNumber,"LifeCfgVehicles",_className,"price");
  23.  
  24. private "_buyMultiplier";
  25. private "_rentMultiplier";
  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. private "_purchasePrice";
  47.  
  48. if (_mode) then {
  49.     _purchasePrice = round(_initalPrice * _buyMultiplier);
  50. } else {
  51.     _purchasePrice = round(_initalPrice * _rentMultiplier);
  52. };
  53.  
  54. private _conditions = M_CONFIG(getText,"LifeCfgVehicles",_className,"conditions");
  55.  
  56. if !([_conditions] call life_fnc_levelCheck) exitWith {hint localize "STR_Shop_Veh_NoLicense";};
  57.  
  58. private _colorIndex = lbValue[2304,(lbCurSel 2304)];
  59.  
  60. if (_purchasePrice < 0) exitWith {closeDialog 0;}; //Bad price entry
  61. if (CASH < _purchasePrice) exitWith {hint format [localize "STR_Shop_Veh_NotEnough",[_purchasePrice - CASH] call life_fnc_numberText];closeDialog 0;};
  62.  
  63. private _spawnPoints = life_veh_shop select 1;
  64. private _spawnPoint = "";
  65.  
  66. if ((life_veh_shop select 0) == "med_air_hs") then {
  67.     if (nearestObjects[(getMarkerPos _spawnPoints),["Air"],35] isEqualTo []) exitWith {_spawnPoint = _spawnPoints};
  68. } else {
  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.         {
  73.             if ((nearestObjects[(getMarkerPos _x),["Car","Ship","Air"],5]) isEqualTo []) exitWith {_spawnPoint = _x};
  74.             true
  75.         } count _spawnPoints;
  76.     } else {
  77.         if (nearestObjects[(getMarkerPos _spawnPoints),["Car","Ship","Air"],5] isEqualTo []) exitWith {_spawnPoint = _spawnPoints};
  78.     };
  79. };
  80.  
  81.  
  82. if (_spawnPoint isEqualTo "") exitWith {hint localize "STR_Shop_Veh_Block"; closeDialog 0;};
  83. CASH = CASH - _purchasePrice;
  84. [0] call SOCK_fnc_updatePartial;
  85. if (_mode) then {
  86.     hint format [localize "STR_Shop_Veh_Bought",getText(configFile >> "CfgVehicles" >> _className >> "displayName"),[_purchasePrice] call life_fnc_numberText];
  87. } else {
  88.     hint format [localize "STR_Shop_Veh_Rented",getText(configFile >> "CfgVehicles" >> _className >> "displayName"),[_purchasePrice] call life_fnc_numberText];
  89. };
  90.  
  91. //Spawn the vehicle and prep it.
  92.  
  93. private "_vehicle";
  94.  
  95. if ((life_veh_shop select 0) == "med_air_hs") then {
  96.     _vehicle = createVehicle [_className,[0,0,999],[], 0, "NONE"];
  97.     waitUntil {!isNil "_vehicle" && {!isNull _vehicle}}; //Wait?
  98.     _vehicle allowDamage false;
  99.     _hs = nearestObjects[getMarkerPos _spawnPoint,["Land_Hospital_side2_F"],50] select 0;
  100.     _vehicle setPosATL (_hs modelToWorld [-0.4,-4,12.65]);
  101.     sleep 0.6;
  102. } else {
  103.     _vehicle = createVehicle [_className, (getMarkerPos _spawnPoint), [], 0, "NONE"];
  104.     waitUntil {!isNil "_vehicle" && {!isNull _vehicle}}; //Wait?
  105.     _vehicle allowDamage false; //Temp disable damage handling..
  106.     _vehicle setPos (getMarkerPos _spawnPoint);
  107.     _vehicle setVectorUp (surfaceNormal (getMarkerPos _spawnPoint));
  108.     _vehicle setDir (markerDir _spawnPoint);
  109. };
  110.  
  111. _vehicle lock 2;
  112.  
  113. [_vehicle,_colorIndex] call life_fnc_colorVehicle;
  114. [_vehicle] call life_fnc_clearVehicleAmmo;
  115.  
  116. _vehicle setVariable ["trunk_in_use",false,true];
  117. _vehicle setVariable ["vehicle_info_owners",[[getPlayerUID player,profileName]],true];
  118.  
  119. _vehicle disableTIEquipment true; //No Thermals.. They're cheap but addictive.
  120.  
  121. //Side Specific actions.
  122. switch (playerSide) do {
  123.     case west: {
  124.         [_vehicle,"cop_offroad",true] spawn life_fnc_vehicleAnimate;
  125.     };
  126.     case civilian: {
  127.         if ((life_veh_shop select 2) isEqualTo "civ" && {_className == "B_Heli_Light_01_F"}) then {
  128.             [_vehicle,"civ_littlebird",true] spawn life_fnc_vehicleAnimate;
  129.         };
  130.     };
  131.     case independent: {
  132.         [_vehicle,"med_offroad",true] spawn life_fnc_vehicleAnimate;
  133.     };
  134. };
  135.  
  136. _vehicle allowDamage true;
  137.  
  138. life_vehicles pushBack _vehicle;
  139.  
  140. //Always handle key management by the server
  141. [getPlayerUID player,playerSide,_vehicle,1] remoteExecCall ["TON_fnc_keyManagement",RSERV];
  142.  
  143. if (_mode) then {
  144.     if !(_className in LIFE_SETTINGS(getArray,"vehicleShop_rentalOnly")) then {
  145.         if (life_HC_isActive) then {
  146.             [(getPlayerUID player),playerSide,_vehicle,_colorIndex] remoteExecCall ["HC_fnc_vehicleCreate",HC_Life];
  147.         } else {
  148.             [(getPlayerUID player),playerSide,_vehicle,_colorIndex] remoteExecCall ["TON_fnc_vehicleCreate",RSERV];
  149.         };
  150.     };
  151. };
  152.  
  153. if (LIFE_SETTINGS(getNumber,"player_advancedLog") isEqualTo 1) then {
  154.     if (LIFE_SETTINGS(getNumber,"battlEye_friendlyLogging") isEqualTo 1) then {
  155.         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];
  156.     } else {
  157.         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];
  158.     };
  159.     publicVariableServer "advanced_log";
  160. };
  161.  
  162. closeDialog 0; //Exit the menu.
  163. true;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement