Errors on position spawn
#1

My code complies correctly, but when a new player registers their X,Y,Z coords are 0, 0, 0 but they spawn at Unity Station. If they go somewhere else and /q Their coords still remain 0, 0, 0 in stead of updating to their last known position for them to reconnect at those last known coords. And the Skins Wont save either now. Not sure what im doing wrong.

OnPlayerDisconnect & OnPlayerSpawn
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"data");
    INI_WriteInt(File,"Cash",PlayerInfo[playerid][pCash]);
    INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
    INI_WriteInt(File,"Skin",PlayerInfo[playerid][pSkin]);
    INI_WriteInt(File,"Vip",PlayerInfo[playerid][pVip]);
    INI_WriteFloat(File,"X",PlayerInfo[playerid][pLastX]);
    INI_WriteFloat(File,"Y",PlayerInfo[playerid][pLastY]);
    INI_WriteFloat(File,"Z",PlayerInfo[playerid][pLastZ]);
    INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
    INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
    INI_Close(File);
    return 1;
}
public OnPlayerSpawn(playerid)
{
    if(PlayerInfo[playerid][pLastX] == 0.0 && PlayerInfo[playerid][pLastY] == 0.0 && PlayerInfo[playerid][pLastZ] == 0.0)
    {
        SetPlayerPos(playerid, 1723.2061,-1907.0430,13.5646);
    }
    else SetPlayerPos(playerid, PlayerInfo[playerid][pLastX], PlayerInfo[playerid][pLastY], PlayerInfo[playerid][pLastZ]);
    return 1;
}
OnDialogRegister
pawn Код:
INI_WriteFloat(File,"X", 1481.3613);
INI_WriteFloat(File,"Y", -1758.5322);
INI_WriteFloat(File,"Z", 17.5313);
Reply
#2

Did you try checking your OnPlayerUpdate ?
Reply
#3

Have nothing under OnPlayerUpdate, can you explain to me how it should look?
Reply
#4

You get player position ondisconnect but don't use it as I can see.
Don't know how your system works but probably the problem is this. So change your code as follow:
Код:
GetPlayerPos(playerid, PlayerInfo[playerid][pLastX], PlayerInfo[playerid][pLastY], PlayerInfo[playerid][pLastZ],);
If it is correct, delete the 3 float variables you defined.
Remember, you need also player interior and virtualworld if players can move through them to respawn correctly.
Reply
#5

Are you loading it correctly too?
Reply
#6

Quote:
Originally Posted by Phanto90
Посмотреть сообщение
You get player position ondisconnect but don't use it as I can see.
Don't know how your system works but probably the problem is this. So change your code as follow:
Код:
GetPlayerPos(playerid, PlayerInfo[playerid][pLastX], PlayerInfo[playerid][pLastY], PlayerInfo[playerid][pLastZ],);
If it is correct, delete the 3 float variables you defined.
Remember, you need also player interior and virtualworld if players can move through them to respawn correctly.
That worked , cant believe it was that simple to fix Thanks.
Reply
#7

Remember also to save player's interior and virtualworld, or may occur other problems :P
If a player disconnect while in a interior, after riconnecting would be falling in air and inevitably die (maybe if he's lucky would land on water xD)


Quote:

If I help you please +1 Reputation me Would appreciate.

:P
Reply
#8

Quote:
Originally Posted by Phanto90
Посмотреть сообщение
Remember also to save player's interior and virtualworld, or may occur other problems :P
If a player disconnect while in a interior, after riconnecting would be falling in air and inevitably die (maybe if he's lucky would land on water xD)



:P
+1 lol @ if hes luck he wouls land in water, but thanks, and to save their Interior, and Virtual world i would have to add it in my Enum as well correct? same way how the position is saved except using the VW/Int Functions?
Reply
#9

Exactly. Just getplayerinterior and virtualworld ondisconnecting as you did for the position and adding also them to playerinfo to use that onspawn.
Reply
#10

Quote:
Originally Posted by Phanto90
Посмотреть сообщение
Exactly. Just getplayerinterior and virtualworld ondisconnecting as you did for the position and adding also them to playerinfo to use that onspawn.
Cool Thanks, if i need anymore help is it fine if i pm you?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)