Save vehicle lockstate to iniDB?

Save vehicle lockstate to iniDB?

« posted: Nov 16, 2014, 01:29 PM »
I'm going to start of with saying I'm a noob when it comes to scripting.

I'm trying to set up a server for my friends and me to mess around on.
I got the iniDB to do a full save of players and vehicles also save but I'm trying to figure out how to save the lockstate aswell, and bind it to the player/UID so only the owner can unlock it.

But as I said, I'm a noob at scripting, so maybe I'll need the explanation to be abit noob-friendly...

Thanks in advance!!

My vehicles db looks like this:

Code: [Select]
[Info]
ObjCount="1"
[Veh1]
Class="B_Heli_Attack_01_F"
Position="[14780.4,16676.5,0.0498085]"
Direction="[[-0.959656,0.281145,0.00427246],[0.00442336,-9.78622e-005,0.99999]]"
HoursAlive="0.501536"
Damage="0"
AllowDamage="1"
Variables="[["ownerUID","76561197962164237"]]"
Weapons="[["hgun_ACPC2_F",1]]"
Magazines="[]"
Items="[]"
Backpacks="[["B_Parachute",2]]"

Vehicle save script:


Code: [Select]
// @file Version: 1.2
// @file Name: oSave.sqf
// @file Author: [GoT] JoSchaap, AgentRev
// @file Description: Basesaving save script

if (!isServer) exitWith {};

#include "functions.sqf"

_saveableObjects = [];

_isSaveable =
{
_result = false;
{ if (_this == _x) exitWith { _result = true } } forEach _saveableObjects;
_result
};

// Add objectList & general store objects
{
_index = _forEachIndex;

{
_obj = _x;
if (_index > 0) then { _obj = _x select 1 };

if (!(_obj isKindOf "AllVehicles") && {!(_obj call _isSaveable)}) then
{
[_saveableObjects, _obj] call BIS_fnc_arrayPush;
};

} forEach _x;
} forEach [civilianVehicles, call allVehStoreVehicles]; //objectList

_filename2 = "Veh" call PDB_databaseNameCompiler;

// If file doesn't exist, create Info section at the top
if !(_filename2 call iniDB_exists) then
{
[_filename2, "Info", "ObjCount", 0] call iniDB_write;
};

while {true} do
{
sleep 60;

_oldObjCount = [_filename2, "Info", "ObjCount", "NUMBER"] call iniDB_read;
_objCount = 0;

{
_obj = _x;

if (alive _obj) then
{
_class = typeOf _obj;
_ownerId = _x getVariable "ownerUID"; //if (_obj getVariable ["objectLocked", true]
if(!isNil "_ownerId" && {(_baseSavingOn && {_class call _isSaveable}) || {_boxSavingOn && {_obj isKindOf "AllVehicles"}}}) //||
  // {_warchestSavingOn && {_obj call _isWarchest}} ||
   //{_beaconSavingOn && {_obj call _isBeacon}})
   then
{
_netId = netId _obj;
_pos = getPosATL _obj;
_dir = [vectorDir _obj, vectorUp _obj];
_damage = damage _obj;
_allowDamage = if (_obj getVariable ["allowDamage", false]) then { 1 } else { 0 };

if (isNil {_obj getVariable "baseSaving_spawningTime"}) then
{
_obj setVariable ["baseSaving_spawningTime", diag_tickTime];
};

_hoursAlive = (_obj getVariable ["baseSaving_hoursAlive", 0]) + ((diag_tickTime - (_obj getVariable "baseSaving_spawningTime")) / 3600);

_variables = [];
/*
switch (true) do
{
case (_obj isKindOf "Land_Sacks_goods_F"):
{
[_variables, ["food", _obj getVariable ["food", 20]]] call BIS_fnc_arrayPush;
};
case (_obj isKindOf "Land_WaterBarrel_F"):
{
[_variables, ["water", _obj getVariable ["water", 20]]] call BIS_fnc_arrayPush;
};
};
*/
_owner = _obj getVariable ["ownerUID", ""];

if (_owner != "") then
{
[_variables, ["ownerUID", _owner]] call BIS_fnc_arrayPush;
};

/*
switch (true) do
{
case (_obj call _isWarchest):
{
[_variables, ["a3w_warchest", true]] call BIS_fnc_arrayPush;
[_variables, ["R3F_LOG_disabled", true]] call BIS_fnc_arrayPush;
[_variables, ["side", str (_obj getVariable ["side", sideUnknown])]] call BIS_fnc_arrayPush;
};
case (_obj call _isBeacon):
{
[_variables, ["a3w_spawnBeacon", true]] call BIS_fnc_arrayPush;
[_variables, ["R3F_LOG_disabled", true]] call BIS_fnc_arrayPush;
[_variables, ["side", str (_obj getVariable ["side", sideUnknown])]] call BIS_fnc_arrayPush;
[_variables, ["ownerName", (_obj getVariable ["ownerName", "[Beacon]"]) call iniDB_Base64Encode]] call BIS_fnc_arrayPush;
[_variables, ["packing", false]] call BIS_fnc_arrayPush;
[_variables, ["groupOnly", _obj getVariable ["groupOnly", false]]] call BIS_fnc_arrayPush;
};
};
*/

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

//if (getNumber (configFile >> "CfgVehicles" >> _class >> "maximumLoad") > 0) then
//{
// Save weapons & ammo
_weapons = (getWeaponCargo _obj) call cargoToPairs;
_magazines = (getMagazineCargo _obj) call cargoToPairs;
_items = (getItemCargo _obj) call cargoToPairs;
_backpacks = (getBackpackCargo _obj) call cargoToPairs;
//};

_objCount = _objCount + 1;
_objName = format ["Veh%1", _objCount];

[_filename2, _objName, "Class", _class] call iniDB_write;
[_filename2, _objName, "Position", _pos] call iniDB_write;
[_filename2, _objName, "Direction", _dir] call iniDB_write;
[_filename2, _objName, "HoursAlive", _hoursAlive] call iniDB_write;
[_filename2, _objName, "Damage", _damage] call iniDB_write;
[_filename2, _objName, "AllowDamage", _allowDamage] call iniDB_write;
[_filename2, _objName, "Variables", _variables] call iniDB_write;

[_filename2, _objName, "Weapons", _weapons] call iniDB_write;
[_filename2, _objName, "Magazines", _magazines] call iniDB_write;
[_filename2, _objName, "Items", _items] call iniDB_write;
[_filename2, _objName, "Backpacks", _backpacks] call iniDB_write;

sleep 0.01;
};
};
} forEach allMissionObjects "All";

[_filename2, "Info", "ObjCount", _objCount] call iniDB_write;
/*
_fundsWest = 0;
_fundsEast = 0;

if (["A3W_warchestMoneySaving"] call isConfigOn) then
{
_fundsWest = ["pvar_warchest_funds_west", 0] call getPublicVar;
_fundsEast = ["pvar_warchest_funds_est", 0] call getPublicVar;
};

[_filename2, "Info", "WarchestMoneyBLUFOR", _fundsWest] call iniDB_write;
[_filename2, "Info", "WarchestMoneyOPFOR", _fundsEast] call iniDB_write;
*/
diag_log format ["A3W - %1 vehicles have been saved with iniDB", _objCount];

// Reverse-delete old objects
if (_oldObjCount > _objCount) then
{
for [{_i = _oldObjCount}, {_i > _objCount}, {_i = _i - 1}] do
{
[_filename2, format ["Veh%1", _i]] call iniDB_deleteSection;
};
};
};

Vehicle load script:

Code: [Select]
// @file Version: 1.2
// @file Name: oLoad.sqf
// @file Author: JoSchaap, AgentRev, Austerror
// @file Description: Basesaving load script

if (!isServer) exitWith {};

#include "functions.sqf"

_strToSide =
{
switch (toUpper _this) do
{
case "WEST":  { BLUFOR };
case "EAST":  { OPFOR };
case "GUER":  { INDEPENDENT };
case "CIV":   { CIVILIAN };
case "LOGIC": { sideLogic };
default       { sideUnknown };
};
};

_maxLifetime = ["A3W_objectLifetime", 0] call getPublicVar;
_exists = _filename2 call iniDB_exists;
_objectsCount = 0;

if (!isNil "_exists" && {_exists}) then
{
_objectsCount = [_filename2, "Info", "ObjCount", "NUMBER"] call iniDB_read;

if (!isNil "_objectsCount") then
{
for "_i" from 1 to _objectsCount do
{
_objName = format ["Veh%1", _i];

_class = [_filename2, _objName, "Class", "STRING"] call iniDB_read;
_pos = [_filename2, _objName, "Position", "ARRAY"] call iniDB_read;
_hoursAlive = [_filename2, _objName, "HoursAlive", "NUMBER"] call iniDB_read;

if (!isNil "_class" && {!isNil "_pos"} && {_maxLifetime <= 0 || {_hoursAlive < _maxLifetime}}) then
{
_variables = [_filename2, _objName, "Variables", "ARRAY"] call iniDB_read;

_allowed = switch (true) do
{
//case (call _isWarchestEntry): { _warchestSavingOn };
//case (call _isBeaconEntry):   { _beaconSavingOn };
//case (_class call _isBox):    { _boxSavingOn };
default                       { _baseSavingOn };
};

if (_allowed) then
{
_dir = [_filename2, _objName, "Direction", "ARRAY"] call iniDB_read;
_damage = [_filename2, _objName, "Damage", "NUMBER"] call iniDB_read;
_allowDamage = [_filename2, _objName, "AllowDamage", "NUMBER"] call iniDB_read;

_obj = createVehicle [_class, _pos, [], 0, "CAN_COLLIDE"];
_obj setPosATL _pos;

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

_obj setVariable ["baseSaving_hoursAlive", _hoursAlive];
_obj setVariable ["baseSaving_spawningTime", diag_tickTime];

if (_allowDamage > 0) then
{
_obj setDamage _damage;
_obj setVariable ["allowDamage", true];
}
else
{
_obj allowDamage false;
};

{
_var = _x select 0;
_value = _x select 1;

switch (_var) do
{
case "side": { _value = _value call _strToSide };
case "ownerName": { _value = _value call iniDB_Base64Decode };
};

_obj setVariable [_var, _value, true];
} forEach _variables;

clearWeaponCargoGlobal _obj;
clearMagazineCargoGlobal _obj;
clearItemCargoGlobal _obj;
clearBackpackCargoGlobal _obj;

_unlock = switch (true) do
{
case (_obj call _isWarchest): { true };
case (_obj call _isBeacon):
{
[pvar_spawn_beacons, _obj] call BIS_fnc_arrayPush;
publicVariable "pvar_spawn_beacons";
true
};
default { false };
};

if (_unlock) exitWith
{
_obj setVariable ["objectLocked", false, true];
};

if (_boxSavingOn) then
{
_weapons = [_filename2, _objName, "Weapons", "ARRAY"] call iniDB_read;
_magazines = [_filename2, _objName, "Magazines", "ARRAY"] call iniDB_read;
_items = [_filename2, _objName, "Items", "ARRAY"] call iniDB_read;
_backpacks = [_filename2, _objName, "Backpacks", "ARRAY"] call iniDB_read;

if (!isNil "_weapons") then
{
{ _obj addWeaponCargoGlobal _x } forEach _weapons;
};
if (!isNil "_magazines") then
{
{ _obj addMagazineCargoGlobal _x } forEach _magazines;
};
if (!isNil "_items") then
{
{ _obj addItemCargoGlobal _x } forEach _items;
};
if (!isNil "_backpacks") then
{
{ _obj addBackpackCargoGlobal _x } forEach _backpacks;
};
};
};
};
};
};
/*
if (_warchestMoneySavingOn) then
{
pvar_warchest_funds_west = ([_filename2, "Info", "WarchestMoneyBLUFOR", "NUMBER"] call iniDB_read) max 0;
publicVariable "pvar_warchest_funds_west";
pvar_warchest_funds_east = ([_filename2, "Info", "WarchestMoneyOPFOR", "NUMBER"] call iniDB_read) max 0;
publicVariable "pvar_warchest_funds_east";
};
*/
};

diag_log format ["A3Wasteland - vehicle persistence loaded %1 objects from iniDB", _objectsCount];

execVM "persistence\world\Veh_Save.sqf";


Re: Save vehicle lockstate to iniDB?

« Reply #1 posted: Nov 17, 2014, 10:16 AM »
Im doing it the lazy way and locking all "owned" after restart but i would prefer to have em unlocked if the owner forgets.
Anyway you can to looking at my stuff if you pull it from my server.

I also answered Shinbotz here on some of that =)
http://forums.a3wasteland.com/index.php?topic=735.0

Re: Save vehicle lockstate to iniDB?

« Reply #2 posted: Dec 11, 2014, 04:31 PM »
Im doing it the lazy way and locking all "owned" after restart but i would prefer to have em unlocked if the owner forgets.
<snip>
That is good enough for me. How do you do that?

 :)

Re: Save vehicle lockstate to iniDB?

« Reply #3 posted: Dec 15, 2014, 12:23 PM »
I'll post it when I get home later :-)
  • Offline LouD
  • Silent but deadly ;)
  • Moderator
  • Veteran
  • ******
  • Posts: 1415

Re: Save vehicle lockstate to iniDB?

« Reply #4 posted: Dec 15, 2014, 12:37 PM »
Here's how I do it (which ofcourse is Caels way ;)). Doing it the same way, locking all owned vehicles on server restart,
https://github.com/LouDnl/ArmA3_Wasteland.Altis/commit/74b60694fe550b5cfdcc82d266915a804e75fc85#diff-69

Re: Save vehicle lockstate to iniDB?

« Reply #5 posted: Dec 16, 2014, 03:27 PM »
Yep, its a bit hard to find there but look in vLoad.sqf (im adding a bit extra here so you can find what i changed.
Code: [Select]
_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];
};

{ _veh setVariable [_x select 0, _x select 1, true] } forEach _variables; //Cael817, SNAFU, Added "true".

//Cael817, SNAFU, If vehicle is owned by a player, lock it and make it untowable/unliftable.
if (!isNil {_veh getVariable "ownerUID"}) then {
_veh setVariable ["R3F_LOG_disabled",true,true];
_veh lock 2;
//_veh setVariable ["inviteDriver",false,true];
};

Where i changed this line and only added the "true"
Code: [Select]
{ _veh setVariable [_x select 0, _x select 1, true] } forEach _variables; //Cael817, SNAFU, Added "true".

and below that ofc, "ownerUID" can be whatever you have an owned vehicle identified with. You could use "A3W_purchasedVehicle" if you only want to lock those, the point is not to lock missionvehicles(if that saving is on) as i triger the lockingscripts on ownerUID which the mission vehicles not have set to them from the beginning.
Code: [Select]
//Cael817, SNAFU, If vehicle is owned by a player, lock it and make it untowable/unliftable.
if (!isNil {_veh getVariable "ownerUID"}) then {
_veh setVariable ["R3F_LOG_disabled",true,true];
_veh lock 2;
//_veh setVariable ["inviteDriver",false,true];
};

Dont mind "_veh setVariable ["inviteDriver",false,true];" its just something i played around with making it so owners could invite one other player to unlock their vehicle, but as this variable isnt saved it should just be removed here.