Saving players last position
#1

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!
Reply


Messages In This Thread
[FIXED]Saving players last position - by Deal-or-die - 11.05.2014, 06:23
Re: Saving players last position - by Deal-or-die - 12.05.2014, 00:00
Re: Saving players last position - by MasonSFW - 12.05.2014, 00:13
[FIXED]Re: Saving players last position - by Deal-or-die - 12.05.2014, 03:15

Forum Jump:


Users browsing this thread: 1 Guest(s)