daily pastebin goal
12%
SHARE
TWEET

Untitled

a guest Apr 15th, 2018 2 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. private [ “_mode” , “_spawnPoints” , “_className” , “_basePrice” , “_colorIndex” , “_spawnPoint” , “_vehicle” , “_sp” , “_vh” , “_box” , “_offset” ];
  10.  
  11. params [["_mode",true,[true]]];
  12.  
  13. if ((lbCurSel 2302) isEqualTo -1) exitWith {hint localize "STR_Shop_Veh_DidntPick";closeDialog 0;};
  14.  
  15. private _className = lbData[2302,(lbCurSel 2302)];
  16. private _vIndex = lbValue[2302,(lbCurSel 2302)];
  17. private _vehicleList = M_CONFIG(getArray,"CarShops",(life_veh_shop select 0),"vehicles");
  18. private _shopSide = M_CONFIG(getText,"CarShops",(life_veh_shop select 0),"side");
  19.  
  20.  
  21. private _initalPrice = M_CONFIG(getNumber,"LifeCfgVehicles",_className,"price");
  22.  
  23. private "_buyMultiplier";
  24. private "_rentMultiplier";
  25.  
  26. switch (playerSide) do {
  27.     case civilian: {
  28.         _buyMultiplier = LIFE_SETTINGS(getNumber,"vehicle_purchase_multiplier_CIVILIAN");
  29.         _rentMultiplier = LIFE_SETTINGS(getNumber,"vehicle_rental_multiplier_CIVILIAN");
  30.     };
  31.     case west: {
  32.         _buyMultiplier = LIFE_SETTINGS(getNumber,"vehicle_purchase_multiplier_COP");
  33.         _rentMultiplier = LIFE_SETTINGS(getNumber,"vehicle_rental_multiplier_COP");
  34.     };
  35.     case independent: {
  36.         _buyMultiplier = LIFE_SETTINGS(getNumber,"vehicle_purchase_multiplier_MEDIC");
  37.         _rentMultiplier = LIFE_SETTINGS(getNumber,"vehicle_rental_multiplier_MEDIC");
  38.     };
  39.     case east: {
  40.         _buyMultiplier = LIFE_SETTINGS(getNumber,"vehicle_purchase_multiplier_OPFOR");
  41.         _rentMultiplier = LIFE_SETTINGS(getNumber,"vehicle_rental_multiplier_OPFOR");
  42.     };
  43. };
  44.  
  45. private "_purchasePrice";
  46.  
  47. if (_mode) then {
  48.     _purchasePrice = round(_initalPrice * _buyMultiplier);
  49. } else {
  50.     _purchasePrice = round(_initalPrice * _rentMultiplier);
  51. };
  52.  
  53. private _conditions = M_CONFIG(getText,"LifeCfgVehicles",_className,"conditions");
  54.  
  55. if !([_conditions] call life_fnc_levelCheck) exitWith {hint localize "STR_Shop_Veh_NoLicense";};
  56.  
  57. private _colorIndex = lbValue[2304,(lbCurSel 2304)];
  58.  
  59. if (_purchasePrice < 0) exitWith {closeDialog 0;}; //Bad price entry
  60. if (CASH < _purchasePrice) exitWith {hint format [localize "STR_Shop_Veh_NotEnough",[_purchasePrice - CASH] call life_fnc_numberText];closeDialog 0;};
  61.  
  62. private _spawnPoints = life_veh_shop select 1;
  63. private _spawnPoint = "";
  64.  
  65. if ((life_veh_shop select 0) == "med_air_hs") then {
  66.     if (nearestObjects[(getMarkerPos _spawnPoints),["Air"],35] isEqualTo []) exitWith {_spawnPoint = _spawnPoints};
  67. } else {
  68.     //Check if there is multiple spawn points and find a suitable spawnpoint.
  69.     if (_spawnPoints isEqualType []) then {
  70.         //Find an available spawn point.
  71.         {
  72.             if ((nearestObjects[(getMarkerPos _x),["Car","Ship","Air"],5]) isEqualTo []) exitWith {_spawnPoint = _x};
  73.             true
  74.         } count _spawnPoints;
  75.     } else {
  76.         if (nearestObjects[(getMarkerPos _spawnPoints),["Car","Ship","Air"],5] isEqualTo []) exitWith {_spawnPoint = _spawnPoints};
  77.     };
  78. };
  79.  
  80.  
  81. if (_spawnPoint isEqualTo "") exitWith {hint localize "STR_Shop_Veh_Block"; closeDialog 0;};
  82. CASH = CASH - _purchasePrice;
  83. [0] call SOCK_fnc_updatePartial;
  84. hint format [localize "STR_Shop_Veh_Bought",getText(configFile >> "CfgVehicles" >> _className >> "displayName"),[_purchasePrice] call life_fnc_numberText];
  85.  
  86. //Spawn the vehicle and prep it.
  87.  
  88. private "_vehicle";
  89.  
  90. if ((life_veh_shop select 0) == "med_air_hs") then {
  91.     _vehicle = createVehicle [_className,[0,0,999],[], 0, "NONE"];
  92.     waitUntil {!isNil "_vehicle" && {!isNull _vehicle}}; //Wait?
  93.     _vehicle allowDamage false;
  94.     _hs = nearestObjects[getMarkerPos _spawnPoint,["Land_Hospital_side2_F"],50] select 0;
  95.     _vehicle setPosATL (_hs modelToWorld [-0.4,-4,12.65]);
  96.     sleep 0.6;
  97. } else {
  98.     _vehicle = createVehicle [_className, (getMarkerPos _spawnPoint), [], 0, "NONE"];
  99.     waitUntil {!isNil "_vehicle" && {!isNull _vehicle}}; //Wait?
  100.     _vehicle allowDamage false; //Temp disable damage handling..
  101.     _vehicle setPos (getMarkerPos _spawnPoint);
  102.     _vehicle setVectorUp (surfaceNormal (getMarkerPos _spawnPoint));
  103.     _vehicle setDir (markerDir _spawnPoint);
  104. };
  105.  
  106. _vehicle lock 2;
  107.  
  108. [_vehicle,_colorIndex] call life_fnc_colorVehicle;
  109. [_vehicle] call life_fnc_clearVehicleAmmo;
  110. [_vehicle,"trunk_in_use",false,true] remoteExecCall ["TON_fnc_setObjVar",RSERV];
  111. [_vehicle,"vehicle_info_owners",[[getPlayerUID player,profileName]],true] remoteExecCall ["TON_fnc_setObjVar",RSERV];
  112.  
  113. _vehicle disableTIEquipment true; //No Thermals.. They're cheap but addictive.
  114.  
  115. //Side Specific actions.
  116. switch (playerSide) do {
  117.     case west: {
  118.         [_vehicle,"cop_offroad",true] spawn life_fnc_vehicleAnimate;
  119.     };
  120.     case civilian: {
  121.         if ((life_veh_shop select 2) isEqualTo "civ" && {_className == "B_Heli_Light_01_F"}) then {
  122.             [_vehicle,"civ_littlebird",true] spawn life_fnc_vehicleAnimate;
  123.         };
  124.     };
  125.     case independent: {
  126.         [_vehicle,"med_offroad",true] spawn life_fnc_vehicleAnimate;
  127.     };
  128. };
  129.  
  130. _vehicle allowDamage true;
  131.  
  132. life_vehicles pushBack _vehicle;
  133.  
  134. //Always handle key management by the server
  135. [getPlayerUID player,playerSide,_vehicle,1] remoteExecCall ["TON_fnc_keyManagement",RSERV];
  136.  
  137. if (_mode) then {
  138.     if !(_className in LIFE_SETTINGS(getArray,"vehicleShop_rentalOnly")) then {
  139.         if (life_HC_isActive) then {
  140.             [(getPlayerUID player),playerSide,_vehicle,_colorIndex] remoteExecCall ["HC_fnc_vehicleCreate",HC_Life];
  141.         } else {
  142.             [(getPlayerUID player),playerSide,_vehicle,_colorIndex] remoteExecCall ["TON_fnc_vehicleCreate",RSERV];
  143.         };
  144.     };
  145. };
  146.  
  147. if (LIFE_SETTINGS(getNumber,"player_advancedLog") isEqualTo 1) then {
  148.     if (LIFE_SETTINGS(getNumber,"battlEye_friendlyLogging") isEqualTo 1) then {
  149.         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];
  150.     } else {
  151.         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];
  152.     };
  153.     publicVariableServer "advanced_log";
  154. };
  155.  
  156. _box = boundingBox _vehicle;    
  157. _offset = _box select 1;  //Gets an array with the maximum bounding values  
  158. _offset = _offset select 2; //Gets the Maxmimum Z height  
  159. _offset = _offset + 0.8; //Just a few inches more…  
  160.  
  161. _sp = visiblePosition _vehicle;  
  162. _sp = _sp vectorAdd [0,0,_offset];  
  163. _vh = createVehicle ["Sign_Arrow_Large_F", _sp ,[],0,"NONE"];  
  164. _vh setPos _sp;  
  165.  
  166. [0] call SOCK_fnc_updatePartial;  
  167. closeDialog 0; //Exit the menu.  
  168. true;  
  169.  
  170. sleep 10;  
  171. deleteVehicle _vh;
RAW Paste Data
Top