Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.68 KB | None | 0 0
  1. /*
  2. File: fn_spawnVehicle.sqf
  3. Author: Bryan "Tonic" Boardwine + Eagledude4
  4.  
  5. Description:
  6. Spawns vehicles from sql table data
  7. */
  8.  
  9. private["_queryResult","_queryResult2","_query","_query2","_uid","_class","_plate","_color","_pos","_dir","_owners","_impounded","_priceList","_vehicle"];
  10.  
  11. _query = "SELECT id FROM vehicles WHERE impounded='0'";
  12. waitUntil{!DB_Async_Active};
  13. _tickTime = diag_tickTime;
  14. _queryResult = [_query, 2, true] call DB_fnc_asyncCall;
  15. if(count _queryResult == 0) exitWith {diag_log "No vehicles to spawn."};
  16. diag_log "------------- Vehicle Query Request -------------";
  17. diag_log format ["Checking %1 vehicles for impound...", count _queryResult];
  18. _impoundCount = 0;
  19. {
  20. _query2 = format["SELECT side, classname, pid, plate, color, gear, inventory, pos, dir, owners FROM vehicles WHERE id='%1'", _x select 0];
  21. waitUntil{!DB_Async_Active};
  22. _queryResult2 = [_query2, 2] call DB_fnc_asyncCall;
  23. diag_log format ["spawnVehicle query: %1", _queryResult2];
  24.  
  25. //Assign Vars
  26. _uid = _queryResult2 select 2;
  27. _plate = _queryResult2 select 3;
  28.  
  29. _pos = _queryResult2 select 7;
  30. _pos = [_pos] call DB_fnc_mresToArray;
  31. if(typeName _pos == "STRING") then {_pos = call compile format["%1", _pos];};
  32.  
  33.  
  34. //Put vehicles in impound if near spawn
  35.  
  36. _spawns = [
  37. "civ_car_1","civ_car_1_1","civ_car_2","civ_car_3",
  38. "civ_truck_1","civ_truck_1_1","civ_truck_2","civ_truck_2_1","civ_truck_3","civ_truck_3_1",
  39. "reb_v_1_1","reb_v_1_2","reb_v_1_3","reb_v_2_1","reb_v_2_2","reb_v_2_3",
  40. "civ_ship_1","civ_ship_2","civ_ship_3",
  41. "civ_air_1","civ_ship_2","civ_ship_3",
  42. "kart_shop_1"
  43. ];
  44. {
  45. if ((_pos distance [(getMarkerPos _x) select 0, (getMarkerPos _x) select 1, _pos select 2]) < 10) then { //_pos is ASL while getMarkerPos is not
  46. _query = format["UPDATE vehicles SET impounded='1' WHERE pid='%1' AND plate='%2'",_uid,_plate];
  47. waitUntil {!DB_Async_Active};
  48. _thread = [_query,1] call DB_fnc_asyncCall;
  49. _impoundCount = _impoundCount + 1;
  50. };
  51. } forEach _spawns;
  52. } forEach _queryResult;
  53. diag_log format ["Impounded %1 vehicles", _impoundCount];
  54.  
  55. _query = "SELECT id FROM vehicles WHERE impounded='0'";
  56. waitUntil{!DB_Async_Active};
  57. _tickTime = diag_tickTime;
  58. _queryResult = [_query, 2, true] call DB_fnc_asyncCall;
  59. if(count _queryResult == 0) exitWith {diag_log "No vehicles to spawn."};
  60. diag_log "------------- Vehicle Query Request -------------";
  61. diag_log format ["Attempting to spawn %1 vehicles...", count _queryResult];
  62. {
  63. _query2 = format["SELECT side, classname, pid, plate, color, gear, inventory, pos, dir, owners FROM vehicles WHERE id='%1'", _x select 0];
  64. waitUntil{!DB_Async_Active};
  65. _queryResult2 = [_query2, 2] call DB_fnc_asyncCall;
  66. diag_log format ["spawnVehicle query: %1", _queryResult2];
  67.  
  68. //Assign Vars
  69. _side = _queryResult2 select 0;
  70. _class = _queryResult2 select 1;
  71. _uid = _queryResult2 select 2;
  72. _plate = _queryResult2 select 3;
  73. _color = _queryResult2 select 4;
  74.  
  75. _gear = _queryResult2 select 5;
  76. _gear = [_gear] call DB_fnc_mresToArray;
  77. if(typeName _gear == "STRING") then {_gear = call compile format["%1", _gear];};
  78.  
  79. _inv = _queryResult2 select 6;
  80. _inv = [_inv] call DB_fnc_mresToArray;
  81. if(typeName _inv == "STRING") then {_inv = call compile format["%1", _inv];};
  82.  
  83. _pos = _queryResult2 select 7;
  84. _pos = [_pos] call DB_fnc_mresToArray;
  85. if(typeName _pos == "STRING") then {_pos = call compile format["%1", _pos];};
  86.  
  87. _dir = _queryResult2 select 8;
  88.  
  89. _owners = _queryResult2 select 9;
  90. _owners = [_owners] call DB_fnc_mresToArray;
  91. if(typeName _owners == "STRING") then {_owners = call compile format["%1", _owners];};
  92.  
  93.  
  94. _vehicle = _class createVehicle _pos;
  95. waitUntil {!isNil "_vehicle" && {!isNull _vehicle}};
  96. _vehicle allowDamage false;
  97. _vehicle setPosASL _pos;
  98. _vehicle setVectorUp (surfaceNormal _pos);
  99. _vehicle setDir _dir;
  100. _vehicle lock 2;
  101.  
  102. [_vehicle] execVM "scripts\IgiLoad\IgiLoad.sqf";
  103.  
  104. if (count _gear > 0) then {
  105. /*_weaps = _gear select 0;
  106. diag_log _weaps;
  107. if (count (_weaps select 0) > 0) then {
  108. for "_i" from 0 to (count (_weaps select 0)) -1 do {
  109. _weap = (_weaps select 0) select _i;
  110. _amount = (_weaps select 1) select _i;
  111.  
  112. _vehicle addWeaponCargoGlobal [_weap, _amount];
  113. diag_log format ["Weap: %1, WeapType: %2 | Amount: %3, AmountType: %4",_weap,typeName _weap,_amount,typeName _amount];
  114. };
  115. };
  116.  
  117. _mags = _gear select 1;
  118. diag_log _mags;
  119. if (count (_mags select 0) > 0) then {
  120. for "_i" from 0 to (count (_mags select 0)) -1 do {
  121. _mag = (_mags select 0) select _i;
  122. _amount = (_mags select 1) select _i;
  123.  
  124. _vehicle addMagazineCargoGlobal [_mag, _amount];
  125. diag_log format ["Mag: %1, WeapType: %2 | Amount: %3, AmountType: %4",_mag,typeName _mag,_amount,typeName _amount];
  126. };
  127. };
  128.  
  129. _items = _gear select 2;
  130. diag_log _items;
  131. if (count (_items select 0) > 0) then {
  132. for "_i" from 0 to (count (_items select 0)) -1 do {
  133. _item = (_items select 0) select _i;
  134. _amount = (_items select 1) select _i;
  135.  
  136. _vehicle addItemCargoGlobal [_item, _amount];
  137. diag_log format ["Item: %1, WeapType: %2 | Amount: %3, AmountType: %4",_item,typeName _item,_amount,typeName _amount];
  138. };
  139. };*/
  140.  
  141. _backpacks = _gear select 3;
  142. if (count (_backpacks select 0) > 0) then {
  143. for "_i" from 0 to (count (_backpacks select 0)) -1 do {
  144. _backpack = (_backpacks select 0) select _i;
  145. _amount = (_backpacks select 1) select _i;
  146.  
  147. _vehicle addBackpackCargoGlobal [_backpack, _amount];
  148. };
  149. };
  150. };
  151.  
  152. [[_vehicle,_color],"life_fnc_colorVehicle",nil,false] spawn life_fnc_MP;
  153.  
  154. _vehicle setVariable["vehicle_info_owners",_owners,true];
  155. _vehicle setVariable["dbInfo",[_uid,_plate],true];
  156. _vehicle setVariable["can_outside",false,true];
  157.  
  158. _vehicle addEventHandler["Killed","_this spawn TON_fnc_vehicleDead"];
  159. _vehicle addEventHandler["engine","_this spawn TON_fnc_vehicleEngine"];
  160. _vehicle addEventHandler["getOut","_this spawn life_fnc_getOut"];
  161.  
  162. [_vehicle] call life_fnc_clearVehicleAmmo;
  163.  
  164. //Sets of animations
  165. switch (_class) do {
  166. case "B_Heli_Light_01_F": {
  167. [_vehicle,"civ_littlebird",true] spawn life_fnc_vehicleAnimate;
  168. };
  169. case "C_Offroad_01_repair_F": {
  170. [_vehicle,"civ_repairoffroad",true] spawn life_fnc_vehicleAnimate;
  171. };
  172. };
  173.  
  174. sleep 0.5;
  175. _house = nearestBuilding (getPosASL _vehicle);
  176. _dammage = {
  177. if ((typeOf _house) == "Land_i_Shed_Ind_F") then {
  178. false
  179. } else {
  180. true
  181. };
  182. };
  183. _vehicle allowDamage (call _dammage);
  184. } forEach _queryResult;
  185.  
  186. diag_log format ["%1 vehicles spawned sucessfully!", count _queryResult];
  187. diag_log format["Time to complete: %1 (in seconds)",(diag_tickTime - _tickTime)];
  188. diag_log "------------------------------------------------";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement