18.05.2015, 01:42
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?
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(playerid, pInfo[playerid][pPos][0], pInfo[playerid][pPos][1], pInfo[playerid][pPos][2]);
SetPlayerFacingAngle(playerid, pInfo[playerid][pPos][3]);
SetPlayerVirtualWorld(playerid, pInfo[playerid][pPosInt][0]);
SetPlayerInterior(playerid, pInfo[playerid][pPosInt][1]);
return 1;
}
// On GameModeInit
mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_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 aExplode, iLength = sizeof aExplode[]) // Created by Westie
{
new
iNode,
iPointer,
iPrevious = -1,
iDelimiter = strlen(sDelimiter);
while(iNode < iVertices)
{
iPointer = strfind(sSource, sDelimiter, false, iPointer);
if(iPointer == -1)
{
strmid(aExplode[iNode], sSource, iPrevious, strlen(sSource), iLength);
break;
}
else
{
strmid(aExplode[iNode], sSource, iPrevious, iPointer, iLength);
}
iPrevious = (iPointer += iDelimiter);
++iNode;
}
return iPrevious;
}
MySQL_Register(playerid, passwordstring[])
{
new query1[350];
format(query1, sizeof(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), passwordstring, pInfo[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(query2, sizeof(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(row, field, "|");
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(playerid, pInfo[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:x, Float:y, Float:z, Float:a;
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, a);
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(query, sizeof(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;
}