Mysql save wrong variables - mixing pSpawn and pSkin
#1

In script when I set player Skin for example to: 288 ( PlayerInfo[playerid] = 288; )

And when I save it to mysql base on player disconnect it saves under pSpawn 288 and under pSkin 49 for unknown reason. Here is the code:

PHP код:
    format(JLstringsizeof(JLstring), "UPDATE `players` SET `Tutorial` = %d, `HoursGameplay` = %d, `LastOnline` = '%e',"PlayerInfo[playerid][pTutorial], PlayerInfo[playerid][pHoursGameplay], PlayerInfo[playerid][pLastOnline]);
    
strcat(stringJLstring);
    
format(JLstringsizeof(JLstring), "`LatestIP` = '%e', `Skin` = %d, `Spawn` = %d, `VirtualWorld` = %d, `Interior` = %d,"PlayerInfo[playerid][pLatestIP], PlayerInfo[playerid][pSkin], PlayerInfo[playerid][pSpawn], PlayerInfo[playerid][pVirtualWorld], PlayerInfo[playerid][pInterior]);
    
strcat(stringJLstring);
    
format(JLstringsizeof(JLstring), "`Kills` = %d, `Deaths` = %d, `Hunger` = %d, `Thirst` = %d,"PlayerInfo[playerid][pKills], PlayerInfo[playerid][pDeaths], PlayerInfo[playerid][pHunger], PlayerInfo[playerid][pThirst]);
    
strcat(stringJLstring);
    
format(JLstringsizeof(JLstring), "`AdminLevel` = %d, `LeaderCoord` = %d, `AdminPin` = %d, `LeaderCoordPin` = %d,"PlayerInfo[playerid][pAdminLevel], PlayerInfo[playerid][pLeaderCoord], PlayerInfo[playerid][pAdminPin], PlayerInfo[playerid][pLeaderCoordPin]);
    
strcat(stringJLstring);
    
format(JLstringsizeof(JLstring), "`Leader` = %d, `LeaderPin` = %d, `Member` = %d, `Rank` = %d, `OrgContract` = %d, `OrgDelivers` = %d, `OrgTasks` = %d,"PlayerInfo[playerid][pLeader], PlayerInfo[playerid][pLeaderPin], PlayerInfo[playerid][pMember], PlayerInfo[playerid][pRank], PlayerInfo[playerid][pOrgContract], PlayerInfo[playerid][pOrgDelivers], PlayerInfo[playerid][pOrgTasks]);
    
strcat(stringJLstring);
    
format(JLstringsizeof(JLstring), "`SubOrgLeader` = %d, `SubOrgMember` = %d, `SubOrgRank` = %d, `SubOrgContract` = %d, `SubOrgTasks` = %d, `Roadblock` = %d WHERE `ID` = %d LIMIT 1"PlayerInfo[playerid][pSubOrgLeader], PlayerInfo[playerid][pSubOrgMember], PlayerInfo[playerid][pSubOrgRank], PlayerInfo[playerid][pSubOrgContract], PlayerInfo[playerid][pSubOrgTasks], PlayerInfo[playerid][pRoadblock], PlayerInfo[playerid][pID]);
    
strcat(stringJLstring);
    
mysql_format(DatabaseDB_Querysizeof(DB_Query), string);
    
mysql_tquery(DatabaseDB_Query); 
Sometimes it won't save pSkin also...
Reply
#2

%e isn't a valid specifier for the native format function (`LatestIP` = '%e'), you should use mysql_format instead.
Reply
#3

Quote:
Originally Posted by Abagail
Посмотреть сообщение
%e isn't a valid specifier for the native format function (`LatestIP` = '%e'), you should use mysql_format instead.
Will it work? Here I'm formating string to put it later in mysql format/query?
Reply
#4

Can I do something like:

mysql_format...
mysql_format...
mysql_format...
mysql_tquery

Or I have to do like:

mysql_format...
mysql_tquery
mysql_format...
mysql_tquery
mysql_format...
mysql_tquery
Reply
#5

I'm just going to avoid giving an answer to that question by saying that you should not be saving everything at once. Save things as and when they change. You will use more queries but they will be lighter and more distributed.
Reply
#6

Quote:
Originally Posted by Vince
Посмотреть сообщение
I'm just going to avoid giving an answer to that question by saying that you should not be saving everything at once. Save things as and when they change. You will use more queries but they will be lighter and more distributed.
Okay, I'll save each variable on her change. But could you tell me what is different from this. Can I first format like 2 times than query it or I have to go query for each format individual. I think it's not the same?
Reply
#7

Quote:
Originally Posted by Saddin
Посмотреть сообщение
Okay, I'll save each variable on her change. But could you tell me what is different from this. Can I first format like 2 times than query it or I have to go query for each format individual. I think it's not the same?
I don't think it will be a good idea to use query much time because forex you would need a WHERE clause twice, but in a single query you will need it only once.
Reply
#8

Quote:
Originally Posted by Vince
Посмотреть сообщение
I'm just going to avoid giving an answer to that question by saying that you should not be saving everything at once. Save things as and when they change. You will use more queries but they will be lighter and more distributed.
Isn't good to save one or two times all things related to player's data (for example) ?
Reply
#9

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
Isn't good to save one or two times all things related to player's data (for example) ?
It's bad because you first need to make huge arrays which will cause these memory issues or whatever you call that (that table appears after you compile) so you'll need to use pragma dynamic and second players will lose all of their data if the server crashes for example.
Reply
#10

Quote:
Originally Posted by GoldenLion
Посмотреть сообщение
It's bad because you first need to make huge arrays which will cause these memory issues or whatever you call that (that table appears after you compile) so you'll need to use pragma dynamic and second players will lose all of their data if the server crashes for example.
What about saving each player data when server crash?
Reply
#11

Quote:
Originally Posted by Saddin
Посмотреть сообщение
What about saving each player data when server crash?
How are you going to do that if the server crashes?
Reply
#12

Quote:
Originally Posted by GoldenLion
Посмотреть сообщение
How are you going to do that if the server crashes?
When server crash OnGameModeExit is called?
Reply
#13

Quote:
Originally Posted by Saddin
Посмотреть сообщение
When server crash OnGameModeExit is called?
Nothing is called when a server crashes.
Reply
#14

Quote:
Originally Posted by GoldenLion
Посмотреть сообщение
Nothing is called when a server crashes.
Than player data is saved when it's changed only.
Reply
#15

Quote:
Originally Posted by GoldenLion
Посмотреть сообщение
It's bad because you first need to make huge arrays which will cause these memory issues or whatever you call that (that table appears after you compile) so you'll need to use pragma dynamic and second players will lose all of their data if the server crashes for example.
So.. We have never to do SavePlayerStats(playerid) for example? On my filterscript, I'm doing it only when I unload it. I need it at least one time or I'm doing it wrong?
Reply
#16

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
So.. We have never to do SavePlayerStats(playerid) for example? On my filterscript, I'm doing it only when I unload it. I need it at least one time or I'm doing it wrong?
As Vince said you should save something after any change, for example when you give player money, update money in the database as well.
Reply
#17

Quote:
Originally Posted by GoldenLion
Посмотреть сообщение
As Vince said you should save something after any change, for example when you give player money, update money in the database as well.
Nope, thats not recommended. I think he meant to say that variables which don't change frequently should be directly saved or loaded to/from the database and should not have any global variable for itself.
Reply
#18

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
So.. We have never to do SavePlayerStats(playerid) for example? On my filterscript, I'm doing it only when I unload it. I need it at least one time or I'm doing it wrong?
Said with easier words; when you change something as it updates - lets say someone gives a player $1000 - Instead of just saving this into his variables, you update the database straight away.

If you update the database frequently, whenever (mostly) when something changes, you avoid the server being overloaded by saving EVERYTHING once in a while. It's way more demanding and issues may occur. This is also referred to as Load Balancing. Wikipedia page here.

So - it's highly recommended
Reply
#19

Quote:
Originally Posted by Tord
Посмотреть сообщение
Said with easier words; when you change something as it updates - lets say someone gives a player $1000 - Instead of just saving this into his variables, you update the database straight away.
Bad idea of cash as Gammix had already stated that calling queries for frequent changes such as kills, deaths, cash, score etc is bad. Now you can easily see if it is good to have a whole query for frequent things Or calling queries for every change.
Reply
#20

Quote:
Originally Posted by coool
Посмотреть сообщение
Bad idea of cash as Gammix had already stated that calling queries for frequent changes such as kills, deaths, cash, score etc is bad. Now you can easily see if it is good to have a whole query for frequent things Or calling queries for every change.
It was a bad example. My intention was to say, do not update all data at once. perhaps a good solution would be to update cash and score at the disconnect, but regarding levels and other settings you may want to update them through the change.
There is no correct answer here, you just have to form it for your own server and make it balance how you'd think it's working best.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)