View Single Post
Old 11/05/2014, 06:23 AM   #1
Huge Clucker
Deal-or-die's Avatar
Join Date: Oct 2010
Location: An Island 1000's of miles away
Posts: 366
Reputation: 22
Question [FIXED]Saving players last position


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);

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

/////////////////////////// | Mini Moot | \\\\\\\\\\\\\\\\\\\\\\\\\\\

"I'm in the country that basically invented the Internet, and your getting faster speeds on an island 1,000miles away"

Last edited by Deal-or-die; 12/05/2014 at 08:46 AM.
Deal-or-die is offline   Reply With Quote