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

Hi everyone,


I want to know, how could I do a system to update player informations every X time.
I'm using a mysql database, with BlueG (+ maddinat0r) plugin.

Thank you.
Reply
#2

No ideas ?
Reply
#3

http://dev.mysql.com/doc/refman/5.0/en/update.html
Reply
#4

you dont need to update every x time, you need to update when field value changes, like player money, save it only when when player get/lose money.

GivePlayerMoneyEx(playerid,amount)
{
mysql_query...
GivePlayerMoney(playerid,amount);
}
Reply
#5

@iKey07

But me I want to save it every X time. Cause if someone DDOS server and the server just crash. Informations will be as they were before the attack
Reply
#6

Quote:
Originally Posted by ikey07
Посмотреть сообщение
you dont need to update every x time, you need to update when field value changes, like player money, save it only when when player get/lose money.

GivePlayerMoneyEx(playerid,amount)
{
mysql_query...
GivePlayerMoney(playerid,amount);
}
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.
Reply
#7

Okay, thank you !

How can I do to repeat a timer every X time please ?

Thank you
Reply
#8

https://sampwiki.blast.hk/wiki/SetTimer

Код:
SetTimer("SaveData", 10000, true); // Will repeat every 10 seconds. 10000ms

forward SaveData();
public SaveData()
{
    // Save your data here
}
Reply
#9

mysql and timers is bad combination, you will overheat mysql server on your host, also when someone ddos your data will be saved eventually.
Reply
#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


Forum Jump:


Users browsing this thread: 1 Guest(s)