Jump to content
pliskin124

inidbi2 Help - Saving Player Location (Help with an Array)

Recommended Posts

_playerPos = getPosATL player;
["write", ["Player Info","Position",_playerPos]] call _inidbi;

The code above saves the location of a player.
 

_location = ["read", ["Player Info","Position", 0]] call _inidbi;
player setpos _location;

The code above sets the position just fine for me. The 0 above means that if it cannot find the value, it returns 0. It can be useful for error checking.
For example: 
 

_location = ["read", ["Player Info","Position", 0]] call _inidbi;
if (_location isEqualTo 0) then {
	hint "ERROR retrieving location."
} else {
	player setpos _location;
};

If I understand how iniDBI2 works correctly, I would recommend saving each key as the player UID to make sure it always fetches the correct information. Otherwise it might save the same for each client, if I understand it correctly. I, personally, would set up functions and remoteExec them to the server and then get return values. Either way, here's a short example:
 

_UID = getPlayerUID player; 
_gear = getUnitLoadout player; 
_playerPos = getPosATL player; 
 
["write", [_uid, "Gear", _gear]] call _inidbi; 
["write", [_uid, "Position", _playerPos]] call _inidbi;

Now the db would look like this:
 

[1111111111111111] // any example UID, ensuring we always get the correct information for each player.
Gear="[["SMG_01_Holo_F","","","optic_Holosight_smg",["30Rnd_45ACP_Mag_SMG_01",30],[],""],[],[],["U_B_PilotCoveralls",[["FirstAidKit",1],["30Rnd_45ACP_Mag_SMG_01",3,30],["SmokeShell",1,1],["SmokeShellBlue",1,1],["Chemlight_green",1,1]]],[],["B_Parachute",[]],"H_PilotHelmetFighter_B","",[],["ItemMap","","ItemRadio","ItemCompass","ItemWatch",""]]" // this is just an example loadout
Position="[4097.17,4153.31,0.00143909]" // example position on the VR map

To fetch the above:
 

_UID = getPlayerUID player;

_playerGear = ["read", [_uid, "Gear", 0]] call _inidbi;
if (_playerGear isEqualTo 0) then {
	systemChat "ERROR retrieving player gear or value does not exist.";
} else {
	player setUnitLoadout _playerGear;
};
_playerLocation = ["read", [_uid, "Position", 0]] call _inidbi;
if (_playerLocation isEqualTo 0) then {
	systemChat "ERROR retrieving player location or value does not exist.";
} else {
	player setPos _playerLocation;
};

 

Edited by Lacyway
Removed my DB to avoid confusion

Share this post


Link to post
Share on other sites

Thanks for the update, I'll test that out tomorrow. My brain is entirely fried today to look at code

Share this post


Link to post
Share on other sites
On 3/18/2022 at 2:08 PM, Lacyway said:

_playerPos = getPosATL player;
["write", ["Player Info","Position",_playerPos]] call _inidbi;

The code above saves the location of a player.
 


_location = ["read", ["Player Info","Position", 0]] call _inidbi;
player setpos _location;

The code above sets the position just fine for me. The 0 above means that if it cannot find the value, it returns 0. It can be useful for error checking.
For example: 
 


_location = ["read", ["Player Info","Position", 0]] call _inidbi;
if (_location isEqualTo 0) then {
	hint "ERROR retrieving location."
} else {
	player setpos _location;
};

If I understand how iniDBI2 works correctly, I would recommend saving each key as the player UID to make sure it always fetches the correct information. Otherwise it might save the same for each client, if I understand it correctly. I, personally, would set up functions and remoteExec them to the server and then get return values. Either way, here's a short example:
 


_UID = getPlayerUID player; 
_gear = getUnitLoadout player; 
_playerPos = getPosATL player; 
 
["write", [_uid, "Gear", _gear]] call _inidbi; 
["write", [_uid, "Position", _playerPos]] call _inidbi;

Now the db would look like this:
 


[1111111111111111] // any example UID, ensuring we always get the correct information for each player.
Gear="[["SMG_01_Holo_F","","","optic_Holosight_smg",["30Rnd_45ACP_Mag_SMG_01",30],[],""],[],[],["U_B_PilotCoveralls",[["FirstAidKit",1],["30Rnd_45ACP_Mag_SMG_01",3,30],["SmokeShell",1,1],["SmokeShellBlue",1,1],["Chemlight_green",1,1]]],[],["B_Parachute",[]],"H_PilotHelmetFighter_B","",[],["ItemMap","","ItemRadio","ItemCompass","ItemWatch",""]]" // this is just an example loadout
Position="[4097.17,4153.31,0.00143909]" // example position on the VR map

To fetch the above:
 


_UID = getPlayerUID player;

_playerGear = ["read", [_uid, "Gear", 0]] call _inidbi;
if (_playerGear isEqualTo 0) then {
	systemChat "ERROR retrieving player gear or value does not exist.";
} else {
	player setUnitLoadout _playerGear;
};
_playerLocation = ["read", [_uid, "Position", 0]] call _inidbi;
if (_playerLocation isEqualTo 0) then {
	systemChat "ERROR retrieving player location or value does not exist.";
} else {
	player setPos _playerLocation;
};

 

 

 

The code above seems to just throw errors. The database is now coming in as:
 

[_uid]
Name=""Nomad""
Gear="[["arifle_MX_ACO_pointer_F","","acc_pointer_IR","optic_Aco",["30Rnd_65x39_caseless_mag",30],[],""],[],["hgun_P07_F","","","",["16Rnd_9x21_Mag",17],[],""],["U_B_CombatUniform_mcam_tshirt",[["ACE_fieldDressing",1],["ACE_packingBandage",1],["ACE_morphine",1],["ACE_tourniquet",1],["30Rnd_65x39_caseless_mag",2,30]]],["V_Chestrig_rgr",[["30Rnd_65x39_caseless_mag",5,30],["16Rnd_9x21_Mag",2,17],["HandGrenade",2,1],["B_IR_Grenade",2,1],["SmokeShell",1,1],["SmokeShellGreen",1,1],["Chemlight_green",2,1]]],["B_Carryall_mcamo_AAT",[["Titan_AT",2,1],["Titan_AP",2,1]]],"H_HelmetB_light","",["Rangefinder","","","",[],[],""],["ItemMap","","ItemRadio","ItemCompass","ItemWatch","NVGoggles"]]"
[Player Info]
Position="[1198.34,3403.18,0.00143909]"

and it just repeats the error messages from the systemChat

You said it was working on your end, would you be able to provide the full scripts so I can test it?

Share this post


Link to post
Share on other sites

I'm away on vacation for 2 weeks but can help you as much as I can. 

 

Since the key/entry is defined as _uid in your db, did you mistakenly quote it? It should be without quotes and you need to define the variable before using it as well with this:

_UID = getPlayerUID player;

 

The position entry seems to be missing too. 

 

My point was that all players should be saved in the same .ini file, and each key is their UID. 

 

For example initialize a db named players. Players.ini would look like this:

 

[1234] // the UID of the player, this is the key that we fetch info from using _uid

Gear=

Position=

 

[5678]

Gear=

Position=

 

Etc.

 

Sorry if this is vague, it's hard to explain over my phone. 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×