SA-MP Forums Archive
Position saver [MySQL] - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Position saver [MySQL] (/showthread.php?tid=459804)



Position saver [MySQL] - x96664 - 24.08.2013

Hi everybody, reading this thread. I need your help to make a position saver for my server. I'm using MySQL R7 Plugin and I tried to make a position saver for my server but it didn't work at all. I need to save players position (x,y,z and angle) when player leaves the server and load them when they join again and log-in. Thanks in advance!


Re: Position saver [MySQL] - PaulDinam - 24.08.2013

If you have a table of 'users' with the next columns: x, y, z, a then it's simple.

Add this when player disconnects:

I'm pretty sure it should work

pawn Код:
new Float:x, Float:y, Float:z, Float:a;

GetPlayerFacingAngle(playerid, a);
GetPlayerPos(playerid, x, y, z);

format(query, sizeof(query), "UPDATE `users` SET `x` = %f, `y` = %f, `z` = %f, `a` = %f WHERE `name` = '%s'", x, y, z, a, GetName(playerid));
mysql_function_query(dbHandle, query, false, "", "");



//When player connects:

LoadPosition(playerid);


//Add those functions


stock LoadPosition(playerid)
{
        //You can use escapse string.
    format(query, sizeof(query), "SELECT * FROM `users` WHERE `name` = '%s' LIMIT 1", GetName(playerid));
    mysql_function_query(dbHandle, query, true, "InsertPosition", "i", playerid);
}

forward InsertPosition(playerid);
public InsertPosition(playerid)
{
    new rows, fields;
    cache_get_data(rows, fields);
    if(rows)
    {
        PlayerInfo[playerid][pPosX] = cache_get_row_int(total, X_COLUMN_NUMBER);
        PlayerInfo[playerid][pPosY] = cache_get_row_int(total, Y_COLUMN_NUMBER);
        PlayerInfo[playerid][pPosZ] = cache_get_row_int(total, Z_COLUMN_NUMBER);
        PlayerInfo[playerid][pPosA] = cache_get_row_int(total, A_COLUMN_NUMBER);
    }
    return 1;
}