SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 11/05/2014, 06:23 AM   #1
Deal-or-die
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

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!
__________________
/////////////////////////// | 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
Old 12/05/2014, 12:00 AM   #2
Deal-or-die
Huge Clucker
 
Deal-or-die's Avatar
 
Join Date: Oct 2010
Location: An Island 1000's of miles away
Posts: 366
Reputation: 22
Default Re: Saving players last position

Sorry guys, still have this problem
__________________
/////////////////////////// | Mini Moot | \\\\\\\\\\\\\\\\\\\\\\\\\\\

"I'm in the country that basically invented the Internet, and your getting faster speeds on an island 1,000miles away"
Deal-or-die is offline   Reply With Quote
Old 12/05/2014, 12:13 AM   #3
MasonSFW
Huge Clucker
 
MasonSFW's Avatar
 
Join Date: Feb 2014
Location: Thailand
Posts: 302
Reputation: 14
Default Re: Saving players last position

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);
}
__________________
5.175.181.128:7777 - Updated 2015

Join us, Great community .

_________________________________________________
My work:
MasonSFW is offline   Reply With Quote
Old 12/05/2014, 03:15 AM   #4
Deal-or-die
Huge Clucker
 
Deal-or-die's Avatar
 
Join Date: Oct 2010
Location: An Island 1000's of miles away
Posts: 366
Reputation: 22
Default [FIXED]Re: Saving players last position

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.
__________________
/////////////////////////// | 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:45 AM.
Deal-or-die is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving position. zClaw Scripting Help 4 30/05/2013 06:50 PM
[HELP] Skin Saving / Position Saving. andershh Help Archive 3 13/07/2010 10:20 AM
Position Saving Sascha Help Archive 2 25/05/2010 11:43 PM
Position saving martyz-lithuania Help Archive 5 23/04/2010 01:24 PM
Position Saving Bug Jbosh123 Help Archive 7 20/03/2010 11:09 AM


All times are GMT. The time now is 10:38 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.