vehicle lock on restart in v1.2

vehicle lock on restart in v1.2

« posted: Jul 21, 2015, 01:19 AM »
Is anyone else having issues with vehicle locking on restart? I implemented everythign the way I had it in v1.1 and vehicles are unlocked after restart.

Everything in vactions is working except this. I have added

Code: [Select]
A3W_fnc_setLockState = { (objectFromNetId (_this select 0)) lock (_this select 1) } call mf_compile;
in global compile and

Code: [Select]

// If vehicle is was locked before restart then restore lockstate and make it untowable/unliftable LouD
if (_veh getVariable "R3F_LOG_disabled") then
{
_veh lock 2;
}
else
{
_veh lock 1;
};

in vload

Am I forgetting something?
  • Offline AgentRev
  • Developer
  • Veteran
  • ******
  • Posts: 2581

Re: vehicle lock on restart in v1.2

« Reply #1 posted: Jul 21, 2015, 04:45 PM »
R3F_LOG_disabled is not saved for vehicles in vanilla
  • Offline LouD
  • Silent but deadly ;)
  • Moderator
  • Veteran
  • ******
  • Posts: 1415

Re: vehicle lock on restart in v1.2

« Reply #2 posted: Jul 21, 2015, 05:18 PM »
Yes you are forgetting something. Did you change fn_getVehicleProperties.sqf too?
Now you are just trying to load something that isn't there in the database.


https://github.com/LouDnl/ArmA3_Wasteland.Altis/commit/3be89b52c570f7660ae6e71113e482d315e4bff1

Re: vehicle lock on restart in v1.2

« Reply #3 posted: Jul 22, 2015, 12:45 AM »
Thanks,  that was the issue for Stratis,  now on to Altis

Re: vehicle lock on restart in v1.2

« Reply #4 posted: Jul 22, 2015, 01:28 PM »
I've just added those lines of code and now the vehicles won't save after the restart.
  • Offline AgentRev
  • Developer
  • Veteran
  • ******
  • Posts: 2581

Re: vehicle lock on restart in v1.2

« Reply #5 posted: Jul 22, 2015, 01:29 PM »
Sounds like you made a typo somewhere.

Re: vehicle lock on restart in v1.2

« Reply #6 posted: Jul 22, 2015, 01:36 PM »
Sounds like you made a typo somewhere.

fn_getVehicleProperties.sqf

Code: [Select]
// ******************************************************************************************
// * This project is licensed under the GNU Affero GPL v3. Copyright © 2014 A3Wasteland.com *
// ******************************************************************************************
// @file Name: fn_getVehicleProperties.sqf
// @file Author: AgentRev

private ["_veh", "_flying", "_class", "_purchasedVehicle", "_missionVehicle", "_pos", "_dir", "_vel", "_fuel", "_lockState", "_damage", "_hitPoints", "_variables", "_owner", "_doubleBSlash", "_textures", "_tex", "_texArr", "_weapons", "_magazines", "_items", "_backpacks", "_turretMags", "_turretMags2", "_turretMags3", "_hasDoorGuns", "_turrets", "_path", "_ammoCargo", "_fuelCargo", "_repairCargo", "_props"];

_veh = _this select 0;
_flying = if (count _this > 1) then { _this select 1 } else { false };

_class = typeOf _veh;
_purchasedVehicle = _veh getVariable ["A3W_purchasedVehicle", false];
_missionVehicle = (_veh getVariable ["A3W_missionVehicle", false] && !(_veh getVariable ["R3F_LOG_disabled", false]));

_pos = ASLtoATL getPosWorld _veh;
{ _pos set [_forEachIndex, _x call fn_numToStr] } forEach _pos;
_dir = [vectorDir _veh, vectorUp _veh];
_vel = velocity _veh;
_fuel = fuel _veh;
_damage = damage _veh;
_hitPoints = [];

{
_hitPoint = configName _x;
_hitPoints set [count _hitPoints, [_hitPoint, _veh getHitPointDamage _hitPoint]];
} forEach (_class call getHitPoints);

_variables = [];

_owner = _veh getVariable ["ownerUID", ""];

if !(_owner in ["","0"]) then
{
_variables pushBack ["ownerUID", _owner];
};

