Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- File: fn_spawnVehicle.sqf
- Author: Bryan "Tonic" Boardwine + Eagledude4
- Description:
- Spawns vehicles from sql table data
- */
- private["_queryResult","_queryResult2","_query","_query2","_uid","_class","_plate","_color","_pos","_dir","_owners","_impounded","_priceList","_vehicle"];
- _query = "SELECT id FROM vehicles WHERE impounded='0'";
- waitUntil{!DB_Async_Active};
- _tickTime = diag_tickTime;
- _queryResult = [_query, 2, true] call DB_fnc_asyncCall;
- if(count _queryResult == 0) exitWith {diag_log "No vehicles to spawn."};
- diag_log "------------- Vehicle Query Request -------------";
- diag_log format ["Checking %1 vehicles for impound...", count _queryResult];
- _impoundCount = 0;
- {
- _query2 = format["SELECT side, classname, pid, plate, color, gear, inventory, pos, dir, owners FROM vehicles WHERE id='%1'", _x select 0];
- waitUntil{!DB_Async_Active};
- _queryResult2 = [_query2, 2] call DB_fnc_asyncCall;
- diag_log format ["spawnVehicle query: %1", _queryResult2];
- //Assign Vars
- _uid = _queryResult2 select 2;
- _plate = _queryResult2 select 3;
- _pos = _queryResult2 select 7;
- _pos = [_pos] call DB_fnc_mresToArray;
- if(typeName _pos == "STRING") then {_pos = call compile format["%1", _pos];};
- //Put vehicles in impound if near spawn
- _spawns = [
- "civ_car_1","civ_car_1_1","civ_car_2","civ_car_3",
- "civ_truck_1","civ_truck_1_1","civ_truck_2","civ_truck_2_1","civ_truck_3","civ_truck_3_1",
- "reb_v_1_1","reb_v_1_2","reb_v_1_3","reb_v_2_1","reb_v_2_2","reb_v_2_3",
- "civ_ship_1","civ_ship_2","civ_ship_3",
- "civ_air_1","civ_ship_2","civ_ship_3",
- "kart_shop_1"
- ];
- {
- if ((_pos distance [(getMarkerPos _x) select 0, (getMarkerPos _x) select 1, _pos select 2]) < 10) then { //_pos is ASL while getMarkerPos is not
- _query = format["UPDATE vehicles SET impounded='1' WHERE pid='%1' AND plate='%2'",_uid,_plate];
- waitUntil {!DB_Async_Active};
- _thread = [_query,1] call DB_fnc_asyncCall;
- _impoundCount = _impoundCount + 1;
- };
- } forEach _spawns;
- } forEach _queryResult;
- diag_log format ["Impounded %1 vehicles", _impoundCount];
- _query = "SELECT id FROM vehicles WHERE impounded='0'";
- waitUntil{!DB_Async_Active};
- _tickTime = diag_tickTime;
- _queryResult = [_query, 2, true] call DB_fnc_asyncCall;
- if(count _queryResult == 0) exitWith {diag_log "No vehicles to spawn."};
- diag_log "------------- Vehicle Query Request -------------";
- diag_log format ["Attempting to spawn %1 vehicles...", count _queryResult];
- {
- _query2 = format["SELECT side, classname, pid, plate, color, gear, inventory, pos, dir, owners FROM vehicles WHERE id='%1'", _x select 0];
- waitUntil{!DB_Async_Active};
- _queryResult2 = [_query2, 2] call DB_fnc_asyncCall;
- diag_log format ["spawnVehicle query: %1", _queryResult2];
- //Assign Vars
- _side = _queryResult2 select 0;
- _class = _queryResult2 select 1;
- _uid = _queryResult2 select 2;
- _plate = _queryResult2 select 3;
- _color = _queryResult2 select 4;
- _gear = _queryResult2 select 5;
- _gear = [_gear] call DB_fnc_mresToArray;
- if(typeName _gear == "STRING") then {_gear = call compile format["%1", _gear];};
- _inv = _queryResult2 select 6;
- _inv = [_inv] call DB_fnc_mresToArray;
- if(typeName _inv == "STRING") then {_inv = call compile format["%1", _inv];};
- _pos = _queryResult2 select 7;
- _pos = [_pos] call DB_fnc_mresToArray;
- if(typeName _pos == "STRING") then {_pos = call compile format["%1", _pos];};
- _dir = _queryResult2 select 8;
- _owners = _queryResult2 select 9;
- _owners = [_owners] call DB_fnc_mresToArray;
- if(typeName _owners == "STRING") then {_owners = call compile format["%1", _owners];};
- _vehicle = _class createVehicle _pos;
- waitUntil {!isNil "_vehicle" && {!isNull _vehicle}};
- _vehicle allowDamage false;
- _vehicle setPosASL _pos;
- _vehicle setVectorUp (surfaceNormal _pos);
- _vehicle setDir _dir;
- _vehicle lock 2;
- [_vehicle] execVM "scripts\IgiLoad\IgiLoad.sqf";
- if (count _gear > 0) then {
- /*_weaps = _gear select 0;
- diag_log _weaps;
- if (count (_weaps select 0) > 0) then {
- for "_i" from 0 to (count (_weaps select 0)) -1 do {
- _weap = (_weaps select 0) select _i;
- _amount = (_weaps select 1) select _i;
- _vehicle addWeaponCargoGlobal [_weap, _amount];
- diag_log format ["Weap: %1, WeapType: %2 | Amount: %3, AmountType: %4",_weap,typeName _weap,_amount,typeName _amount];
- };
- };
- _mags = _gear select 1;
- diag_log _mags;
- if (count (_mags select 0) > 0) then {
- for "_i" from 0 to (count (_mags select 0)) -1 do {
- _mag = (_mags select 0) select _i;
- _amount = (_mags select 1) select _i;
- _vehicle addMagazineCargoGlobal [_mag, _amount];
- diag_log format ["Mag: %1, WeapType: %2 | Amount: %3, AmountType: %4",_mag,typeName _mag,_amount,typeName _amount];
- };
- };
- _items = _gear select 2;
- diag_log _items;
- if (count (_items select 0) > 0) then {
- for "_i" from 0 to (count (_items select 0)) -1 do {
- _item = (_items select 0) select _i;
- _amount = (_items select 1) select _i;
- _vehicle addItemCargoGlobal [_item, _amount];
- diag_log format ["Item: %1, WeapType: %2 | Amount: %3, AmountType: %4",_item,typeName _item,_amount,typeName _amount];
- };
- };*/
- _backpacks = _gear select 3;
- if (count (_backpacks select 0) > 0) then {
- for "_i" from 0 to (count (_backpacks select 0)) -1 do {
- _backpack = (_backpacks select 0) select _i;
- _amount = (_backpacks select 1) select _i;
- _vehicle addBackpackCargoGlobal [_backpack, _amount];
- };
- };
- };
- [[_vehicle,_color],"life_fnc_colorVehicle",nil,false] spawn life_fnc_MP;
- _vehicle setVariable["vehicle_info_owners",_owners,true];
- _vehicle setVariable["dbInfo",[_uid,_plate],true];
- _vehicle setVariable["can_outside",false,true];
- _vehicle addEventHandler["Killed","_this spawn TON_fnc_vehicleDead"];
- _vehicle addEventHandler["engine","_this spawn TON_fnc_vehicleEngine"];
- _vehicle addEventHandler["getOut","_this spawn life_fnc_getOut"];
- [_vehicle] call life_fnc_clearVehicleAmmo;
- //Sets of animations
- switch (_class) do {
- case "B_Heli_Light_01_F": {
- [_vehicle,"civ_littlebird",true] spawn life_fnc_vehicleAnimate;
- };
- case "C_Offroad_01_repair_F": {
- [_vehicle,"civ_repairoffroad",true] spawn life_fnc_vehicleAnimate;
- };
- };
- sleep 0.5;
- _house = nearestBuilding (getPosASL _vehicle);
- _dammage = {
- if ((typeOf _house) == "Land_i_Shed_Ind_F") then {
- false
- } else {
- true
- };
- };
- _vehicle allowDamage (call _dammage);
- } forEach _queryResult;
- diag_log format ["%1 vehicles spawned sucessfully!", count _queryResult];
- diag_log format["Time to complete: %1 (in seconds)",(diag_tickTime - _tickTime)];
- diag_log "------------------------------------------------";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement