SA-MP Forums Archive
Saving/Loading Positions - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Saving/Loading Positions (/showthread.php?tid=574528)



Saving/Loading Positions - JaKe Elite - 18.05.2015

I have issues on saving & loading the float positions, along with the VirtualWorld & Interior.
It always sets to something which isn't the correct result, more of like being scrambled up by my messed up coding.

The VW & Int (on my last observation) always set to 19 / 1.

Can someone give me a hand on what i did wrong on loading/saving the float values/int/vw?

PHP код:
public OnPlayerSpawn(playerid)
{
    
SetPlayerPos(playeridpInfo[playerid][pPos][0], pInfo[playerid][pPos][1], pInfo[playerid][pPos][2]);
    
SetPlayerFacingAngle(playeridpInfo[playerid][pPos][3]);
    
SetPlayerVirtualWorld(playeridpInfo[playerid][pPosInt][0]);
    
SetPlayerInterior(playeridpInfo[playerid][pPosInt][1]);
    return 
1;
}
// On GameModeInit
mysql_connect(SQL_HOSTSQL_USERSQL_DBSQL_PASS);
mysql_query("CREATE TABLE IF NOT EXISTS players (username VARCHAR(24), password VARCHAR(40), level INT(20), cash INT(20), admin INT(1), donor INT(20), posx FLOAT, posy FLOAT, posz FLOAT, posa FLOAT, posvw INT(20), posint INT(20), IP VARCHAR(16) )");
mysql_debug(1);
if(
mysql_ping()>2)
print(
"INTRP: Connection to database failed.");
else print(
"INTRP: Connection to database successful.");
// Functions to Save/Load
explode(const sSource[], aExplode[][], const sDelimiter[] = " "iVertices sizeof aExplodeiLength sizeof aExplode[]) // Created by Westie
{
    new
        
iNode,
        
iPointer,
        
iPrevious = -1,
        
iDelimiter strlen(sDelimiter);
    while(
iNode iVertices)
    {
        
iPointer strfind(sSourcesDelimiterfalseiPointer);
        if(
iPointer == -1)
        {
            
strmid(aExplode[iNode], sSourceiPreviousstrlen(sSource), iLength);
            break;
        }
        else
        {
            
strmid(aExplode[iNode], sSourceiPreviousiPointeriLength);
        }
        
iPrevious = (iPointer += iDelimiter);
        ++
iNode;
    }
    return 
iPrevious;
}
MySQL_Register(playeridpasswordstring[])
{
    new 
query1[350];
    
format(query1sizeof(query1), "INSERT INTO `players` (`username`, `password`, `level`, `cash`, `admin`, `donor`, `posx`, `posy`, `posz`, `posa`, `posvw`, `posint`, `IP`) VALUES('%s', SHA1('%s'), 0, 0, 0, 0, 0.0, 0.0, 0.0, 0.0, 0, 0, '%s')"GetName(playerid), passwordstringpInfo[playerid][pIP]);
    
mysql_query(query1);
    
SendClientMessage(playerid, -1"You have been registered to International Roleplay (Saved in to our SQL database)");
    
    
pInfo[playerid][pLogged] = 1;
    return 
1;
}
MySQL_Login(playerid)
{
    new 
query2[300];
    
format(query2sizeof(query2), "SELECT * FROM `players` WHERE `username` = '%s'"GetName(playerid));
    
mysql_query(query2);
    
mysql_store_result();
    
    new 
row[128];
    new 
field[13][91];
    
mysql_fetch_row_format(row"|");
    
explode(rowfield"|");
    
mysql_free_result();
    
pInfo[playerid][pLevel] = strval(field[0]);
    
pInfo[playerid][pCash] = strval(field[1]);
    
pInfo[playerid][pAdmin] = strval(field[2]);
    
pInfo[playerid][pDonor] = strval(field[3]);
    
pInfo[playerid][pPos][0] = floatstr(field[4]);
    
pInfo[playerid][pPos][1] = floatstr(field[5]);
    
pInfo[playerid][pPos][2] = floatstr(field[6]);
    
pInfo[playerid][pPos][3] = floatstr(field[7]);
    
pInfo[playerid][pPosInt][0] = strval(field[8]);
    
pInfo[playerid][pPosInt][1] = strval(field[9]);
    
mysql_free_result();
    
    
GivePlayerMoney(playeridpInfo[playerid][pCash]);
    
SendClientMessage(playerid, -1"You have successfully logged in to your account on INTRP.");
    
pInfo[playerid][pLogged] = 1;
    return 
1;
}
MySQL_Save(playerid)
{
    new 
Float:xFloat:yFloat:zFloat:a;
    
GetPlayerPos(playeridxyz);
    
GetPlayerFacingAngle(playerida);
    
pInfo[playerid][pPos][0] = x;
    
pInfo[playerid][pPos][1] = y;
    
pInfo[playerid][pPos][2] = z;
    
pInfo[playerid][pPos][3] = a;
    
pInfo[playerid][pPosInt][0] = GetPlayerVirtualWorld(playerid);
    
pInfo[playerid][pPosInt][1] = GetPlayerInterior(playerid);
    
pInfo[playerid][pCash] = GetPlayerMoney(playerid);
    new 
query[600];
    
format(querysizeof(query), "UPDATE `players` SET `level`=%d, `cash`=%d, `admin`=%d, `donor`=%d, `posx`='%.3f', `posy`='%.3f', `posz`='%.3f', `posa`='%.3f', `posvw`=%d, `posint`=%d  WHERE `username`='%s'",\
           
pInfo[playerid][pLevel],
           
pInfo[playerid][pCash],
           
pInfo[playerid][pAdmin],
           
pInfo[playerid][pDonor],
           
pInfo[playerid][pPos][0], pInfo[playerid][pPos][1], pInfo[playerid][pPos][2], pInfo[playerid][pPos][3],
           
pInfo[playerid][pPosInt][0], pInfo[playerid][pPosInt][1], GetName(playerid));
    
mysql_query(query);
    return 
1;




Re: Saving/Loading Positions - DeathKing - 18.05.2015

I can't really help you with the information you've provided because there seems to be nothing wrong with your setup.. Check the SQL logs and print out the data for debug purposes... I also suggest you to use r37 or something higher and use the cache or object oriented SQL


Re: Saving/Loading Positions - JaKe Elite - 18.05.2015

The way how i load the data and storing them to variable is wrong & unarranged.

I have managed to fix them up by myself, thank you for the help by the way