Jump to content
code34

iniDBI - Save and Load data to the server or your local computer without databases!

Recommended Posts

I have box and save box cargo .

How i can read this and refill box in game restart!?

_transformArray = {
	private "_array";

	_array = [];

	params ["_types", "_quantities"];

	{_array pushBack [_x, _quantities select _forEachIndex]} forEach _types;

	_array
};

_cargo = ["locker", "GLOBAL", "Locker1", "ARRAY"] call iniDB_read;

_weaponsCargo = _cargo select 0; // Looks like [[<type1>, ...], [<quantity1>, ...]]
_magazinesCargo = _cargo select 1;
_itemsCargo = _cargo select 2;
_backpacksCargo = _cargo select 3;

_weaponsCargo = _weaponsCargo call _transformArray; // Now looks like [[<type1>, <quantity1>], ...]
_magazinesCargo = _magazinesCargo call _transformArray;
_itemsCargo = _itemsCargo call _transformArray;
_backpacksCargo = _backpacksCargo call _transformArray;

{Storage_1 addWeaponCargo _x} forEach _weaponsCargo;
{Storage_1 addMagazineCargo _x} forEach _magazinesCargo;
{Storage_1 addItemCargo _x} forEach _itemsCargo;
{Storage_1 addBackpackCargo _x} forEach _backpacksCargo;

But you need to use functions with global effect (e.g. addWeaponCargoGlobal) if you want that all players view same cargo.

  • Like 1

Share this post


Link to post
Share on other sites

how to get this work?

i want to save player score and load it again but i lost.

   private ["_name","_Profile","_name_UID"];
    _name = name player;
    _Profile = format["%1", getPlayerUID player];
    _name_UID = _name + "_" + _Profile;
    _exist = _name_UID call iniDB_exists;
    systemChat "Checking if you got an account...";
    if (_exist) then {
        
        
        _addscore = [_name_UID, _Profile, "PlayerScore", "SCALAR"] call inidb_read;

player addScore _addscore;
        
    };        
//////////
  private ["_name","_Profile","_name_UID"];
    _name = name player;
    _Profile = format["%1", getPlayerUID player];
    _name_UID = _name + "_" + _Profile;

_score = [_name_UID,_Profile, "PlayerScore", score player] call iniDB_write;

Persian MO_7656xxxxxxxxxxxxxxxx.ini

[7656xxxxxxxxxxxx]
PlayerScore="4"

Share this post


Link to post
Share on other sites

i got this code

initserver.sqf

call compile preProcessFile "\inidbi\init.sqf";
campaignFile = "Campaign_0";

fnc_getLoadout = {

    private ["_player","_uid","_cid"];

    _player = _this select 0;

    _uid = getPlayerUID _player;

    _cid = owner _player;



    loadout = [_uid, campaignFile, "loadout", "SCALAR"] call iniDB_read;

    _cid publicVariableClient "loadout";

};


fnc_saveLoadout = {

    private ["_player","_loadout","_uid"];

    _player = _this select 0;

    _loadout = _this select 1;

    _uid = getPlayerUID _player;



    [_uid, campaignFile, "loadout", _loadout] call iniDB_write;

};

initplayerlocal.sqf

loadout = false;

[ [player], "fnc_getLoadout", false] spawn BIS_fnc_MP;

waitUntil {typeName loadout == "SCALAR"};

player addScore loadout;

sleep 10;

while {(true)} do {
    
[ [player,score player], "fnc_saveLoadout", false] spawn BIS_fnc_MP;    

sleep 5;
};

Code working on client server.didn't test yet on dedicated server.If i change loadout name and variables to something else like myscore , code not working !!!

 

Share this post


Link to post
Share on other sites

 fix the score save/load.work on dedicated too, finally.

{
 _playerUID = getPlayerUID _x;

//_name = ["MyScore", _playerUID, "Name", "STRING"] call iniDB_read;
_score = ["MyScore", _playerUID, "Score", "SCALAR"] call iniDB_read;

_x addScore _score;

    } forEach playableUnits;

sleep 5;

