Advertisement
RickyMeekle123

Untitled

May 22nd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.59 KB | None | 0 0
  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. private["_vid","_sp","_pid","_query","_sql","_vehicle","_nearVehicles","_name","_side","_tickTime","_dir","_servIndex","_damage","_wasIllegal","_location","_thread"];
  11. _vid = [_this,0,-1,[0]] call BIS_fnc_param;
  12. _pid = [_this,1,"",[""]] call BIS_fnc_param;
  13. _sp = [_this,2,[],[[],""]] call BIS_fnc_param;
  14. _unit = [_this,3,ObjNull,[ObjNull]] call BIS_fnc_param;
  15. _price = [_this,4,0,[0]] call BIS_fnc_param;
  16. _dir = [_this,5,0,[0]] call BIS_fnc_param;
  17. _spawntext = _this select 6;
  18. _unit_return = _unit;
  19. _name = name _unit;
  20. _side = side _unit;
  21. _unit = owner _unit;
  22.  
  23. if (_vid isEqualTo -1 || _pid isEqualTo "") exitWith {};
  24. if (_vid in serv_sv_use) exitWith {};
  25. serv_sv_use pushBack _vid;
  26. _servIndex = serv_sv_use find _vid;
  27.  
  28. _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];
  29.  
  30. _tickTime = diag_tickTime;
  31. _queryResult = [_query,2] call DB_fnc_asyncCall;
  32.  
  33. if (EXTDB_SETTING(getNumber,"DebugMode") isEqualTo 1) then {
  34. diag_log "------------- Client Query Request -------------";
  35. diag_log format["QUERY: %1",_query];
  36. diag_log format["Time to complete: %1 (in seconds)",(diag_tickTime - _tickTime)];
  37. diag_log format["Result: %1",_queryResult];
  38. diag_log "------------------------------------------------";
  39. };
  40.  
  41. if (_queryResult isEqualType "") exitWith {};
  42.  
  43. _vInfo = _queryResult;
  44. if (isNil "_vInfo") exitWith {serv_sv_use deleteAt _servIndex;};
  45. if (count _vInfo isEqualTo 0) exitWith {serv_sv_use deleteAt _servIndex;};
  46.  
  47. if ((_vInfo select 5) isEqualTo 0) exitWith {
  48. serv_sv_use deleteAt _servIndex;
  49. [1,format[(localize "STR_Garage_SQLError_Destroyed"),(_vInfo select 2)]] remoteExecCall ["life_fnc_broadcast",_unit];
  50. };
  51.  
  52. if ((_vInfo select 6) isEqualTo 1) exitWith {
  53. serv_sv_use deleteAt _servIndex;
  54. [1,format[(localize "STR_Garage_SQLError_Active"),(_vInfo select 2)]] remoteExecCall ["life_fnc_broadcast",_unit];
  55. };
  56.  
  57. if (!(_sp isEqualType "")) then {
  58. _nearVehicles = nearestObjects[_sp,["Car","Air","Ship"],10];
  59. } else {
  60. _nearVehicles = [];
  61. };
  62.  
  63. if (count _nearVehicles > 0) exitWith {
  64. serv_sv_use deleteAt _servIndex;
  65. [_price,_unit_return] remoteExecCall ["life_fnc_garageRefund",_unit];
  66. [1,(localize "STR_Garage_SpawnPointError")] remoteExecCall ["life_fnc_broadcast",_unit];
  67. };
  68.  
  69. _query = format ["UPDATE vehicles SET active='1',fourriere='0', damage='""[]""' WHERE pid='%1' AND id='%2'",_pid,_vid];
  70.  
  71. _trunk = [(_vInfo select 9)] call DB_fnc_mresToArray;
  72. _gear = [(_vInfo select 10)] call DB_fnc_mresToArray;
  73. _damage = [(_vInfo select 12)] call DB_fnc_mresToArray;
  74. _wasIllegal = (_vInfo select 13);
  75. _wasIllegal = if (_wasIllegal isEqualTo 1) then { true } else { false };
  76.  
  77. [_query,1] call DB_fnc_asyncCall;
  78. if (_sp isEqualType "") then {
  79. _vehicle = createVehicle[(_vInfo select 2),[0,0,999],[],0,"NONE"];
  80. waitUntil {!isNil "_vehicle" && {!isNull _vehicle}};
  81. _vehicle allowDamage false;
  82. _hs = nearestObjects[getMarkerPos _sp,["Land_Hospital_side2_F"],50] select 0;
  83. _vehicle setPosATL (_hs modelToWorld [-0.4,-4,12.65]);
  84. uiSleep 0.6;
  85. } else {
  86. _vehicle = createVehicle [(_vInfo select 2),_sp,[],0,"NONE"];
  87. waitUntil {!isNil "_vehicle" && {!isNull _vehicle}};
  88. _vehicle allowDamage false;
  89. _vehicle setPos _sp;
  90. _vehicle setVectorUp (surfaceNormal _sp);
  91. _vehicle setDir _dir;
  92. };
  93. _vehicle allowDamage true;
  94. //Send keys over the network.
  95. [_vehicle] remoteExecCall ["life_fnc_addVehicle2Chain",_unit];
  96. [_pid,_side,_vehicle,1] call TON_fnc_keyManagement;
  97. _vehicle lock 2;
  98. //Reskin the vehicle
  99. [_vehicle,(_vInfo select 8)] remoteExecCall ["life_fnc_colorVehicle",_unit];
  100. _vehicle setVariable["vehicle_info_owners",[[_pid,_name]],true];
  101. _vehicle setVariable["dbInfo",[(_vInfo select 4),(_vInfo select 7)],true];
  102. _vehicle disableTIEquipment true; //No Thermals.. They're cheap but addictive.
  103. [_vehicle] call life_fnc_clearVehicleAmmo;
  104.  
  105. // Avoid problems if u keep changing which stuff to save!
  106. if (LIFE_SETTINGS(getNumber,"save_vehicle_virtualItems") isEqualTo 1) then {
  107. _vehicle setVariable["Trunk",_trunk,true];
  108. if (_wasIllegal) then {
  109. if (_sp isEqualType "") then {
  110. _location= (nearestLocations [getPos _sp,["NameCityCapital","NameCity","NameVillage"],1000]) select 0;
  111. } else {
  112. _location= (nearestLocations [_sp,["NameCityCapital","NameCity","NameVillage"],1000]) select 0;
  113. };
  114. _location = text _location;
  115. _msg = format[localize "STR_NOTF_BlackListedVehicle", _location ,_name];
  116.  
  117. [1,_msg,false] remoteExecCall ["life_fnc_broadcast",west];
  118. _query = format["UPDATE vehicles SET blacklist='0' WHERE id='%1' AND pid='%2'",_vid,_pid];
  119. _thread = [_query,1] call DB_fnc_asyncCall;
  120. };
  121. }else{
  122. _vehicle setVariable["Trunk",[[],0],true];
  123. };
  124.  
  125. if (LIFE_SETTINGS(getNumber,"save_vehicle_fuel") isEqualTo 1) then {
  126. _vehicle setFuel (_vInfo select 11);
  127. }else{
  128. _vehicle setFuel 1;
  129. };
  130.  
  131. if (count _gear > 0 && (LIFE_SETTINGS(getNumber,"save_vehicle_inventory") isEqualTo 1)) then {
  132. _items = _gear select 0;
  133. _mags = _gear select 1;
  134. _weapons = _gear select 2;
  135. _backpacks = _gear select 3;
  136.  
  137. for "_i" from 0 to ((count (_items select 0)) - 1) do {
  138. _vehicle addItemCargoGlobal [((_items select 0) select _i), ((_items select 1) select _i)];
  139. };
  140. for "_i" from 0 to ((count (_mags select 0)) - 1) do {
  141. _vehicle addMagazineCargoGlobal [((_mags select 0) select _i), ((_mags select 1) select _i)];
  142. };
  143. for "_i" from 0 to ((count (_weapons select 0)) - 1) do {
  144. _vehicle addWeaponCargoGlobal [((_weapons select 0) select _i), ((_weapons select 1) select _i)];
  145. };
  146. for "_i" from 0 to ((count (_backpacks select 0)) - 1) do {
  147. _vehicle addBackpackCargoGlobal [((_backpacks select 0) select _i), ((_backpacks select 1) select _i)];
  148. };
  149. };
  150.  
  151. if (count _damage > 0 && (LIFE_SETTINGS(getNumber,"save_vehicle_damage") isEqualTo 1)) then {
  152. _parts = getAllHitPointsDamage _vehicle;
  153.  
  154. for "_i" from 0 to ((count _damage) - 1) do {
  155. _vehicle setHitPointDamage [format["%1",((_parts select 0) select _i)],_damage select _i];
  156. };
  157. };
  158.  
  159. //Sets of animations
  160. if ((_vInfo select 1) isEqualTo "civ" && (_vInfo select 2) isEqualTo "B_Heli_Light_01_F" && !((_vInfo select 8) isEqualTo 13)) then {
  161. [_vehicle,"civ_littlebird",true] remoteExecCall ["life_fnc_vehicleAnimate",_unit];
  162. };
  163.  
  164. 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","C_Hatchback_01_F"]) then {
  165. [_vehicle,"cop_offroad",true] remoteExecCall ["life_fnc_vehicleAnimate",_unit];
  166. };
  167.  
  168. if ((_vInfo select 1) isEqualTo "med" && ((_vInfo select 2)) in ["C_Offroad_01_F","C_SUV_01_F","I_C_Offroad_02_unarmed_F","C_Offroad_02_unarmed_F","C_Hatchback_01_sport_F","B_MRAP_01_F","C_Hatchback_01_F","I_MRAP_03_F","O_MRAP_02_F","B_Heli_Light_01_F","O_Heli_Light_02_unarmed_F","I_Heli_light_03_unarmed_F","C_Boat_Civil_01_police_F"]) then {
  169. [_vehicle,"med_offroad",true] remoteExecCall ["life_fnc_vehicleAnimate",_unit];
  170. };
  171.  
  172. [1,_spawntext] remoteExecCall ["life_fnc_broadcast",_unit];
  173. serv_sv_use deleteAt _servIndex;
  174. _vehicle setVariable ["vehicle_info_vid",_vid,true];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement