Save pos problem.
#1

If i spawn in game for first time then i will fall to the 0 cordinade but save pos are working fine. I just need to know how can i make that if player spawns first time then he spawn pos will be something els (example "2087.1606,1683.9849,10.8203") and after playing and disconnecting he will be able to spawn place where he left before.

I tryed to make new enum that after player disconnects it will set pFirstTime = 1; and saves it, after player reconnects and spawns it will check if pFirstTime == 1; to set saved pos but that didnt work :S it gave error...

EDIT:
Nvm got it work, i made this:
pawn Код:
if(gPlayerLogged[playerid] == 1)
    {
        if(file, "FirstTime", PlayerInfo[playerid][pFirstTime] == 1)
        {
            x = dini_Float(file, "posX");
            y = dini_Float(file, "posY");
            z = dini_Float(file, "posZ");
            SetPlayerPos(playerid, x, y, z);
        }
    }
But now when i reconnect it continues with CJ skin :S
Reply
#2

You have to save player data on files, use dini, SII or y_ini.

example with SII:
Writing:
pawn Код:
public OnPlayerDisconnect(playerid, reason);
{
  new Float:X,Float:Y,Float:Z;
  GetPlayerPos(playerid,X,Y,Z);
  INI_Open("Positions.txt");
  new string[256];
  new name[MAX_PLAYER_NAME];
  GetPlayerName(playerid,name,sizeof(name));
  format(string,sizeof(string),"%sX",name);
  INI_WriteFloat(string,X);
  format(string,sizeof(string),"%sY",name);
  INI_WriteFloat(string,Y);
  format(string,sizeof(string),"%sZ",name);
  INI_WriteFloat(string,Z);
  INI_Save();
  INI_Close();
  return 1;
}
To load it:
pawn Код:
OnPlayerConnect(playerid)
{
  SetPVarInt(playerid,"Spawned",0);
  return 1;
}

public OnPlayerSpawn(playerid)
{
  //First the other thing because theres a return 1 below.
  if(GetPVarInt(playerid, "Spawned") == 0)
  {
    SetPVarInt(playerid, "Spawned", 1);
    new name[20];
    new Float:X,Float:Y,Float:Z;
    GetPlayerName(playerid,name,sizeof(name));
    new string[256];
    INI_Open("Positions.txt");
    format(string,sizeof(string),"%sX",name);
    X = INI_ReadFloat(string);
    format(string,sizeof(string),"%sY",name);
    Y = INI_ReadFloat(string);
    format(string,sizeof(string),"%sZ",name);
    Z = INI_ReadFloat(string);
    SetPlayerPos(playerid,X,Y,Z);
    return 1;
  }
  return 1;
}
Reply
#3

what?? Like you see im using dini and saving data just skin saving is bugged and im trying to figure out how to make that if you login then it will automaticaly spawn with your late choosed skin.
Reply
#4

I saw the edit after I posted it xD.
Reply
#5

Quote:
Originally Posted by tuuker
Посмотреть сообщение
If i spawn in game for first time then i will fall to the 0 cordinade but save pos are working fine. I just need to know how can i make that if player spawns first time then he spawn pos will be something els (example "2087.1606,1683.9849,10.8203") and after playing and disconnecting he will be able to spawn place where he left before.

I tryed to make new enum that after player disconnects it will set pFirstTime = 1; and saves it, after player reconnects and spawns it will check if pFirstTime == 1; to set saved pos but that didnt work :S it gave error...

EDIT:
Nvm got it work, i made this:
pawn Код:
if(gPlayerLogged[playerid] == 1)
    {
        if(file, "FirstTime", PlayerInfo[playerid][pFirstTime] == 1)
        {
            x = dini_Float(file, "posX");
            y = dini_Float(file, "posY");
            z = dini_Float(file, "posZ");
            SetPlayerPos(playerid, x, y, z);
        }
    }
