Forum Jump :

Author Message


Posts: 31
Rank:


Level: Member

Country: uk
Location:
Occupation:
Age:
In-game name:

 
#1 Posted at 2016-10-11 23:30        
     
so, im fairly new to scripting but i have learnt a lot over the past few months as i have been having a go at hosting my own game mode via dedicated server and as i am doing this i learnt very quickly that i would need a database for saving player stats (ie position,gear etc), as i said im fairly new to all this (fist time using mp scripting with this, client>server talking) so i searched everywhere to see what i could work with, mysql was totally out of the question, but i stumbled on inidbi2, it took me a while to learn how to setup as there isn't much to go on for a newbie, but i now have something that works (to a certain degree) and as i couldnt find much to help me get started id like to share what i found as a quick startup package for anyone in my predicament.....

NOTE: some of it may seem unethical (but it works) to some of the more experienced scripters out there, so any pointers would be great, thanks. also this isnt a finished product you will be expected to add to it yourself to make it what you want, its just to get you going with a persistent database for your server, i will update it as i clean it up and make things better.

-install inidbi2 on your server, make sure there is a db folder inside (if not make one) and make sure you have proper read right permissions on the dll file (i think some hosting services dont give you these rights?).
-activate it on your server config (-serverMod=@inidbi2)
- make 2 folders in your mission file/or if you already have (initServer.sqf/initPlayerLocal.sqf) these files then add the scripts to the top of these files.

initserver.sqf
waitUntil {time > 0};
// --------------------------------------------------------------------checking the database-----------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
"un_database_check" addPublicVariableEventHandler {
private ["_packet"];

  _packet = _this select 1;
  _dataplayrowner = _packet select 0;
  _dataplayrname = _packet select 1;
  _dataplayruid = _packet select 2;
  _datanamearray = format ["%1_%2_mycustommissionname", _dataplayrname, _dataplayruid];
  _databasename = _datanamearray;
  
  _inidbiUN = ["new", _databasename] call OO_INIDBI;
  _databasefind = "exists" call _inidbiUN;

// ------------------------------------------------------cant find the database saveing new players name and uid---------------------------------------------------
  if (!_databasefind) then {
  ["write", ["INFO", "Name", _dataplayrname]] call _inidbiUN;
  ["write", ["INFO", "UID", _dataplayruid]] call _inidbiUN;

  "welcome new spawn" remoteExec ["hint"];
  };
// --------------------------------------------------------found the database now loading data to send to player---------------------------------------------------
  if (_databasefind) then {
  "found the database" remoteExec ["hint"];
	_readpos = ["read", ["POSITION", "Position", []]] call _inidbiUN;   
	_readdir = ["read", ["POSITION", "Direction", ""]] call _inidbiUN;
	_readdamage = ["read", ["INFO", "Health", ""]] call _inidbiUN;
	_readloadout = ["read", ["GEAR", "Loadout", []]] call _inidbiUN;
	

	un_database_load = [_readpos,
	                    _readdir,
						_readdamage,
						_readloadout];

    _dataplayrowner publicVariableClient "un_database_load";
  };
  un_database_check = nil;
};

// --------------------------------------------------player sent save game data to server - saving it to database--------------------------------------------------
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
"un_database_save" addPublicVariableEventHandler {
private ["_packet"];
    _packet = _this select 1;
    _datanamearray = format ["%1_%2_mycustommissionname", _packet select 0, _packet select 1];
    _databasename = _datanamearray;
	_inidbiUN = ["new", _databasename] call OO_INIDBI;
	
	["write", ["INFO", "Name", _packet select 0]] call _inidbiUN;
    ["write", ["INFO", "UID", _packet select 1]] call _inidbiUN;
    ["write", ["POSITION", "Position", _packet select 2]] call _inidbiUN;
	["write", ["POSITION", "Direction", _packet select 3]] call _inidbiUN;
	["write", ["INFO", "Health", _packet select 4]] call _inidbiUN;
	["write", ["GEAR", "Loadout", _packet select 5]] call _inidbiUN;

	
	"Progress Saved" remoteExec ["hint"];
};

// MrJizz - Factionfinderdotcom

initplayerlocal.sqf
waitUntil {time > 10};
// -------------------------------------------------------send name and uid to server to check for database--------------------------------------------------------
if (!isNil "un_database_check") then {
un_database_check = nil;
};

sleep 1;

if (isNil "un_database_check") then {
_dataplayrowner = clientOwner;
_dataplayrname = profileName;
_dataplayruid = getPlayerUID player;

un_database_check = [_dataplayrowner,_dataplayrname,_dataplayruid];
publicVariableServer "un_database_check";
};

// ------------------------------------------------------server found database and now sent us the data to load----------------------------------------------------
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
"un_database_load" addPublicVariableEventHandler {
private ["_ppacket"];
  _ppacket = _this select 1;
  _readpos = _ppacket select 0;
  _readdir = _ppacket select 1;
  _readdamage = _ppacket select 2;
  _readloadout = _ppacket select 3;
  

  _passtheparcel = [_readpos,
                    _readdir,
					_readdamage,
					_readloadout];
  _Null = _passtheparcel call FN_loaddata;

};

// -----------------------------------------------applying the data sent to player - magazine loaded work around-------------------------------------------------
FN_loaddata = {
params ["_readpos",
        "_readdir",
		"_readdamage",
		"_readloadout"];

hint "all your shit has loaded";
// Clear player gear
  removeAllAssignedItems player;
  removeAllItems player;
  clearAllItemsFromBackpack player;
  removeBackpack player;
  removeUniform player;
  removeVest player;
  removeHeadgear player;
  removeGoggles player;
  removeAllWeapons player;
  removeAllPrimaryWeaponItems player;
  removeAllHandgunItems player;
  cash = 0;
  killcount = 0; 
  
// Add player gear
  player setPosATL _readpos;
  player setDir _readdir;
  player setDamage _readdamage;
  player setUnitLoadout _readloadout;

  
  un_database_load = nil;
  publicVariable "un_database_load";
};

// ---------------------------------------------------------request to save game - send data to server-------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
UN_savedata = {
_dataplayrname = profileName;
_dataplayruid = getPlayerUID player;
_dataplayrpos = getPosATL player;
_dataplayrdir = direction player;
_dataplayrdamage = damage player;
_dataplayrloadout = getUnitLoadout player;



un_database_save = [_dataplayrname,
					_dataplayruid,
		            _dataplayrpos,
	                _dataplayrdir,
		            _dataplayrdamage,
					_dataplayrloadout]; 
publicVariableServer "un_database_save";
hint "saveing game";
};

// ------------------------------------------------------------addaction to player to save data--------------------------------------------------------------------
player addAction ["<t color='#38BAFF'>Save Game</t>", {[] call UN_savedata;}];


// MrJizz - Factionfinderdotcom

-------------------------------------------------------------------------------------------------------
if you dont have these files heres a direct download for a sample mission just copy and paste what you need etc.
Dropbox - click here

Added 14 minutes later:

As i say you will need to edit this to suite your needs, i already know the health part of this script does not work with ace3 mod, but as i am using this mod myself i will be adding this ability, so if your interested let me know

This post was edited by mr.jizz (2017-08-22 11:54, ago)


Author Message


Posts: 31
Rank:


Level: Member

Country: uk
Location:
Occupation:
Age:
In-game name:

 
#2 Posted at 2016-10-15 16:00        
     
updated, now saves magazine ammo count in uniform/vest/backpack thanks to 654wak654 for pointing out "setUnitLoadout"


Advertisement


Author Message


Posts: 2
Rank:


Level: Member

Country: es
Location:
Occupation:
Age:
In-game name:

 
#3 Posted at 2016-10-23 12:39        
     
Hello, very good job, it helps me to know how the inibd2 works. Can you tell me how I can do to keep the player automatically without having to give Save Data.

Thank you very much

Sorry, my English is bad, I use Google Translator.


Author Message


Posts: 31
Rank:


Level: Member

Country: uk
Location:
Occupation:
Age:
In-game name:

 
#4 Posted at 2016-10-28 19:18        
     
You can add the save data to a loop in a seperate sqf if you like?, or use an eventhandler to detect when esc button is pressed (something i may be using)


Author Message


Posts: 2
Rank:


Level: Member

Country: es
Location:
Occupation:
Age:
In-game name:

 
#5 Posted at 2016-10-31 20:35        
     
Ok, thanks, I look to loop sql to save data.


Author Message


Posts: 3
Rank:


Level: Member

Country: fr
Location:
Occupation:
Age:
In-game name:

 
#6 Posted at 2017-01-26 14:14        
     
Hello,

Nice job "MrJizz", but i have a problem with your code "ini". ( sorry for my english^^)
Your code find the data base and save équippement and position, but when an other player connect to the server all my stuff disappear!
anyone can help me please!


Author Message


Posts: 1589
Rank:


Level: Member

Country: pf
Location: Tahiti
Occupation: too many Arma
Age: 60
In-game name: Kobayashi Maru

 
#7 Posted at 2017-01-26 15:49        
     
That looks like an overriding of public variables. Are you sure to use and name them correctly: initServer.sqf and initPlayerLocal.sqf?

PLEASE CONTACT ME ON BI FORUMS FOR ANY SCRIPT / MOD QUESTION. TKS

Author Message


Posts: 3
Rank:


Level: Member

Country: fr
Location:
Occupation:
Age:
In-game name:

 
#8 Posted at 2017-01-26 20:14        
     
Yes I've proceed like that : Enter text for the link here...


Author Message

zuzul  



Posts: 1
Rank:


Level: Member

Country: fr
Location:
Occupation:
Age:
In-game name:

 
#9 Posted at 2017-02-14 13:22        
     
Hi there!
Thanks a lot for those scripts, they're really helpful to understand how a bloddy save is working on Arma.

I also got the same result as hérétique on my server.
I'm using TADST to create the dedicated server.
I made a first mistake by having the Inidbi mod on every client. Since the variables are public, you can imagine the lag and the result of having everyone naked all the time...I made everyone remove it as soon as possible ^^
Now the -serverMod params is correctly enabled and is working properly.

I've put the initServer.sqf/initPlayerLocal.sqf at the root of my mission folder.

Everything is working flawlessly until another player join the mission: then, the scripts seems to unequip all items on the players. Each time we try to take any item (weapon, clothes...) when the save/load scripts are activated, the character is back to being naked and the DB file of the character is back to being empty.
I will try to check if my buddies have correctly unistalled the Indbi mod, because that's the only issue I can think of.

Any advice is welcomed.


Author Message


Posts: 1589
Rank:


Level: Member

Country: pf
Location: Tahiti
Occupation: too many Arma
Age: 60
In-game name: Kobayashi Maru

 
#10 Posted at 2017-02-14 16:33        
     
You're right. InitServer runs once at start and on server only. Not affected by JIP.
All JIP runs initPlayerLocal ... locally. I don't have any problem with specific loadout here. So, you should have someWhere a "public" variable:
- declared as is. So track publicVariable command in all your scripts;

- as any init field of unit(s). These fields are useful for easy configuration but we often forget the mission.sqm runs at each players, overriding (resetting) the code everywhere if not specified if (isServer) then {..}

- in init.sqf itself, running also at each player start.

So, try to track the publicVariable (as a string in text editor), and /or forceAddUniform or even just uniform, and/or loadout in all your scripts.

PLEASE CONTACT ME ON BI FORUMS FOR ANY SCRIPT / MOD QUESTION. TKS

Author Message


Posts: 3
Rank:


Level: Member

Country: fr
Location:
Occupation:
Age:
In-game name:

 
#11 Posted at 2017-02-16 20:34        
     
Tanks you for your answer,
I'am very bad in English and very bad in code for Arma 3, I've don't understand what i have to do.
Have you an exemple to explain this?

thank you for your patience


Author Message


Posts: 31
Rank:


Level: Member

Country: uk
Location:
Occupation:
Age:
In-game name:

 
#12 Posted at 2017-08-22 10:24        
     
Yah sorry guys i havent been on in a while, i know off this issue, as noted by pierre, publicvariables are being over written as they activate on all computers (ie players), i may tryn fix this issue, i think i should be using publicvariableclient (i think i had issues with this before?) or maybe try adding an 'if' to check player uid.

if i find a fix i will certainly update!, sorry again

Added 4 minutes later:

Sorry i am already using publicvariableclient , i think the issue is using 'owner' instead of 'clientowner'

Added 1 hour 29 minutes later:

# zuzul : Hi there!
Thanks a lot for those scripts, they're really helpful to understand how a bloddy save is working on Arma.

I also got the same result as hérétique on my server.
I'm using TADST to create the dedicated server.
I made a first mistake by having the Inidbi mod on every client. Since the variables are public, you can imagine the lag and the result of having everyone naked all the time...I made everyone remove it as soon as possible ^^
Now the -serverMod params is correctly enabled and is working properly.

I've put the initServer.sqf/initPlayerLocal.sqf at the root of my mission folder.

Everything is working flawlessly until another player join the mission: then, the scripts seems to unequip all items on the players. Each time we try to take any item (weapon, clothes...) when the save/load scripts are activated, the character is back to being naked and the DB file of the character is back to being empty.
I will try to check if my buddies have correctly unistalled the Indbi mod, because that's the only issue I can think of.

Any advice is welcomed.

ok, i done a quick edit from my phone, as i wont have alot off time to go through it all for some time, but i changed 'player' to clientOwner (hopefully it will kinda remote execute on the target only), just re-copy and paste the script and let me know how you get on!

This post was edited by mr.jizz (2017-08-22 11:58, ago)