Update ExileServer_object_vehicle_database_load.sqf

This commit is contained in:
Bones50 2017-11-06 13:13:11 +11:00 committed by GitHub
parent 623131b6e2
commit 2dd113a71d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,62 +9,42 @@
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
*/
private["_vehicleID","_data","_position","_vectorDirection","_vectorUp","_pinCode","_texture","_vehicleObject","_lock","_unlockInSafeZonesAfterRestart","_isLocked","_hitpoints","_cargoContainers"];
private["_vehicleID", "_data", "_position", "_vectorDirection", "_vectorUp", "_pinCode", "_texture", "_vehicleObject", "_lock", "_unlockInSafeZonesAfterRestart", "_isLocked", "_hitpoints", "_cargoContainers", "_query"];
_vehicleID = _this;
_data = format ["loadVehicle:%1", _vehicleID] call ExileServer_system_database_query_selectSingle;
_position = [_data select 8, _data select 9, _data select 10];
_vectorDirection = [_data select 11, _data select 12, _data select 13];
_vectorUp = [_data select 14, _data select 15, _data select 16];
//Bones Side Vehicle Check
if ((_vectorUp select 2) == 0) then {_vectorUp set [2,1]};
//end custom
_pinCode = _data select 20;
_texture = _data select 21;
try
{
if !((vectorMagnitude _vectorUp) isEqualTo 1) then
{
throw true;
};
if ((_vectorUp select 0) > 0.95) then
{
throw true;
};
if ((_vectorUp select 1) > 0.95) then
{
throw true;
};
if ((_vectorUp select 2) isEqualTo 0) then
{
throw true;
};
}
catch
{
_vectorUp = [0, 0, 1];
};
_vehicleObject = [(_data select 1), _position, [_vectorDirection, _vectorUp], true,_pinCode] call ExileServer_object_vehicle_createPersistentVehicle;
_vehicleObject setVariable ["ExileDatabaseID", _vehicleID];
_vehicleObject setVariable ["ExileOwnerUID", (_data select 3)];
_vehicleObject setVariable ["ExileMoney", (_data select 23), true];
_lock = (_data select 4);
_query = format["getVehicleAmmo:%1", _vehicleID];
_data1 = (_result select 1) select 0;
_savedMagazines = _data1 select 0;
_vehicle setVehicleAmmoDef 0;
if (typeName _savedMagazines isEqualTo "ARRAY") then
{
if (typeName (_savedMagazines select 0) isEqualTo "ARRAY") then
{
{
_turretPath = _x select 0;
for "_i" from (count _x - 1) to 1 step -1 do
{
_magData = _x select _i;
_magClass = _magData select 0;
_ammoCount = _magData select 1;
_maxMagAmmo = (configFile >> "CfgMagazines" >> _magClass >> "count") call BIS_fnc_getCfgData;
_numMags = ceil (_ammoCount / _maxMagAmmo);
while {_numMags > 1} do
{
_vehicle addMagazineTurret [_magClass, _turretPath];
_numMags = _numMags - 1;
_ammoCount = _ammoCount - _maxMagAmmo;
};
_vehicle setMagazineTurretAmmo [_magClass, _ammoCount, _turretPath];
};
} forEach _savedMagazines;
};
}
else
{
diag_log format["AMMO ERROR - INVALID MAGAZINE SAVED IN DATABASE: %1", _savedMagazines];
diag_log format["AMMO ERROR - Magazines should be saved an array. Blank entries should be: [] Verify your database."];
};
_unlockInSafeZonesAfterRestart = (getNumber (configFile >> "CfgSettings" >> "VehicleSpawn" >> "unlockInSafeZonesAfterRestart")) isEqualTo 1;
_isLocked = (_lock isEqualTo -1);
if (_isLocked) then
@ -123,4 +103,44 @@ if (_vehicleObject call ExileClient_util_world_isInTraderZone) then
{
_vehicleObject allowDamage false;
};
//Bones Ammo Save Addition
_query = format["getVehicleAmmo:%1", _vehicleID] call ExileServer_system_database_query_selectSingle;
_savedMagazines = _query select 0;
_vehicleobject setVehicleAmmoDef 0;
if (typeName _savedMagazines isEqualTo "ARRAY") then
{
if (typeName (_savedMagazines select 0) isEqualTo "ARRAY") then
{
{
_turretPath = _x select 0;
for "_i" from (count _x - 1) to 1 step -1 do
{
_magData = _x select _i;
_magClass = _magData select 0;
_ammoCount = _magData select 1;
_maxMagAmmo = (configFile >> "CfgMagazines" >> _magClass >> "count") call BIS_fnc_getCfgData;
_numMags = ceil (_ammoCount / _maxMagAmmo);
while {_numMags > 1} do
{
_vehicleobject addMagazineTurret [_magClass, _turretPath];
_numMags = _numMags - 1;
_ammoCount = _ammoCount - _maxMagAmmo;
};
_vehicleobject setMagazineTurretAmmo [_magClass, _ammoCount, _turretPath];
};
} forEach _savedMagazines;
};
}
else
{
diag_log format["AMMO ERROR - INVALID MAGAZINE SAVED IN DATABASE: %1", _savedMagazines];
diag_log format["AMMO ERROR - Magazines should be saved an array. Blank entries should be: [] Verify your database."];
};
//End Custom Ammo Save
_vehicleObject