switch (true) do
{
case _purchasedVehicle:
{
_variables pushBack ["A3W_purchasedVehicle", true];
};
case _missionVehicle:
{
_variables pushBack ["A3W_missionVehicle", true];
};
};

//Save lockstate by LouD
_lockState = _veh getVariable ["R3F_LOG_disabled",""];
_variables pushBack ["R3F_LOG_disabled", _lockState];

_doubleBSlash = (call A3W_savingMethod == "extDB");

_textures = [];
{
_tex = _x select 1;

if (_doubleBSlash) then
{
_texArr = [];

{
_texArr pushBack _x;

if (_x == 92) then // backslash
{
_texArr pushBack 92; // double it
};
} forEach toArray _tex;

_tex = toString _texArr;
};

[_textures, _tex, [_x select 0]] call fn_addToPairs;
} forEach (_veh getVariable ["A3W_objectTextures", []]);

_weapons = [];
_magazines = [];
_items = [];
_backpacks = [];

if (_class call fn_hasInventory) then
{
// Save weapons & ammo
_weapons = (getWeaponCargo _veh) call cargoToPairs;
_magazines = _veh call fn_magazineAmmoCargo;
_items = (getItemCargo _veh) call cargoToPairs;
_backpacks = (getBackpackCargo _veh) call cargoToPairs;
};

_turretMags = magazinesAmmo _veh;
_turretMags2 = [];
_turretMags3 = [];
_hasDoorGuns = isClass (configFile >> "CfgVehicles" >> _class >> "Turrets" >> "RightDoorGun");

_turrets = allTurrets [_veh, false];

if !(_class isKindOf "B_Heli_Transport_03_unarmed_F") then
{
_turrets = [[-1]] + _turrets; // only add driver turret if not unarmed Huron, otherwise flares get saved twice
};

if (_hasDoorGuns) then
{
// remove left door turret, because its mags are already returned by magazinesAmmo
{
if (_x isEqualTo [1]) exitWith
{
_turrets set [_forEachIndex, 1];
};
} forEach _turrets;

_turrets = _turrets - [1];
};

{
_path = _x;

{
if ([_turretMags, _x, -1] call fn_getFromPairs == -1 || _hasDoorGuns) then
{
if (_veh currentMagazineTurret _path == _x && {count _turretMags3 == 0}) then
{
_turretMags3 pushBack [_x, _path, [_veh currentMagazineDetailTurret _path] call getMagazineDetailAmmo];
}
else
{
_turretMags2 pushBack [_x, _path];
};
};
} forEach (_veh magazinesTurret _path);
} forEach _turrets;

_ammoCargo = getAmmoCargo _veh;
_fuelCargo = getFuelCargo _veh;
_repairCargo = getRepairCargo _veh;

// Fix for -1.#IND
if (isNil "_ammoCargo" || {!finite _ammoCargo}) then { _ammoCargo = 0 };
if (isNil "_fuelCargo" || {!finite _fuelCargo}) then { _fuelCargo = 0 };
if (isNil "_repairCargo" || {!finite _repairCargo}) then { _repairCargo = 0 };

_props =
[
["Class", _class],
["Position", _pos],
["Direction", _dir],
["Velocity", _vel],
["Fuel", _fuel],
["Damage", _damage],
["HitPoints", _hitPoints],
["Variables", _variables],
["Textures", _textures],

["Weapons", _weapons],
["Magazines", _magazines],
["Items", _items],
["Backpacks", _backpacks],

["TurretMagazines", _turretMags],
["TurretMagazines2", _turretMags2],
["TurretMagazines3", _turretMags3],

["AmmoCargo", _ammoCargo],
["FuelCargo", _fuelCargo],
["RepairCargo", _repairCargo]
];

// If flying and not UAV, do not save current pos/dir/vel
if (_flying && {getNumber (configFile >> "CfgVehicles" >> _class >> "isUav") <= 0}) then
{
_props deleteRange [1,3];
};

_props

vLoad.sqf

Code: [Select]
// ******************************************************************************************
// * This project is licensed under the GNU Affero GPL v3. Copyright © 2014 A3Wasteland.com *
// ******************************************************************************************
// @file Name: vLoad.sqf
// @file Author: AgentRev, JoSchaap, Austerror

private ["_maxLifetime", "_maxUnusedTime", "_worldDir", "_methodDir", "_vehCount", "_vehicles", "_exclVehicleIDs"];

_maxLifetime = ["A3W_vehicleLifetime", 0] call getPublicVar;
_maxUnusedTime = ["A3W_vehicleMaxUnusedTime", 0] call getPublicVar;

_worldDir = "persistence\server\world";
_methodDir = format ["%1\%2", _worldDir, call A3W_savingMethodDir];

_vehCount = 0;
_vehicles = call compile preprocessFileLineNumbers format ["%1\getVehicles.sqf", _methodDir];

_exclVehicleIDs = [];

{
private ["_veh", "_vehicleID", "_class", "_pos", "_dir", "_vel", "_flying", "_damage", "_fuel", "_hitPoints", "_variables", "_textures", "_weapons", "_magazines", "_items", "_backpacks", "_turretMags", "_turretMags2", "_turretMags3", "_ammoCargo", "_fuelCargo", "_repairCargo", "_hoursAlive", "_hoursUnused", "_valid"];

{ (_x select 1) call compile format ["%1 = _this", _x select 0] } forEach _x;

if (isNil "_flying") then { _flying = 0 };
if (isNil "_hoursAlive") then { _hoursAlive = 0 };
if (isNil "_hoursUnused") then { _hoursUnused = 0 };
_valid = false;

if (!isNil "_class" && !isNil "_pos" && {count _pos == 3 && (_maxLifetime <= 0 || _hoursAlive < _maxLifetime) && (_maxUnusedTime <= 0 || _hoursUnused < _maxUnusedTime)}) then
{
_vehCount = _vehCount + 1;
_valid = true;

{ if (typeName _x == "STRING") then { _pos set [_forEachIndex, parseNumber _x] } } forEach _pos;

_isUAV = (getNumber (configFile >> "CfgVehicles" >> _class >> "isUav") > 0);
_flying = (_flying > 0);

_veh = createVehicle [_class, _pos, [], 0, if (_isUAV && _flying) then { "FLY" } else { "None" }];

_velMag = vectorMagnitude velocity _veh;

_veh setPosWorld ATLtoASL _pos;

if (!isNil "_dir") then
{
_veh setVectorDirAndUp _dir;
};

// UAV AI
if (_isUAV) then
{
createVehicleCrew _veh;

if (_flying) then
{
if (isNil "_vel" || {count _vel < 3}) then
{
_vel = (vectorDir _veh) vectorMultiply _velMag;
};

_veh setVelocity _vel;
_veh flyInHeight (((_veh call fn_getPos3D) select 2) max 500);
};

[_veh, _flying] spawn
{
_uav = _this select 0;
_flying = _this select 1;

waitUntil {!isNull driver _uav};

if (_flying) then
{
_wp = (group _uav) addWaypoint [getPosATL _uav, 0];
_wp setWaypointType "MOVE";
};

{
[[_x, ["AI","",""]], "A3W_fnc_setName", true] call A3W_fnc_MP;
} forEach crew _uav;
};
};

[_veh] call vehicleSetup;

if (!isNil "_vehicleID") then
{
_veh setVariable ["A3W_vehicleID", _vehicleID, true];
A3W_vehicleIDs pushBack _vehicleID;
};

_veh setVariable ["vehSaving_hoursUnused", _hoursUnused];
_veh setVariable ["vehSaving_lastUse", diag_tickTime];
_veh setVariable ["vehSaving_hoursAlive", _hoursAlive];
_veh setVariable ["vehSaving_spawningTime", diag_tickTime];

_veh setDamage _damage;
{ _veh setHitPointDamage _x } forEach _hitPoints;

_veh setFuel _fuel;

if (!isNil "_textures") then
{
_veh setVariable ["BIS_enableRandomization", false, true];

_objTextures = [];
{
_texture = _x select 0;
{
_veh setObjectTextureGlobal [_x, _texture];
[_objTextures, _x, _texture] call fn_setToPairs;
} forEach (_x select 1);
} forEach _textures;

_veh setVariable ["A3W_objectTextures", _objTextures, true];
};

if (!isNil "_owner") then
{
_veh setVariable ["ownerUID", _owner, true];
};

{ _veh setVariable [_x select 0, _x select 1, true] } forEach _variables;

// If vehicle is was locked before restart then restore lockstate and make it untowable/unliftable LouD
if (_veh getVariable "R3F_LOG_disabled") then
{
    _veh lock 2;
}
else
{
            _veh lock 1;
};

clearWeaponCargoGlobal _veh;
clearMagazineCargoGlobal _veh;
clearItemCargoGlobal _veh;
clearBackpackCargoGlobal _veh;

if (!isNil "_weapons") then
{
{ _veh addWeaponCargoGlobal _x } forEach _weapons;
};
if (!isNil "_magazines") then
{
[_veh, _magazines] call processMagazineCargo;
};
if (!isNil "_items") then
{
{ _veh addItemCargoGlobal _x } forEach _items;
};
if (!isNil "_backpacks") then
{
{
_bpack = _x select 0;

if (!(_bpack isKindOf "Weapon_Bag_Base") || {{_bpack isKindOf _x} count ["B_UAV_01_backpack_F", "B_Static_Designator_01_weapon_F", "O_Static_Designator_02_weapon_F"] > 0}) then
{
_veh addBackpackCargoGlobal _x;
};
} forEach _backpacks;
};

_veh setVehicleAmmo 0;

if (!isNil "_turretMags3") then
{
{
_veh addMagazineTurret [_x select 0, _x select 1];
_veh setVehicleAmmo (_x select 2);
} forEach _turretMags3;
};
if (!isNil "_turretMags") then
{
{ _veh addMagazine _x } forEach _turretMags;
};
if (!isNil "_turretMags2") then
{
{ _veh addMagazineTurret _x } forEach _turretMags2;
};

if (!isNil "_ammoCargo") then { _veh setAmmoCargo _ammoCargo };
if (!isNil "_fuelCargo") then { _veh setFuelCargo _fuelCargo };
if (!isNil "_repairCargo") then { _veh setRepairCargo _repairCargo };

reload _veh;
};

if (!_valid && !isNil "_vehicleID") then
{
_exclVehicleIDs pushBack _vehicleID;
};
} forEach _vehicles;

