MySQL saving problem
#1

Guys i have a problem that when i set kills or any thing in player stats and relog it didn't load it why ?

PHP код:
public OnAccountCheck(playerid)
{
    new 
rowsfields//a variable that will be used to retrieve rows and fields in the database.
    
cache_get_data(rowsfieldsmysql);//let's get the rows and fields from the database.
    
if(rows//if there is row
    
{
        
cache_get_field_content(0"IP"IP[playerid], mysql16);
        new 
newIP[16];
        
GetPlayerIp(playeridnewIP16);
        
IsPlayerRegisterd[playerid] = 1;
        if(
strlen(IP[playerid]) != && !strcmp(IP[playerid], newIPtrue)) //Checks that the MySQL IP has a value and that they are the same.
        
{
            
/*GameTextForPlayer(playerid, "Loading Account", 3000, 3);
            SetTimerEx("OnAccountLoad", 3000, false, "i", playerid);*/
            
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,MAX_PLAYER_NAME);
new 
query[100];
format(query,sizeof(query),"SELECT * FROM `players` WHERE Username = '%s'",name);
mysql_tquery(mysqlquery"OnAccountLoad2""i"playerid);
        }
        else
        {
            (!
strlen(IP[playerid]) || strcmp(IP[playerid], newIPtrue));
            
//then
            
cache_get_field_content(0"Password"pData[playerid][Password], mysql129);
            
//we will load player's password into pData[playerid][Password] to be used in logging in
            
pData[playerid][ID] = cache_get_field_content_int(0"ID"); //now let's load player's ID into pData[playerid][ID] so we can use it later
            
printf("%s"pData[playerid][Password]); //OPTIONAL: Just for debugging. If it didn't show your password, then there must be something wrong while getting player's password
            
new st4[2016+1000];
            
ShowPlayerDialog(playeriddLOGINDIALOG_STYLE_INPUT"Login""In order to play, you need to login""Login""Quit"); //And since we found a result from the database, which means, there is an account; we will show a login dialog
        
}
    }
    else 
//if we didn't find any rows from the database, that means, no accounts were found
    
{
        
ShowPlayerDialog(playeriddREGISTERDIALOG_STYLE_INPUT"Register""In order to play, you need to register.""Register""Quit");
        
//So we show them a dialog register
    
}
    return 
1;
}
public 
OnPlayerDisconnect(playeridreason)
{
        new 
playerName[MAX_PLAYER_NAME], string[56];
    
GetPlayerName(playeridplayerNamesizeof(playerName));
    switch(
reason)
    {
        case 
0format(stringsizeof(string), "%s has left the server. (Ping Timeout)"playerName);
        case 
1format(stringsizeof(string), "%s has left the server. (Left/Leave)"playerName);
        case 
2format(stringsizeof(string), "%s has left the server. (Kicked/Banned)"playerName);
    }
    
SendClientMessageToAll(0xFF0000Fstring);
SavePlayerData(playerid);
    return 
1;
}
public 
OnAccountLoad(playerid)
{
    new 
score,string[134];
     
pData[playerid][Admin] = cache_get_field_content_int(0"Admin"); //we're getting a field 4 from row 0. And since it's an integer, we use cache_get_row_int
     
pData[playerid][VIP] = cache_get_field_content_int(0"VIP"); //Above
     
pData[playerid][Money] = cache_get_field_content_int(0"Money");//Above
     
pData[playerid][Kills] = cache_get_field_content_int(0,"Kills");
     
pData[playerid][Deaths] = cache_get_field_content_int(0"Deaths");
     
score cache_get_field_content_int(0"Score");
     
SetPlayerScore(playeridscore);
     
GivePlayerMoney(playeridpData[playerid][Money]);//Let's set their money
     //For player's position, set it once they spawn(OnPlayerSpawn)
     
format(string,sizeof(string),"* Login Successful... Welcome back to XtremeX %s!",GetName(playerid));
    
SendClientMessage(playerid0xFF0000Fstring); //tell them that they have successfully logged in
    
SendClientMessage(playerid,COLOR_YELLOW,"---------------------------------------");
    
SendClientMessage(playerid,0xFFAA00FF,"Type /cmds or /commands to view our commands");
    
SendClientMessage(playerid,0xFFAA00FF,"Type /credits to check the server creators");
    
SendClientMessage(playerid,COLOR_YELLOW,"---------------------------------------");
    return 
1;
}
public 
OnAccountLoad2(playerid)
{
    new 
score,string[134];
     
pData[playerid][Admin] = cache_get_field_content_int(0"Admin"); //we're getting a field 4 from row 0. And since it's an integer, we use cache_get_row_int
     
pData[playerid][VIP] = cache_get_field_content_int(0"VIP"); //Above
     
pData[playerid][Money] = cache_get_field_content_int(0"Money");//Above
     
pData[playerid][Kills] = cache_get_field_content_int(0,"Kills");
     
pData[playerid][Deaths] = cache_get_field_content_int(0"Deaths");
     
score cache_get_field_content_int(0"Score");
     
SetPlayerScore(playeridscore);
     
GivePlayerMoney(playeridpData[playerid][Money]);//Let's set their money
     //For player's position, set it once they spawn(OnPlayerSpawn)
    
format(string,sizeof(string),"* Auto-IP Login Successful... Welcome back to XtremeX %s!",GetName(playerid));
    
SendClientMessage(playerid,0xFF0000F,string);
    return 
1;
}
public 
OnAccountRegister(playerid)
{
    
pData[playerid][ID] = cache_insert_id(); //loads the ID of the player in the variable once they registered.
    
printf("New account registered. ID: %d"pData[playerid][ID]); //just for debugging.
    
pData[playerid][Money] = 50000;
    
GivePlayerMoney(playerid50000);
    return 
1;

Help guys
Reply
#2

Use mysql_format with %e instead of %s.
And i don't think using the IP check on login is a good way, Since some players may not have a static IP.
Reply
#3

where i should edit the %s to %e?
Reply
#4

Where ever you use %s in mysql.
And why you have 2 OnAccountLoad?
Can you show me 'SavePlayerData(playerid);' function and the last mysql log.
Reply
#5

You're not saving any data, or you're not showing where you do. We need that.
Reply
#6

Quote:
Originally Posted by Keyhead
Посмотреть сообщение
You're not saving any data, or you're not showing where you do. We need that.
Quote:
Originally Posted by oMa37
Посмотреть сообщение
Where ever you use %s in mysql.
And why you have 2 OnAccountLoad?
Can you show me 'SavePlayerData(playerid);' function and the last mysql log.
PHP код:
stock SavePlayerData(playerid)
{
    new 
query[100];
    
mysql_format(mysqlquerysizeof(query), "UPDATE `players` SET `IP`='%s', `Admin`=%d, `VIP`=%d, `Kills`=%d, `Deaths`=%d, `Score`=%d, `Money`=%d WHERE `ID`=%d",\
    
IP[playerid], pData[playerid][Admin], pData[playerid][VIP], pData[playerid][Kills], pData[playerid][Deaths], GetPlayerScore(playerid), pData[playerid][Money], pData[playerid][ID]);
    
mysql_tquery(mysqlquery"""");

Logs:

Код:
[23:35:36] [DEBUG] Calling callback "OnAccountCheck"..
[23:35:36] [DEBUG] cache_get_data - connection: 1
[23:35:36] [DEBUG] cache_get_field_content - row: 0, field_name: "IP", connection: 1, max_len: 16
[23:35:36] [DEBUG] CMySQLResult::GetRowDataByName - row: '0', field: "IP", data: "127.0.0.1"
[23:35:36] [DEBUG] mysql_tquery - connection: 1, query: "SELECT * FROM `players` WHERE Username = 'Nour'", callback: "OnAccountLoad2", format: "i"
[23:35:36] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
[23:35:36] [DEBUG] CMySQLQuery::Execute[OnAccountLoad2] - starting query execution
[23:35:36] [DEBUG] CMySQLQuery::Execute[OnAccountLoad2] - query was successfully executed within 0.361 milliseconds
[23:35:36] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
[23:35:36] [DEBUG] Calling callback "OnAccountLoad2"..
[23:35:36] [DEBUG] cache_get_field_content_int - row: 0, field_name: "Admin", connection: 1
[23:35:36] [DEBUG] CMySQLResult::GetRowDataByName - row: '0', field: "Admin", data: "10"
[23:35:36] [DEBUG] cache_get_field_content_int - row: 0, field_name: "VIP", connection: 1
[23:35:36] [DEBUG] CMySQLResult::GetRowDataByName - row: '0', field: "VIP", data: "0"
[23:35:36] [DEBUG] cache_get_field_content_int - row: 0, field_name: "Money", connection: 1
[23:35:36] [DEBUG] CMySQLResult::GetRowDataByName - row: '0', field: "Money", data: "50000"
[23:35:36] [DEBUG] cache_get_field_content_int - row: 0, field_name: "Kills", connection: 1
[23:35:36] [DEBUG] CMySQLResult::GetRowDataByName - row: '0', field: "Kills", data: "0"
[23:35:36] [DEBUG] cache_get_field_content_int - row: 0, field_name: "Deaths", connection: 1
[23:35:36] [DEBUG] CMySQLResult::GetRowDataByName - row: '0', field: "Deaths", data: "0"
[23:35:36] [DEBUG] cache_get_field_content_int - row: 0, field_name: "Score", connection: 1
[23:35:36] [DEBUG] CMySQLResult::GetRowDataByName - row: '0', field: "Score", data: "0"
[23:35:36] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
whats the problem in it?

Guys i need it for fast

Any help guys,
Reply
#7

Have you forwarded your public OnAccountLoad2?
Try just using the original?
Reply
#8

i have the forward

And i made the second one to change the message

It save but doesnt load

please guys i need it.
Reply
#9

And i made the second one to change the message
Reply
#10

It save but doesnt load
Reply
#11

please guys i need it.
Reply
#12

Stop spamming after few hours please. OT, admin level and money are loading correctly, so make sure everything is saved correctly on your table, and try to debug your kills and deaths when you set em, maybe your /setkills is not working fine
Reply
#13

all load but Money, score , kills,deaths doesn't load
Reply
#14

But it save in the database?
Reply
#15

no, because only it saves when i edit from database not from server and when i try from server it doesn't save to database,

And the save stats in the database my id is 5 and when i type /savestats

its SavePlayerData it print saved id 0 and iam 5 in database
Reply
#16

whats the problem
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)