[FIXED]Saving players last position -
Deal-or-die - 11.05.2014
G'day.
Okay... I am pretty lost on how to explain what's happening without confusing ya.
Basically, When you login, you spawn where you logged out 2 times ago.
1 Login - Freight Roof
1 Logout -
Street near pizza place
2 Login -
Pizza Roof
2 Logout -
Shipping containers
3 Login -
Street near pizza place
3 Logout -
Building ruins
4 Login -
Shipping containers
4 Logout -
Freight Depot
5 Login -
Building Ruins
5 Logout -
Paddock
6 Login -
Freight Depot
6 logout -
House
7 Login -
Paddock
7 Logout - Bridge
8 Login -
House
This is the login Dialog that handles the setting of player Pos
pawn Code:
if(!strcmp(hpass, pInfo[playerid][Password]))
{
mysql_format(mysql, query, sizeof(query), "SELECT * FROM `players` WHERE `Username` = '%e' LIMIT 1", Name[playerid]);
mysql_tquery(mysql, query, "OnAccountLoad", "i", playerid);
pInfo[playerid][LoggedIn] = 1;
SetSpawnInfo(playerid, 0, 240, pInfo[playerid][posX], pInfo[playerid][posY], pInfo[playerid][posZ], SpawnA, 0,0,0,0,0,0);
SpawnPlayer(playerid);
}
OnAccountLoad
pawn Code:
public OnAccountLoad(playerid)
{
pInfo[playerid][Admin] = cache_get_field_content_int(0, "Admin");
pInfo[playerid][VIP] = cache_get_field_content_int(0, "VIP");
pInfo[playerid][Money] = cache_get_field_content_int(0, "Money");
pInfo[playerid][posX] = cache_get_field_content_float(0, "PosX");
pInfo[playerid][posY] = cache_get_field_content_float(0, "PosY");
pInfo[playerid][posZ] = cache_get_field_content_float(0, "PosZ");
GivePlayerMoney(playerid, pInfo[playerid][Money]);
SendClientMessage(playerid, -1, "Successfully logged in");
return 1;
}
Annnd this is OnPlayerDisconnect
pawn Code:
public OnPlayerDisconnect(playerid, reason)
{
new query[128], Float:pos[3];
GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
mysql_format(mysql, query, sizeof(query), "UPDATE `players` SET `Admin`=%d, `VIP`=%d, `Money`=%d, `posX`=%f, `posY`=%f, `posZ`=%f WHERE `ID`=%d",\
pInfo[playerid][Admin], pInfo[playerid][VIP], pInfo[playerid][Money], pos[0], pos[1], pos[2], pInfo[playerid][ID]);
mysql_tquery(mysql, query, "", "");
return 1;
}
Any ideas?
I am new to MySQL so just on a learning curve at the moment.
I assume it's something to do with 'cache_get_field_content_float' in 'OnAccountLoad' But I'll leave that assumption up to you guys :P
Cheers!
Re: Saving players last position -
Deal-or-die - 12.05.2014
Sorry guys, still have this problem
Re: Saving players last position -
MasonSFW - 12.05.2014
if(!strcmp(hpass, pInfo[playerid][Password],
true))
{
mysql_format(mysql, query, sizeof(query), "SELECT * FROM `players` WHERE `Username` = '%e' LIMIT 1", Name[playerid]);
mysql_tquery(mysql, query, "OnAccountLoad", "i", playerid);
pInfo[playerid][LoggedIn] = 1;
SetSpawnInfo(playerid, 0, 240, pInfo[playerid][posX], pInfo[playerid][posY], pInfo[playerid][posZ], SpawnA, 0,0,0,0,0,0);
SpawnPlayer(playerid);
}
[FIXED]Re: Saving players last position -
Deal-or-die - 12.05.2014
Cheers Mason but no go :/
I added a line to print my XYZ position On numerous cases, logged in, ran around for a bit and then logged out. Here are the results... Not good. :/
pawn Code:
public OnPlayerDisconnect(playerid, reason)
{
new query[128], Float:pos[3];
GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
mysql_format(mysql, query, sizeof(query), "UPDATE `players` SET `Admin`=%d, `VIP`=%d, `Money`=%d, `posX`=%f, `posY`=%f, `posZ`=%f WHERE `ID`=%d", Player[playerid][Admin], Player[playerid][VIP], Player[playerid][Money], pos[0], pos[1], pos[2], Player[playerid][ID]);
mysql_tquery(mysql, query, "", "");
printf("OnPlayerDisconnect: X:%f Y:%f Z:%f", pos[0], pos[1], pos[2]);
return 1;
}
pawn Code:
public OnPlayerSpawn(playerid)
{
printf("OnPlayerSpawn: X:%f Y:%f Z:%f", Player[playerid][posX], Player[playerid][posY], Player[playerid][posZ]);
// SetPlayerPos(playerid, Player[playerid][posX], Player[playerid][posZ], Player[playerid][posZ]);
//Set player's position to the last saved position.
return 1;
}
pawn Code:
public OnAccountLoad(playerid)
{
pInfo[playerid][Admin] = cache_get_field_content_int(0, "Admin");
pInfo[playerid][VIP] = cache_get_field_content_int(0, "VIP");
pInfo[playerid][Money] = cache_get_field_content_int(0, "Money");
pInfo[playerid][posX] = cache_get_field_content_float(0, "PosX");
pInfo[playerid][posY] = cache_get_field_content_float(0, "PosY");
pInfo[playerid][posZ] = cache_get_field_content_float(0, "PosZ");
GivePlayerMoney(playerid, pInfo[playerid][Money]);
printf("OnAccountLoad: X:%f Y:%f Z:%f", Player[playerid][posX], Player[playerid][posY], Player[playerid][posZ]);
SendClientMessage(playerid, -1, "Successfully logged in");
return 1;
}
Code:
[12:01:39] OnAccountLoad: X:1370.969970 Y:264.326995 Z:19.566900
[12:01:39] OnPlayerSpawn: X:1370.969970 Y:264.326995 Z:19.566900
[12:02:08] OnPlayerDisconnect: X:1442.952758 Y:291.002258 Z:19.224281
Cleaned up a lot of useless shit, made a spawning/saving stock and all works now.