diag_log format ["A3Wasteland - world persistence loaded %1 vehicles from %2", _vehCount, call A3W_savingMethodName];

fn_deleteVehicles = [_methodDir, "deleteVehicles.sqf"] call mf_compile;
_exclVehicleIDs call fn_deleteVehicles;
  • Offline LouD
  • Silent but deadly ;)
  • Moderator
  • Veteran
  • ******
  • Posts: 1415

Re: vehicle lock on restart in v1.2

« Reply #7 posted: Jul 22, 2015, 01:54 PM »
Have you looked at my comment in the commit?
Code: [Select]
Be carefull implementing this commit. It might cause your server/object saving to stop working if you already have vehicles in your database.
You will have to empty your vehicle database. Because there is no R3F_LOG_Disabled variable saved to existing vehicles the vLoad.sqf will stop with an error. I never bothered to fix this as I just emptied my database.

You could probably whip up a small line of code in the vLoad.sqf to counter act this error and save you from emptying the database.

I think it could look something like this (not tested so could give errors):
Code: [Select]
if {!(isNil {_veh getVariable "R3F_LOG_disabled"})} then
{
// If vehicle is was locked before restart then restore lockstate and make it untowable/unliftable LouD
if (_veh getVariable "R3F_LOG_disabled") then
{
_veh lock 2;
}
else
{
_veh lock 1;
};
};

Re: vehicle lock on restart in v1.2

« Reply #8 posted: Jul 22, 2015, 02:36 PM »
Have you looked at my comment in the commit?
Code: [Select]
Be carefull implementing this commit. It might cause your server/object saving to stop working if you already have vehicles in your database.
You will have to empty your vehicle database. Because there is no R3F_LOG_Disabled variable saved to existing vehicles the vLoad.sqf will stop with an error. I never bothered to fix this as I just emptied my database.

You could probably whip up a small line of code in the vLoad.sqf to counter act this error and save you from emptying the database.

I think it could look something like this (not tested so could give errors):
Code: [Select]
if {!(isNil {_veh getVariable "R3F_LOG_disabled"})} then
{
// If vehicle is was locked before restart then restore lockstate and make it untowable/unliftable LouD
if (_veh getVariable "R3F_LOG_disabled") then
{
_veh lock 2;
}
else
{
_veh lock 1;
};
};

Getting this error:

Code: [Select]
14:12:21 Error in expression < select 1, true] } forEach _variables;

if {!(isNil {_veh getVariable "R3F_LOG_d>
14:12:21   Error position: <if {!(isNil {_veh getVariable "R3F_LOG_d>
14:12:21   Error if: Type code, expected Bool
14:12:21 File mpmissions\__cur_mp.Stratis\persistence\server\world\vLoad.sqf, line 127

I'm testing this with new purchased vehicles btw, not one's already on the map.
  • Offline LouD
  • Silent but deadly ;)
  • Moderator
  • Veteran
  • ******
  • Posts: 1415

Re: vehicle lock on restart in v1.2

« Reply #9 posted: Jul 22, 2015, 03:04 PM »
Try this instead (normally I would test the code myself first, but I can't atm)

Code: [Select]
if (!isNil {_veh getVariable "R3F_LOG_disabled"}) then
{
// If vehicle is was locked before restart then restore lockstate and make it untowable/unliftable LouD
if (_veh getVariable "R3F_LOG_disabled") then
{
_veh lock 2;
}
else
{
_veh lock 1;
};
};
  • Offline LouD
  • Silent but deadly ;)
  • Moderator
  • Veteran
  • ******
  • Posts: 1415

Re: vehicle lock on restart in v1.2

« Reply #10 posted: Jul 22, 2015, 03:11 PM »
Are you using the vactions from Micovery for vehicle locking? Your locking script should set the R3F_LOG_Disabled variable too.

Re: vehicle lock on restart in v1.2

« Reply #11 posted: Jul 22, 2015, 03:14 PM »
Try this instead (normally I would test the code myself first, but I can't atm)

Code: [Select]
if (!isNil {_veh getVariable "R3F_LOG_disabled"}) then
{
// If vehicle is was locked before restart then restore lockstate and make it untowable/unliftable LouD
if (_veh getVariable "R3F_LOG_disabled") then
{
_veh lock 2;
}
else
{
_veh lock 1;
};
};

Code: [Select]
15:18:53 Error in expression <tVariable "R3F_LOG_disabled"}) then
{

if (_veh getVariable "R3F_LOG_disabled")>
15:18:53   Error position: <if (_veh getVariable "R3F_LOG_disabled")>
15:18:53   Error if: Type String, expected Bool
15:18:53 File mpmissions\__cur_mp.Stratis\persistence\server\world\vLoad.sqf, line 130

Error again.

Re: vehicle lock on restart in v1.2

« Reply #12 posted: Jul 22, 2015, 03:15 PM »
Are you using the vactions from Micovery for vehicle locking? Your locking script should set the R3F_LOG_Disabled variable too.

Yes i am.
  • Offline LouD
  • Silent but deadly ;)
  • Moderator
  • Veteran
  • ******
  • Posts: 1415

Re: vehicle lock on restart in v1.2

« Reply #13 posted: Jul 22, 2015, 03:40 PM »
Ah I see where this is going wrong. I later did an update to fn_getVehicleProperties.sqf because I probably got the same error :)

https://github.com/LouDnl/ArmA3_Wasteland.Altis/commit/36b80f362b4f2fc894261d62a7e74993aa45e190

Re: vehicle lock on restart in v1.2

« Reply #14 posted: Jul 22, 2015, 03:57 PM »
Ah I see where this is going wrong. I later did an update to fn_getVehicleProperties.sqf because I probably got the same error :)

https://github.com/LouDnl/ArmA3_Wasteland.Altis/commit/36b80f362b4f2fc894261d62a7e74993aa45e190

There is still an error

Code: [Select]
15:35:20 Error in expression <tVariable "R3F_LOG_disabled"}) then
{

if (_veh getVariable "R3F_LOG_disabled")>
15:35:20   Error position: <if (_veh getVariable "R3F_LOG_disabled")>
15:35:20   Error if: Type String, expected Bool
15:35:20 File mpmissions\__cur_mp.Stratis\persistence\server\world\vLoad.sqf, line 130