Saving and Loading Positions
#1

Alright,
I am trying to save X Y and Z Positions of a Player when they logout, and that is sorta good.

The bug is when It saves it does something like this
This is in the user file!
Posx=1151790684
Posy=-998878702
Posz=1107785917

When the server goes to load the position it fails and brings up bright colors like when you set the gravity to like 9999 until I try to GMX.
Any way I can add the . in the position?

Here is what I have for the whole Pos system

pawn Code:
enum pInfo

Float:Posx,
Float:Posy,
Float:Posz,

OnPlayerDisconnect

new Float: X, Float: Y, Float:Z;
GetPlayerPos(playerid, X, Y, Z);
PlayerInfo[playerid][Posx] = X;
PlayerInfo[playerid][Posy] = Y;
PlayerInfo[playerid][Posz] = Z;

OnPlayerRegister

format(var, 32, "Posx=%d\n",PlayerInfo[playerid][Posx]);fwrite(hFile, var);
format(var, 32, "Posy=%d\n",PlayerInfo[playerid][Posy]);fwrite(hFile, var);
format(var, 32, "Posz=%d\n",PlayerInfo[playerid][Posz]);fwrite(hFile, var);

OnPlayerLogin

if( strcmp( key , "Posx" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][Posx] = strval( val ); }
if( strcmp( key , "Posy" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][Posy] = strval( val ); }
if( strcmp( key , "Posz" , true ) == 0 ) { val = ini_GetValue( Data ); PlayerInfo[playerid][Posz] = strval( val ); }
I Created a command to get to the positions instead of it failing everytime I connect.

Command here

pawn Code:
if(strcmp(cmd, "/gotolastpos", true) == 0)
    {
      if(PlayerInfo[playerid][pAdmin] >= 1)
        {
    SetPlayerPos(playerid, PlayerInfo[playerid][Posx], PlayerInfo[playerid][Posy], PlayerInfo[playerid][Posz]);
    SetPlayerInterior(playerid, PlayerInfo[playerid][pInterior]);
    SendClientMessage(playerid, COLOR_YELLOW, "Teleported!");
        return 1;
        }
    }
Can someone please help!
Reply
#2

you need to save it as a float (%f), not decimal (%d):
Code:
format(var, 32, "Posx=%f\n",PlayerInfo[playerid][Posx]);fwrite(hFile, var);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)