Position saver [MySQL]
#1

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

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;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)