Guest User

My garage is broken!!

a guest
Apr 27th, 2020
27
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "\life_server\script_macros.hpp"
  2. /*
  3. File: fn_spawnVehicle.sqf
  4. Author: Bryan "Tonic" Boardwine
  5.  
  6. Description:
  7. Sends the query request to the database, if an array is returned then it creates
  8. the vehicle if it's not in use or dead.
  9. */
  10. params [
  11. ["_vid", -1, [0]],
  12. ["_pid", "", [""]],
  13. ["_sp", [], [[],""]],
  14. ["_unit", objNull, [objNull]],
  15. ["_price", 0, [0]],
  16. ["_dir", 0, [0]],
  17. "_spawntext"
  18. ];
  19.  
  20. private _unit_return = _unit;
  21. private _name = name _unit;
  22. private _side = side _unit;
  23. _unit = owner _unit;
  24.  
  25. if (_vid isEqualTo -1 || {_pid isEqualTo ""}) exitWith {};
  26. if (_vid in serv_sv_use) exitWith {};
  27. serv_sv_use pushBack _vid;
  28.  
  29. private _servIndex = serv_sv_use find _vid;
  30.  
  31. private _query = format ["SELECT id, side, classname, type, pid, alive, active, plate, color, inventory, gear, fuel, damage, blacklist FROM vehicles WHERE id='%1' AND pid='%2'",_vid,_pid];
  32.  
  33. private _tickTime = diag_tickTime;
  34. private _queryResult = [_query,2] call DB_fnc_asyncCall;
  35.  
  36. if (EXTDB_SETTING(getNumber,"DebugMode") isEqualTo 1) then {
  37. diag_log "------------- Client Query Request -------------";
  38. diag_log format ["QUERY: %1",_query];
  39. diag_log format ["Time to complete: %1 (in seconds)",(diag_tickTime - _tickTime)];
  40. diag_log format ["Result: %1",_queryResult];
  41. diag_log "------------------------------------------------";
  42. };
  43.  
  44. if (_queryResult isEqualType "") exitWith {};
  45.  
  46. private _vInfo = _queryResult;
  47. if (isNil "_vInfo") exitWith {serv_sv_use deleteAt _servIndex;};
  48. if (count _vInfo isEqualTo 0) exitWith {serv_sv_use deleteAt _servIndex;};
  49.  
  50. if ((_vInfo select 5) isEqualTo 0) exitWith {
  51. serv_sv_use deleteAt _servIndex;
  52. [1,"STR_Garage_SQLError_Destroyed",true,[_vInfo select 2]] remoteExecCall ["life_fnc_broadcast",_unit];
  53. };
  54.  
  55. if ((_vInfo select 6) isEqualTo 1) exitWith {
  56. serv_sv_use deleteAt _servIndex;
  57. [1,"STR_Garage_SQLError_Active",true,[_vInfo select 2]] remoteExecCall ["life_fnc_broadcast",_unit];
  58. };
  59.  
  60. private "_nearVehicles";
  61. if !(_sp isEqualType "") then {
  62. _nearVehicles = nearestObjects[_sp,["Car","Air","Ship"],10];
  63. } else {
  64. _nearVehicles = [];
  65. };
  66.  
  67. if (count _nearVehicles > 0) exitWith {
  68. serv_sv_use deleteAt _servIndex;
  69. [_price,_unit_return] remoteExecCall ["life_fnc_garageRefund",_unit];
  70. [1,"STR_Garage_SpawnPointError",true] remoteExecCall ["life_fnc_broadcast",_unit];
  71. };
  72.  
  73. _query = format ["UPDATE vehicles SET active='1', damage='""[]""' WHERE pid='%1' AND id='%2'",_pid,_vid];
  74.  
  75. private _trunk = [(_vInfo select 9)] call DB_fnc_mresToArray;
  76. private _gear = [(_vInfo select 10)] call DB_fnc_mresToArray;
  77. private _damage = [call compile (_vInfo select 12)] call DB_fnc_mresToArray;
  78. private _wasIllegal = _vInfo select 13;
  79. _wasIllegal = if (_wasIllegal isEqualTo 1) then { true } else { false };
  80.  
  81. [_query,1] call DB_fnc_asyncCall;
  82.  
  83. private "_vehicle";
  84. if (_sp isEqualType "") then {
  85. _vehicle = createVehicle[(_vInfo select 2),[0,0,999],[],0,"NONE"];
  86. waitUntil {!isNil "_vehicle" && {!isNull _vehicle}};
  87. _vehicle allowDamage false;
  88. _hs = nearestObjects[getMarkerPos _sp,["Land_Hospital_side2_F"],50] select 0;
  89. _vehicle setPosATL (_hs modelToWorld [-0.4,-4,12.65]);
  90. uiSleep 0.6;
  91. } else {
  92. _vehicle = createVehicle [(_vInfo select 2),_sp,[],0,"NONE"];
  93. waitUntil {!isNil "_vehicle" && {!isNull _vehicle}};
  94. _vehicle allowDamage false;
  95. _vehicle setPos _sp;
  96. _vehicle setVectorUp (surfaceNormal _sp);
  97. _vehicle setDir _dir;
  98. };
  99. _vehicle allowDamage true;
  100. //Send keys over the network.
  101. [_vehicle] remoteExecCall ["life_fnc_addVehicle2Chain",_unit];
  102. [_pid,_side,_vehicle,1] call TON_fnc_keyManagement;
  103. _vehicle lock 2;
  104. //Reskin the vehicle
  105. [_vehicle,(_vInfo select 8)] remoteExecCall ["life_fnc_colorVehicle",_unit];
  106. _vehicle setVariable ["vehicle_info_owners",[[_pid,_name]],true];
  107. _vehicle setVariable ["dbInfo",[(_vInfo select 4),(_vInfo select 7)],true];
  108. _vehicle disableTIEquipment true; //No Thermals.. They're cheap but addictive.
  109. [_vehicle] call life_fnc_clearVehicleAmmo;
  110.  
  111. if (LIFE_SETTINGS(getNumber,"save_vehicle_virtualItems") isEqualTo 1) then {
  112.  
  113. _vehicle setVariable ["Trunk",_trunk,true];
  114.  
  115. if (_wasIllegal) then {
  116. private _refPoint = if (_sp isEqualType "") then {getMarkerPos _sp;} else {_sp;};
  117.  
  118. private _distance = 100000;
  119. private "_location";
  120.  
  121. {
  122. private _tempLocation = nearestLocation [_refPoint, _x];
  123. private _tempDistance = _refPoint distance _tempLocation;
  124.  
  125. if (_tempDistance < _distance) then {
  126. _location = _tempLocation;
  127. _distance = _tempDistance;
  128. };
  129. false
  130.  
  131. } count ["NameCityCapital", "NameCity", "NameVillage"];
  132.  
  133. _location = text _location;
  134. [1,"STR_NOTF_BlackListedVehicle",true,[_location,_name]] remoteExecCall ["life_fnc_broadcast",west];
  135.  
  136. _query = format ["UPDATE vehicles SET blacklist='0' WHERE id='%1' AND pid='%2'",_vid,_pid];
  137. [_query,1] call DB_fnc_asyncCall;
  138. };
  139. } else {
  140. _vehicle setVariable ["Trunk",[[],0],true];
  141. };
  142.  
  143. if (LIFE_SETTINGS(getNumber,"save_vehicle_fuel") isEqualTo 1) then {
  144. _vehicle setFuel (_vInfo select 11);
  145. }else{
  146. _vehicle setFuel 1;
  147. };
  148.  
  149. if (count _gear > 0 && (LIFE_SETTINGS(getNumber,"save_vehicle_inventory") isEqualTo 1)) then {
  150. _items = _gear select 0;
  151. _mags = _gear select 1;
  152. _weapons = _gear select 2;
  153. _backpacks = _gear select 3;
  154.  
  155. for "_i" from 0 to ((count (_items select 0)) - 1) do {
  156. _vehicle addItemCargoGlobal [((_items select 0) select _i), ((_items select 1) select _i)];
  157. };
  158. for "_i" from 0 to ((count (_mags select 0)) - 1) do {
  159. _vehicle addMagazineCargoGlobal [((_mags select 0) select _i), ((_mags select 1) select _i)];
  160. };
  161. for "_i" from 0 to ((count (_weapons select 0)) - 1) do {
  162. _vehicle addWeaponCargoGlobal [((_weapons select 0) select _i), ((_weapons select 1) select _i)];
  163. };
  164. for "_i" from 0 to ((count (_backpacks select 0)) - 1) do {
  165. _vehicle addBackpackCargoGlobal [((_backpacks select 0) select _i), ((_backpacks select 1) select _i)];
  166. };
  167. };
  168.  
  169. if (count _damage > 0 && (LIFE_SETTINGS(getNumber,"save_vehicle_damage") isEqualTo 1)) then {
  170. _parts = getAllHitPointsDamage _vehicle;
  171.  
  172. for "_i" from 0 to ((count _damage) - 1) do {
  173. _vehicle setHitPointDamage [format ["%1",((_parts select 0) select _i)],_damage select _i];
  174. };
  175. };
  176.  
  177. //Sets of animations
  178. if ((_vInfo select 1) isEqualTo "civ" && (_vInfo select 2) isEqualTo "B_Heli_Light_01_F" && !((_vInfo select 8) isEqualTo 13)) then {
  179. [_vehicle,"civ_littlebird",true] remoteExecCall ["life_fnc_vehicleAnimate",_unit];
  180. };
  181.  
  182. if ((_vInfo select 1) isEqualTo "cop" && ((_vInfo select 2)) in ["C_Offroad_01_F","B_MRAP_01_F","C_SUV_01_F","C_Hatchback_01_sport_F","B_Heli_Light_01_F","B_Heli_Transport_01_F"]) then {
  183. [_vehicle,"cop_offroad",true] remoteExecCall ["life_fnc_vehicleAnimate",_unit];
  184. };
  185.  
  186. if ((_vInfo select 1) isEqualTo "med" && (_vInfo select 2) isEqualTo "C_Offroad_01_F") then {
  187. [_vehicle,"med_offroad",true] remoteExecCall ["life_fnc_vehicleAnimate",_unit];
  188. };
  189.  
  190. [1,_spawntext] remoteExecCall ["life_fnc_broadcast",_unit];
  191. serv_sv_use deleteAt _servIndex;
RAW Paste Data