MySQL - Floats + AccountID
#1

Hey guys, Iґve got 2 small Problems with MySQL

Iґm saving the players spawn positions and it should be set to them after a player relogs but it always sets my position to the same spot even when the positions are getting saved

And the 2nd Problem is that when I create another account it saves the Stats on the same row where the first player is saved


Codes:

PHP код:
public OnPlayerConnect(playerid)
{
    
SetPlayerColor(playerid0xBEBEBEFF);
    new 
query[1024];
    
GetPlayerName(playeridName[playerid], 24);
    
GetPlayerIp(playeridIP[playerid], 16);
    
mysql_format(mysqlquerysizeof(query),"SELECT `Password`, `ID` FROM `accounts` WHERE `Name` = '%e' LIMIT 1"Name[playerid]);
    
// - We use mysql_format instead of format because we can use an %e specifier. %e specifier escapes a string so we can avoid sql injection which means we don't have to use mysql_real_escape_string
    // - Formatting our query; SELECT `Password`, `ID` FROM `players` WHERE `Username`='%e' means we are selecting a Password and ID's column in the table that has player's name in Username column.
    // - LIMIT 1; we only need 1 result to be shown
    
mysql_tquery(mysqlquery"OnAccountCheck""i"playerid);
    
//lets execute the formatted query and when the execution is done, a callback OnAccountCheck will be called
    //You can name the callback however you like
    
return 1;

PHP код:
forward OnAccountCheck(playerid);
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)
    {
        
cache_get_field_content(0"Password"pInfo[playerid][Password], mysql129);
        
//we will load player's password into pInfo[playerid][Password] to be used in logging in
        
pInfo[playerid][ID] = cache_get_field_content_int(0"ID"); //now let's load player's ID into pInfo[playerid][ID] so we can use it later
        //printf("%s", pInfo[playerid][Password]); //OPTIONAL: Just for debugging. If it didn't show your password, then there must be something wrong while getting player's password
        
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_PASSWORD"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(playeridDIALOG_REGISTERDIALOG_STYLE_PASSWORD"Register""In order to play, you need to register.""Register""Quit");
        
//So we show them a dialog register
    
}
    return 
1;

PHP код:
public OnAccountRegister(playerid)
{
    
pInfo[playerid][ID] = cache_insert_id(); //loads the ID of the player in the variable once they registered.
    
printf("New account registered. ID: %d"pInfo[playerid][ID]); //just for debugging.
    
return 1;

PHP код:
public OnPlayerDisconnect(playeridreason)
{
    new 
Query[256];
    
GetPlayerPos(playeridpInfo[playerid][posX], pInfo[playerid][posY], pInfo[playerid][posZ]);
    
mysql_format(mysqlQuerysizeof(Query), "UPDATE accounts SET Score='%d', VIP='%d', Money='%d', PosX='%.6f', PosY='%.6f', PosZ='%.6f' WHERE ID='%d'",
    
pInfo[playerid][Score], pInfo[playerid][VIP], pInfo[playerid][Money], pInfo[playerid][posX], pInfo[playerid][posY], pInfo[playerid][posZ], pInfo[playerid][ID]);
    
printf("%s"Query);
    
mysql_tquery(mysqlQuery"""");
    return 
1;

PHP код:
public OnPlayerSpawn(playerid)
{
    
SetPlayerMapIconplayerid1701.8041,-519.4351,16.3318550MAPICON_LOCAL );
    
SetPlayerMapIconplayerid2661.3626,-573.4266,16.3359520MAPICON_LOCAL );
    
SetPlayerColor(playerid0xFFFFFFFF);
    
SetPlayerInterior(playerid,0);
    
SetPlayerVirtualWorld(playerid,0);
    
SetTimerEx("SetPos"600false"i"playerid);
    
    
SetPlayerSkin(playeridpInfo[playerid][pSkin]);
    
SetPlayerPos(playeridpInfo[playerid][posX], pInfo[playerid][posZ], pInfo[playerid][posZ]);
    return 
1;

PHP код:
forward SetPos(playerid);
public 
SetPos(playerid)
{
    
SetPlayerPos(playeridpInfo[playerid][posX], pInfo[playerid][posZ], pInfo[playerid][posZ]);
    return 
1;

Reply


Messages In This Thread
MySQL - Floats + AccountID - by Saize - 25.01.2015, 08:12
Re: MySQL - Floats + AccountID - by Ironboy - 25.01.2015, 09:35
AW: Re: MySQL - Floats + AccountID - by Saize - 25.01.2015, 09:53
Re: MySQL - Floats + AccountID - by Vince - 25.01.2015, 11:50
AW: Re: MySQL - Floats + AccountID - by Saize - 25.01.2015, 12:00
AW: Re: MySQL - Floats + AccountID - by Saize - 25.01.2015, 16:26
Re: MySQL - Floats + AccountID - by Ironboy - 25.01.2015, 16:30
AW: Re: MySQL - Floats + AccountID - by Saize - 26.01.2015, 18:55
AW: MySQL - Floats + AccountID - by Saize - 26.01.2015, 21:48
AW: Re: MySQL - Floats + AccountID - by Saize - 31.01.2015, 00:15

Forum Jump:


Users browsing this thread: 1 Guest(s)