while{true} do {
   
   sleep 100;

   //save player data
   {
      _playerUID = getPlayerUID _x;

//      ["MyScore", _playerUID, "Name", name _x] call iniDB_write;
      ["MyScore", _playerUID, "Score", score _x] call iniDB_write;
   } forEach playableUnits;
   
//   [-1, {hint _this}, "Saved loc"] call CBA_fnc_globalExecute;

};

------------------------------------

 

 

I tried to save/load player inventory but looks like this is harder!

Here i found this code.

  {
if (isPlayer _x) then {



_Profile = format["%1", getPlayerUID _x];
[_Profile, "playerData", "position", position _x] call iniDB_write;
[_Profile, "playerData", "Playername", name _x] call iniDB_write;
[_Profile, "playerData", "magazines", magazines _x] call iniDB_write;
[_Profile, "playerData", "weapons", Weapons _x] call iniDB_write;
[_Profile, "playerData", "weapons1", SecondaryWeapon _x] call iniDB_write;
[_Profile, "playerData", "vest", vest _x] call iniDB_write;
[_Profile, "playerData", "uniform", uniform _x] call iniDB_write;
[_Profile, "playerData", "headgear", headgear _x] call iniDB_write;
[_Profile, "playerData", "items", items _x] call iniDB_write;
[_Profile, "playerData", "goggles", goggles _x] call iniDB_write;
[_Profile, "playerData", "UniformItems", UniformItems _x] call iniDB_write;
[_Profile, "playerData", "VestItems", VestItems _x] call iniDB_write;
[_Profile, "playerData", "backpack", backpack _x] call iniDB_write;
[_Profile, "playerData", "backpackItems", backpackItems _x] call iniDB_write;
[_Profile, "playerData", "handgunMagazine", handgunMagazine _x] call iniDB_write;
[_Profile, "playerData", "handgunWeapon", handgunWeapon _x] call iniDB_write;
[_Profile, "playerData", "handgunItems", handgunItems _x] call iniDB_write;
[_Profile, "playerData", "assignedItems", assignedItems _x] call iniDB_write;


       };  
    
} forEach allUnits;

765xxxxxxxxxxxxx.ini

[playerData]
position="[6110.89,11635.4,0.00144196]"
Playername="Persian MO"
magazines="["30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","Chemlight_green","30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","16Rnd_9x21_Mag","16Rnd_9x21_Mag","SmokeShell","SmokeShellGreen","Chemlight_green","HandGrenade","HandGrenade"]"
weapons="["arifle_MX_ACO_pointer_F","hgun_P07_F"]"
weapons1=""
vest="V_PlateCarrier1_rgr"
uniform="U_B_CombatUniform_mcam"
headgear="H_HelmetB"
items="["FirstAidKit"]"
goggles=""
UniformItems="["FirstAidKit","30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","Chemlight_green"]"
VestItems="["30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag","16Rnd_9x21_Mag","16Rnd_9x21_Mag","SmokeShell","SmokeShellGreen","Chemlight_green","HandGrenade","HandGrenade"]"
backpack=""
backpackItems="[]"
handgunMagazine="["16Rnd_9x21_Mag"]"
handgunWeapon="hgun_P07_F"
handgunItems="["","","",""]"
assignedItems="["ItemMap","ItemCompass","tf_microdagr","tf_anprc152_1","NVGoggles"]"

again, how to load this and work fine on dedicated server?

 

 

Share this post


Link to post
Share on other sites

Nah, I can't do it :(

trying for days but i can't get this working on dedicated server.

Please, anybody can give me a example about saving and load SCORE and player loadout?

Share this post


Link to post
Share on other sites

Hi,

 

I am having a little difficulty getting iniDBi to run as expected.

 

I have installed in tot he iniDBi folder in the Arma3 directory (on my client machine as it will be used for saving map editor work).

 

I have unblocked the .dll file that comes with iniDBi.

 

Under the DB folder I have created a folder called 'test'

 

In that folder I have a file called test.ini

 

The contents of test.ini is

[testItem]
testVariable="working"

diag_log call inidb_version results with the following in the client log file

 

 "Inidbi: 1.4 Dll: "

I cannot get the exists or read functions to work at all though.  Both of the following commands return nothing.

_doesinidbExist = "test\test" call inidb_exists;
_value = ["test\test", "testItem", "testValue", "STRING"] call iniDB_read;

I have had this working a number of months ago but this install is after a PC rebuild on Windows 10.

 

Any pointers greatly appreciated.

 

Thanks

 

Share this post


Link to post
Share on other sites

rimblock, I'm not sure that it is possible to use subfolders under db folder.

 

Hi Schatten.  Thanks for the reply.

 

X-Cam is using iniDBi for storage of various setting.  It installs in to a xcam folder under the db folder in @inidbi.

 

More details can be found here.

 

I have also tried it with the test.ini which is in the DB folder of the latest inidbi version and have the same issue.

Share this post


Link to post
Share on other sites

rimblock, does test.ini contain blank line in the end of file?

Also replace third argument of called iniDB_read function from "testValue" to "testVariable".

Share this post


Link to post
Share on other sites

Good spot on the var name in the file.

 

To make it simpler I have moved back to trying to reference the TEST.ini in the 'db' folder that comes with iniDBi.

 

Code is being run via Debug Window in the A3 editor on Stratis.

call compile preProcessFile "\inidbi\init.sqf";
inidbExists = "TEST" call inidb_exists;
value = ["TEST", "GLOBAL", "units", "STRING"] call iniDB_read;
diag_log format["inidbExists: %1, value: %2",inidbExists, value];

Output from the Diag_Log

"inidbExists: any, value: any"

The TEST.ini is exactly as it is in the @inidbi distro.

 

Is anyone able to verify they are running iniDBi on Windows 10 ?.

Share this post


Link to post
Share on other sites

Hi and thanks for this great DB, I love this thing!

 

I have used this in the past and it worked great. This time I am on windows 10, not sure if it makes a difference, and it will save player position like expected and will even load the pos if i tell it to. The issue I am having is the DB file will update on my 30 second timer, however, the only thing that will not update is the player position. It will make an initial entry when you are a new spawn. This is expected in the code i wrote. What i snot expected is if I delete the table for said player it will remake with the same initial position regardless fo where the player is when the update happens. Sorry if this is confusing. Here is my code:

{
	if (isPlayer _x && alive _x) then {
		
		_Profile = format["%1", getPlayerUID _x];
		playerExists = _Profile call inidb_exists;
	
		if (playerExists) then {
			_playerPos = [_Profile, "Player_Data", "Position", "ARRAY"] call iniDB_read;
			_playerDmg = [_Profile, "Player_Data", "Damage", "SCALAR"] call iniDB_read;
			_playerInv = [_Profile, "Player_Data", "Inventory", "ARRAY"] call iniDB_read;
			_playerPri = [_Profile, "Player_Data", "Primary", "STRING"] call iniDB_read;
			_playerSec = [_Profile, "Player_Data", "Secondary", "STRING"] call iniDB_read;
			_playerSid = [_Profile, "Player_Data", "Sidearm", "STRING"] call iniDB_read;
		
			diag_log format ["Player %1 database load: [Position:%2,Damage:%3,Inventory:%4,Primary Weapon:%5,Secondary Weapon:%6,Sidearm:%7]",name _x,_playerPos,_playerDmg,_playerInv,_playerPri,_playerSec,_playerSid];

			playerLoadout = [_playerPos,_playerDmg,_playerInv,_playerPri,_playerSec,_playerSid];
			(owner _x) publicVariableClient "playerLoadout";
		};
		publicVariable "playerExists";
	};
} forEach playableUnits;

{
	while {true} do {
		sleep 30;
		if (isPlayer _x && alive _x) then {
			_Profile = format["%1", getPlayerUID _x];
			[_Profile, "Server_Time", "Time", time] call iniDB_write;
			[_Profile, "Server_Date", "Date", date] call iniDB_write;
			
			[_Profile, "Player_Name", "Player", name _x] call iniDB_write;
			[_Profile, "Player_Pos", "Position", position _x] call iniDB_write;
			[_Profile, "Player_Dmg", "Damage", damage _x] call iniDB_write;
			[_Profile, "Player_Inv", "Inventory", magazines _x] call iniDB_write;
			[_Profile, "Player_Primary", "Primary", primaryWeapon _x] call iniDB_write;
			[_Profile, "Player_Secondary", "Secondary", secondaryWeapon _x] call iniDB_write;
			[_Profile, "Player_Sidearm", "Sidearm", handGunWeapon _x] call iniDB_write;
		};
	};
} forEach playableUnits;

Is anyone else having this issue?

 

Share this post


Link to post
Share on other sites

Good spot on the var name in the file.

 

To make it simpler I have moved back to trying to reference the TEST.ini in the 'db' folder that comes with iniDBi.

 

Code is being run via Debug Window in the A3 editor on Stratis.

call compile preProcessFile "\inidbi\init.sqf";
inidbExists = "TEST" call inidb_exists;
value = ["TEST", "GLOBAL", "units", "STRING"] call iniDB_read;
diag_log format["inidbExists: %1, value: %2",inidbExists, value];

Output from the Diag_Log

"inidbExists: any, value: any"

The TEST.ini is exactly as it is in the @inidbi distro.

 

Is anyone able to verify they are running iniDBi on Windows 10 ?.

Rimblock,

 

I am also running my dedicated box on Windows 10 and everything seems to be great with the exception of the position variable not updating depending on player position. I noticed that if I compiled the DB globally my client would report file yada yada not found. I just compile it isServer now and the clients are pushed info with a (owner _x) publicVariableClient "variable";

 

Seems to be working better than expected too! :)

 

EDIT: I am testing on Windows 7 Pro Ultimate not Windows 10 sorry.

Share this post


Link to post
Share on other sites

Alright. I can confirm that all my variables are saving and loading extremely well with the exception of the player position. It will save one array when the table is first created but after that it will remain the same regardless of what I have tested. It will even recreate the same position array if you remove it or even the whole table. It does this even if logged in as server admin. I am baffled lol O.o

Share this post


Link to post
Share on other sites

this code saving player score in deicated server

while {true} do {

   
   sleep 300;


   {  
      _playerUID = getPlayerUID _x;


      

      Skore = ["MyScore", _playerUID, "Score", score _x] call iniDB_write;


      
    } forEach playableUnits;

  [-1, {hint _this}, "Saved"] call CBA_fnc_globalExecute;

 
 
};

but if i change it and use onPlayerDisconnected not working.Where is the problem?

 


onPlayerDisconnected {
    
_id =   _this select 0;
_name = _this select 1;
_uid =  _this select 2;
_playerUID = getPlayerUID _uid;

Skore = ["MyScore", _playerUID, "Score", score _uid] call iniDB_write;

};

Share this post


Link to post
Share on other sites

but if i change it and use onPlayerDisconnected not working.Where is the problem?

onPlayerDisconnected doesn't contain unit's object - use HandleDisconnect event handler instead:

addMissionEventHandler [
	"HandleDisconnect",
	{
		_unit = _this select 0;
		_uid = _this select 2;

		Skore = ["MyScore", _uid, "Score", score _unit] call iniDB_write;
	}
];
  • Like 1

Share this post


Link to post
Share on other sites

I guess I will make a public variable to send player position back to the zerver. This defeats the purpose of handling all dB data serverside. Using position player client side returns correct position. Using position _x in my server side save loop only works on the initial dB creation and it never updates again afterwards. Does anyone have suggestions? I can load the position just fine btw.

Share this post


Link to post
Share on other sites

I guess I will make a public variable to send player position back to the zerver. This defeats the purpose of handling all dB data serverside. Using position player client side returns correct position. Using position _x in my server side save loop only works on the initial dB creation and it never updates again afterwards. Does anyone have suggestions? I can load the position just fine btw.

Try:

while {true} do {
	sleep 30;

	{
		if (isPlayer _x) then { // playableUnits doesn't contain dead units
			_Profile = getPlayerUID _x; // getPlayerUID returns string

			[_Profile, "Server_Time", "Time", time] call iniDB_write;
			[_Profile, "Server_Date", "Date", date] call iniDB_write;

			[_Profile, "Player_Name", "Player", name _x] call iniDB_write;
			[_Profile, "Player_Pos", "Position", position _x] call iniDB_write;
			[_Profile, "Player_Dmg", "Damage", damage _x] call iniDB_write;
			[_Profile, "Player_Inv", "Inventory", magazines _x] call iniDB_write;
			[_Profile, "Player_Primary", "Primary", primaryWeapon _x] call iniDB_write;
			[_Profile, "Player_Secondary", "Secondary", secondaryWeapon _x] call iniDB_write;
			[_Profile, "Player_Sidearm", "Sidearm", handgunWeapon _x] call iniDB_write;
		};
	}
	forEach playableUnits;
};

Share this post


Link to post
Share on other sites

Try:

while {true} do {
	sleep 30;

	{
		if (isPlayer _x) then { // playableUnits doesn't contain dead units
			_Profile = getPlayerUID _x; // getPlayerUID returns string

			[_Profile, "Server_Time", "Time", time] call iniDB_write;
			[_Profile, "Server_Date", "Date", date] call iniDB_write;

			[_Profile, "Player_Name", "Player", name _x] call iniDB_write;
			[_Profile, "Player_Pos", "Position", position _x] call iniDB_write;
			[_Profile, "Player_Dmg", "Damage", damage _x] call iniDB_write;
			[_Profile, "Player_Inv", "Inventory", magazines _x] call iniDB_write;
			[_Profile, "Player_Primary", "Primary", primaryWeapon _x] call iniDB_write;
			[_Profile, "Player_Secondary", "Secondary", secondaryWeapon _x] call iniDB_write;
			[_Profile, "Player_Sidearm", "Sidearm", handgunWeapon _x] call iniDB_write;
		};
	}
	forEach playableUnits;
};

You know... that's a great idea man. I never even thought of that. I will try tonight and report back. Thanks!

Share this post


Link to post
Share on other sites

You know... that's a great idea man. I never even thought of that. I will try tonight and report back. Thanks!

Well, it did not work either. I am wondering if it is some kind of flaw in arma when calling position after a certain point after the mission starts. I cannot imagine the db is bugged because everything else saves, loads and overwrites with current data at the time of the loop running. The alive _x seems to returning a boolean true since i have added a waitUntil call on it and I can load just fine as opposed to not getting the full exec on my playerLogin.sqf. This seems pretty strange since I can run a position, getPos, getPosASL/ATL and pretty much every version of it client side and return the exact coords with no problem. The icing on the cake is that it will save the spawn point provided for being a player not in the database. Could it be possible that using this spawn script for new players I could be setting the server to believe the player is always at this spawn point?

diag_log format ["Player %1 does not exist in database.",_Profile];
				_mapCenter = getArray (configFile >> "CfgWorlds" >> worldName >> "centerPosition");
				_cityPos = nearestLocations [_mapCenter, ["nameCity","nameVillage"], 10000];
				_citySel = _cityPos call BIS_fnc_selectRandom;
				_cityLoc = getPos _citySel;
				
				_cityMarker = createMarker ["spawnMarker", _cityLoc];
				_cityMarker setMarkerAlpha 0;
				_cityMarker setMarkerColor "ColorRed";
				_cityMarker setMarkerShape "ELLIPSE";
				_cityMarker setMarkerBrush "Grid";
				_cityMarker setMarkerSize [3,3];
				
				_spawnPos = [getmarkerPos _cityMarker,0,750,2,0,1,0] call BIS_fnc_findSafePos;
				_x setPos _spawnPos;
			};
			(owner _x) publicVariableClient "playerExists";

Share this post


Link to post
Share on other sites

I noticed this line in my rpt log:

 

Unable to get file version size: C:\Program Files (x86)\Steam\steamapps\common\Arma 3 Server\@inidbi\iniDB.dll

 

Maybe this has something to do with it? Then again I am not so sure it does. I would imagine the whole mod would be failing rather than the player position. If I call any kind of position _x i notice I get [x,y,z] and the z coord is always zero. Is this because im on the ground or perhaps a clue as to why I cannot get an updated position to report back to me from the the server?

Share this post


Link to post
Share on other sites

Sorry if this is a noob question lol

Can I use this when setting up an epoch server?

I just want a small co-op max 5 players between friends and I have an arma server already.

Thanks

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

×