Save coordinates when player disconnects
#1

Hey, I tried to make this simple save/load position system, so that when a player disconnects, his pos is saved to his file and when he connects back to the server, he is teleported to those coords. They coords are saved properly but they won't load, instead it'll teleport the player back to his faction's HQ (if he died or got respawned).

Here's the code:
pawn Код:
if(JustConnected[playerid] == 1 && pInfo[playerid][Jailed] != 1) // If the player just connected and he's not jailed
    {
        SetPlayerPos(playerid,pInfo[playerid][posX],pInfo[playerid][posY],pInfo[playerid][posZ]);
        SetPlayerInterior(playerid,pInfo[playerid][Interior]);
        SetPlayerVirtualWorld(playerid,pInfo[playerid][VirtualWorld]);
        JustConnected[playerid]=0;
        if(pInfo[playerid][Faction] == 1)
        {
            GivePlayerWeapon(playerid,3,1);
            switch(pInfo[playerid][Clothes])
            {
                case 1: SetPlayerSkin(playerid,280);
                case 2: SetPlayerSkin(playerid,281);
                case 3: SetPlayerSkin(playerid,284);
                case 4: SetPlayerSkin(playerid,285);
                case 5: SetPlayerSkin(playerid,282);
                case 6: SetPlayerSkin(playerid,265);
            }
            SetPlayerColor(playerid,COLOR_BLUE);
        }
        else if(pInfo[playerid][Faction] == 3)
        {
            SetPlayerColor(playerid,COLOR_ORANGE);
            switch(pInfo[playerid][Clothes])
            {
                case 1: SetPlayerSkin(playerid,197);
                case 2: SetPlayerSkin(playerid,188);
                case 3: SetPlayerSkin(playerid,187);
                case 4: SetPlayerSkin(playerid,228);
                case 5: SetPlayerSkin(playerid,240);
                case 6: SetPlayerSkin(playerid,227);
            }
        }
    }
    else if(pInfo[playerid][Faction] == 1) // ... if he died/respawned he'll teleport to his faction's HQ
Also JustConnected is set to 1 when a player connects if he's registered.
Reply
#2

Can you post the loading and saving system codes for positions?
Reply
#3

Quote:
Originally Posted by MattTucker
Посмотреть сообщение
Can you post the loading and saving system codes for positions?
Well, it's quite simple.

Loading:
pawn Код:
//Under the login dialog
pInfo[playerid][posX] = dini_Float(path,"posX");
pInfo[playerid][posY] = dini_Float(path,"posY");
pInfo[playerid][posZ] = dini_Float(path,"posZ");
pInfo[playerid][Interior] = dini_Int(path,"Interior");
pInfo[playerid][VirtualWorld] = dini_Int(path,"VirtualWorld");
Saving:
pawn Код:
//Under OnPlayerDisconnect
new Float:ppX,Float:ppY,Float:ppZ;
GetPlayerPos(playerid,ppX,ppY,ppZ);
dini_FloatSet(path, "posX", ppX);
dini_FloatSet(path, "posY", ppY);
dini_FloatSet(path, "posZ", ppZ);
dini_IntSet(path, "Interior", GetPlayerInterior(playerid));
dini_IntSet(path, "VirtualWorld", GetPlayerVirtualWorld(playerid));
Reply
#4

Код:
New Float: X, Float: Y, Float: Z;
GetPlayerPos(playerid, X, Y, Z);
pInfo[playerid][posX] = X;
pInfo[playerid][posY] = Y;
pInfo[playerid][posZ] = Z;
pInfo[playerid][Interior] = GetPlayerInterior(playerid);
pInfo[playerid][VirtualWorld] = GetPlayerVirtualWorld(playerid);
Reply
#5

This might sound a bit dumb but, where is that part of code placed under? Not saving/loading the other one.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)