How could I do a system to update player informations in Database ?
#10

Quote:
Originally Posted by Shetch
Посмотреть сообщение
This is definetly a good idea.
Or you can updeate the player's data only when he disconnects.

EDIT: In that case just set up a timer under OnGameModeInit.
Be sure to use threaded queries, and don't use them too often, or you will experience lag with large ammount of players online.

Thank you, I did this:

Код:
public SauvegardeJoueurs()
{
	for(new i = 0; i < MAX_PLAYERS; i++)
	{
		if(IsPlayerConnected(i))
		{
			SauvegardeJoueur(i);
		}
	}
}

public SauvegardeJoueur(playerid)
{
	if(IsPlayerConnected(playerid))
	{
		new query[1024];
		mysql_format(mysql, query, sizeof(query),"SELECT * FROM `joueurs` WHERE `Username` = '%e' LIMIT 1", Name[playerid]);
		new Float:pos[3]; 
		GetPlayerPos(playerid, pos[0], pos[1], pos[2]); 
		mysql_format(mysql, query, sizeof(query), "UPDATE `joueurs` SET `DerniereIP`='%s', `Admin`=%d, `VIP`=%d, `Argent`=%d, `posX`=%f, `posY`=%f, `posZ`=%f, `Interieur`=%i, `World`=%i, `Skin`=%d, `Niveau`=%d WHERE `ID`=%d",\
		IP[playerid], pInfo[playerid][Admin], pInfo[playerid][VIP], pInfo[playerid][Argent], pos[0], pos[1], pos[2], GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid), pInfo[playerid][Skin], pInfo[playerid][Niveau], pInfo[playerid][ID]);
		mysql_tquery(mysql, query, "", "");
		new Float:vie[1], Float:armure[1];
		GetPlayerHealth(playerid, vie[0]);
		GetPlayerArmour(playerid, armure[0]);
		mysql_format(mysql, query, sizeof(query), "UPDATE `joueurs` SET `Vie`=%f, `Armure`=%f WHERE `ID`=%d", vie[0], armure[0], pInfo[playerid][ID]);
		mysql_tquery(mysql, query, "", "");
	}
}
Is this correct ?
I put a timer every 5 minutes, is it too much and will cause lags or is that good ?
Can I do it every minute or it's useless ?


Are my queries good ? Or it isn't threaded queries ?
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)