Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 6.33 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. hint format [localize "STR_Shop_Veh_Bought",getText(configFile >> "CfgVehicles" >> _className >> "displayName"),[_purchasePrice] call life_fnc_numberText];
  86.  
  87. //Spawn the vehicle and prep it.
  88.  
  89. private "_vehicle";
  90.  
  91. if ((life_veh_shop select 0) == "med_air_hs") then {
  92.     _vehicle = createVehicle [_className,[0,0,999],[], 0, "NONE"];
  93.     waitUntil {!isNil "_vehicle" && {!isNull _vehicle}}; //Wait?
  94.     _vehicle allowDamage false;
  95.     _hs = nearestObjects[getMarkerPos _spawnPoint,["Land_Hospital_side2_F"],50] select 0;
  96.     _vehicle setPosATL (_hs modelToWorld [-0.4,-4,12.65]);
  97.     sleep 0.6;
  98. } else {
  99.     _vehicle = createVehicle [_className, (getMarkerPos _spawnPoint), [], 0, "NONE"];
  100.     waitUntil {!isNil "_vehicle" && {!isNull _vehicle}}; //Wait?
  101.     _vehicle allowDamage false; //Temp disable damage handling..
  102.     _vehicle setPos (getMarkerPos _spawnPoint);
  103.     _vehicle setVectorUp (surfaceNormal (getMarkerPos _spawnPoint));
  104.     _vehicle setDir (markerDir _spawnPoint);
  105. };
  106.  
  107. _vehicle lock 2;
  108.  
  109. [_vehicle,_colorIndex] call life_fnc_colorVehicle;
  110. [_vehicle] call life_fnc_clearVehicleAmmo;
  111.  
  112. _vehicle setVariable ["trunk_in_use",false,true];
  113. _vehicle setVariable ["vehicle_info_owners",[[getPlayerUID player,profileName]],true];
  114.  
  115. _vehicle disableTIEquipment true; //No Thermals.. They're cheap but addictive.
  116.  
  117. //Side Specific actions.
  118. switch (playerSide) do {
  119.     case west: {
  120.         [_vehicle,"cop_offroad",true] spawn life_fnc_vehicleAnimate;
  121.     };
  122.     case civilian: {
  123.         if ((life_veh_shop select 2) isEqualTo "civ" && {_className == "B_Heli_Light_01_F"}) then {
  124.             [_vehicle,"civ_littlebird",true] spawn life_fnc_vehicleAnimate;
  125.         };
  126.     };
  127.     case independent: {
  128.         [_vehicle,"med_offroad",true] spawn life_fnc_vehicleAnimate;
  129.     };
  130. };
  131.  
  132. _vehicle allowDamage true;
  133.  
  134. life_vehicles pushBack _vehicle;
  135.  
  136. //Always handle key management by the server
  137. [getPlayerUID player,playerSide,_vehicle,1] remoteExecCall ["TON_fnc_keyManagement",RSERV];
  138.  
  139. if (_mode) then {
  140.     if !(_className in LIFE_SETTINGS(getArray,"vehicleShop_rentalOnly")) then {
  141.         if (life_HC_isActive) then {
  142.             [(getPlayerUID player),playerSide,_vehicle,_colorIndex] remoteExecCall ["HC_fnc_vehicleCreate",HC_Life];
  143.         } else {
  144.             [(getPlayerUID player),playerSide,_vehicle,_colorIndex] remoteExecCall ["TON_fnc_vehicleCreate",RSERV];
  145.         };
  146.     };
  147. };
  148.  
  149. if (LIFE_SETTINGS(getNumber,"player_advancedLog") isEqualTo 1) then {
  150.     if (LIFE_SETTINGS(getNumber,"battlEye_friendlyLogging") isEqualTo 1) then {
  151.         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];
  152.     } else {
  153.         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];
  154.     };
  155.     publicVariableServer "advanced_log";
  156. };
  157.  
  158. closeDialog 0; //Exit the menu.
  159. true;
  160. sleep 0.001;
  161. [_mode,_vehicle] spawn max_immat_fnc_vehicleBuyImmatriculation;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement