Jump to content
Arconymos

Best time to save player on server to a database

Recommended Posts

Hello, 

 

i am currently working on a small mission with a persistent map. The players and vehicles are saved into a mysql database. Everytime i saving a player, there is a short moment of stuttering of the game (around 0,5sec). It is very annoying if i save each player every 5 seconds. 
Now i asking myself if there are events that i can register my save function to. I've tried the OnPlayerDisconnect and HandleDisconnect events -> None of them works. 
My save function needs the player object as a parameter. 

Is there someone who can give me an advice?

Thanks. 

Share this post


Link to post
Share on other sites

At the start of the mission you could load the database from mysql into the missionNamespace (or similar) and use the default arma commands to edit and save variables during the mission. When the mission ends or the server restart you can now save the variables in the mysql database. Should be way more efficient since it is not a file operation each time.

Share this post


Link to post
Share on other sites

If you only need the player object and not his local variables, HandleDisconnect works great (it has to be executed on the server)

I'm using it in my mission. 

 

21 hours ago, 7erra said:

At the start of the mission you could load the database from mysql into the missionNamespace (or similar) and use the default arma commands to edit and save variables during the mission. When the mission ends or the server restart you can now save the variables in the mysql database. Should be way more efficient since it is not a file operation each time.

 

That's a solution but if the server crash for whatever reason, nothing will be saved 

Share this post


Link to post
Share on other sites
On 3/6/2019 at 5:17 PM, Arconymos said:

Hello, 

 

i am currently working on a small mission with a persistent map. The players and vehicles are saved into a mysql database. Everytime i saving a player, there is a short moment of stuttering of the game (around 0,5sec). It is very annoying if i save each player every 5 seconds. 
Now i asking myself if there are events that i can register my save function to. I've tried the OnPlayerDisconnect and HandleDisconnect events -> None of them works. 
My save function needs the player object as a parameter. 

Is there someone who can give me an advice?

Thanks. 

 

 

initServer.sqf //example

addMissionEventHandler ["HandleDisconnect", {
	params ["_unit", "_id", "_uid", "_name"];

  _gear = getUnitLoadout _unit;
  [_unit,_gear] remoteExec ["fox_alive_fnc_savePlayer",2];
  format["%1 left the server.",_name] remoteExec ["systemChat",-2];

}];

 

Share this post


Link to post
Share on other sites
2 hours ago, DeathF0X said:

 

 

initServer.sqf //example


addMissionEventHandler ["HandleDisconnect", {
	params ["_unit", "_id", "_uid", "_name"];

  _gear = getUnitLoadout _unit;
  [_unit,_gear] remoteExec ["fox_alive_fnc_savePlayer",2];
  format["%1 left the server.",_name] remoteExec ["systemChat",-2];

}];

 

You don't need to remoteExec to the server if you already are on the server

Share this post


Link to post
Share on other sites

Is it ok to ask here, where could you save if you are saving the whole mission but not players?

 

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

×