But now when i reconnect it continues with CJ skin :S
Then just do the same thing for the skin? Save it in OnPlayerDisconnect using GetPlayerSkin and dini_IntSet, then when the player spawns set his skin using SetPlayerSkin and dini_Int to get the ID of the skin you stored.

Also I'm not sure what you're trying to achieve with that if statement. It doesn't make sense.
Reply
#6

with that if statement im asking that is player new or have he been here before, so if FirstTime == 1 that means that player has been here before(if player disconnects it will save FirstTime as 1 first it is 0) and that means it can use now set saved pos. If i don't use it then player will spawn at 0 cordinade, i have 2 teams cops and robbers thats why i want that new player as cop will spawn near police station and new civilian player will spawn somewere els.
Reply
#7

Yes, but what is the "if(file, "FirstTime"," part about?
Reply
#8

It checks if player is reconnected, if new player has disconnected it sets it to 1 and now im looking that if its 1 it will set player pos else it will spawn in some other location as new player.
Reply
#9

That part doesn't make sense though, it should just be:

pawn Код:
if(PlayerInfo[playerid][pFirstTime] == 1)
I don't see what the file and "string" part are for....are you trying to compare them or something?
Reply
#10

I made that stuff here so i tought if player now logs in then all hes stats,pos,skins,money etc. will be loaded but it still keeps me stuck at skin choosing menu.
pawn Код:
if (dialogid == 2) // This is player logged in dialog
    {
        new name[MAX_PLAYER_NAME], file[128], Float:x, Float:y, Float:z;
        GetPlayerName(playerid, name, sizeof(name));
        format(file, sizeof(file), SERVER_USER_FILE, name);
        if(!response) return Kick(playerid);
        if (!strlen(inputtext)) return ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Logi sisse:", "See kasutaja nimi on registreerunud, palun sisestage oma parool ning logige sisse.", "Logi sisse", "Lahku");
        new tmp;
        tmp = dini_Int(file, "Password");
        if(udb_hash(inputtext) != tmp) {
            SendClientMessage(playerid, COLOR_RED, "Vale parool!");
            ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Logi sisse:", "See kasutaja nimi on registreerunud, palun sisestage oma parool ning logige sisse.", "Logi sisse", "Lahku");
        }
        else
        {
            gPlayerLogged[playerid] = 1;
            if(file, "FirstTime", PlayerInfo[playerid][pFirstTime] == 1)
            {
                PlayerInfo[playerid][pAdminLevel] = dini_Int(file, "AdminLevel");
                SetPlayerScore(playerid, PlayerInfo[playerid][pScore]);
                GivePlayerMoney(playerid, dini_Int(file, "Money")-GetPlayerMoney(playerid));
                SetPlayerWantedLevel(playerid, dini_Int(file,"WantedLevel")-GetPlayerWantedLevel(playerid));
                SetPlayerSkin(playerid, dini_Int(file, "Skin")-GetPlayerSkin(playerid));
                PlayerInfo[playerid][pCop] = dini_Int(file, "Cop");
                PlayerInfo[playerid][pCivilian] = dini_Int(file, "Civilian");
                PlayerInfo[playerid][pFirstTime] = dini_Int(file, "FirstTime");
                SendClientMessage(playerid,COLOR_RED, "[SЬSTEEM]: Olete edukalt sisse loginud.");
                x = dini_Float(file, "posX");
                y = dini_Float(file, "posY");
                z = dini_Float(file, "posZ");
                SetPlayerPos(playerid, x, y, z);
            }

        }
    }
    return 1;
}
Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
That part doesn't make sense though, it should just be:

pawn Код:
if(PlayerInfo[playerid][pFirstTime] == 1)
I don't see what the file and "string" part are for....are you trying to compare them or something?
Doesn't work like that because if its "if(playerinfo[playerid][pFirstTime] == 1) " then it doesn't load from .ini file where player information is stored.

FirstTime = 1 then if player disconnects and it will be stored so it knows that to load from saved pos not anymore load at New player location.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)