Saving Player Pos with Y_INI and using it with SetSpawnInfo
#1

Firstly, sorry to be heckling you all the past few days.

I got the position to save and load correctly, however the playerskin (while it saves) loads as either ID 5 or ID 0 everytime.

I can go into my .ini file and change the skin to 299 or any number and it always loads as 0 or 5, then saves 0 or 5 upon disconnect...

edit: A few things I've noticed, if I take SpawnPlayer out of the Login dialog response, even though it's already set in onplayerrequestclass, it won't load my position or skin. I spawn as CJ falling out of the sky.

pawn Код:
enum pInfo
{
    pPass,
    pCash,
    pAdmin,
    pKills,
    pDeaths,
    pSkin
}
new PlayerInfo[MAX_PLAYERS][pInfo];

forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_Int("Password",PlayerInfo[playerid][pPass]);
    INI_Int("Cash",PlayerInfo[playerid][pCash]);
    INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
    INI_Int("Kills",PlayerInfo[playerid][pKills]);
    INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
    INI_Int("Skin",PlayerInfo[playerid][pSkin]);
    INI_Float( "PositionX", PosX[ playerid ] );
    INI_Float( "PositionY", PosY[ playerid ] );
    INI_Float( "PositionZ", PosZ[ playerid ] );
    INI_Float( "Angle", Angle[ playerid ] );
    INI_Int( "Interior", Interior[ playerid ] );
    INI_Int( "VirtualWorld", VirtualWorld[ playerid ] );
    return 1;
}

stock UserPath(playerid)
{
    new string[128],playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    format(string,sizeof(string),PATH,playername);
    return string;
}

stock udb_hash(buf[]) {
    new length=strlen(buf);
    new s1 = 1;
    new s2 = 0;
    new n;
    for (n=0; n<length; n++)
    {
       s1 = (s1 + buf[n]) % 65521;
       s2 = (s2 + s1)     % 65521;
    }
    return (s2 << 16) + s1;
}

public OnPlayerRequestClass(playerid, classid)
{
    SpawnPlayer(playerid);
    return 1;
}

public OnPlayerConnect(playerid)
{
    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
    if(fexist(UserPath(playerid)))
        {
            INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
            ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,""COL_WHITE"Login",""COL_WHITE"Type your password below to login.","Login","Quit");
        }
    else
        {
            ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD,""COL_WHITE"Registering...",""COL_WHITE"Type your password below to register a new account.","Register","Quit");
        }
    SetSpawnInfo(playerid, 0, pSkin, PosX[playerid], PosY[playerid], PosZ[playerid], Angle[playerid], Interior[playerid], VirtualWorld[playerid], 0, 0, 0, 0);
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    GetPlayerPos( playerid, PosX[ playerid ], PosY[ playerid ], PosZ[ playerid ] );
    GetPlayerFacingAngle( playerid, Angle[ playerid ] );
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"data");
    INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
    INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
    INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
    INI_WriteInt(File,"Skin",GetPlayerSkin(playerid));
    INI_SetTag( File, "position" );
    INI_WriteFloat( File, "PositionX", PosX[ playerid ] );
    INI_WriteFloat( File, "PositionY", PosY[ playerid ] );
    INI_WriteFloat( File, "PositionZ", PosZ[ playerid ] );
    INI_WriteFloat( File, "Angle", Angle[ playerid ] );
    INI_WriteInt( File, "Interior", GetPlayerInterior( playerid ) );
    INI_WriteInt( File, "VirtualWorld", GetPlayerVirtualWorld( playerid ) );
    INI_Close( File );
    return 1;
}

public OnPlayerSpawn(playerid)
{
    if (newplayer[playerid] == 1)
    {
    SetPlayerSkin(playerid, random(299));
    newplayer[playerid] = 0;
    switch(random(4))
    {
      case 0:
      {
       SetPlayerPos(playerid,1694.7915,-1861.8884,13.5459);
       SetPlayerFacingAngle(playerid,269.4764);
       SetCameraBehindPlayer(playerid);
      }
      case 1:
      {
       SetPlayerPos(playerid, 1694.3257,-1865.3435,13.5447);
       SetPlayerFacingAngle(playerid,299.5566);
       SetCameraBehindPlayer(playerid);
      }
      case 2:
      {
       SetPlayerPos(playerid,1697.5978,-1867.1487,13.5567);
       SetPlayerFacingAngle(playerid,287.9631);
       SetCameraBehindPlayer(playerid);
      }
      case 3:
      {
       SetPlayerPos(playerid,1697.3198,-1859.8524,13.5572);
       SetPlayerFacingAngle(playerid,258.8228);
       SetCameraBehindPlayer(playerid);
      }
    }
    }

    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    PlayerInfo[killerid][pKills]++;
    PlayerInfo[playerid][pDeaths]++;
    return 1;
}


public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch( dialogid )
    {
        case DIALOG_REGISTER:
        {
            if (!response) return Kick(playerid);
            if(response)
            {
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_WHITE"Registering...",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"data");
                INI_WriteInt(File,"Password",udb_hash(inputtext));
                INI_WriteInt(File,"Cash",0);
                INI_WriteInt(File,"Admin",0);
                INI_WriteInt(File,"Kills",0);
                INI_WriteInt(File,"Deaths",0);
                INI_Close(File);
                newplayer[playerid] = 1;
                ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"Thank you for registering. All of your info will now be saved upon disconnecting.","Ok","");
            }
        }

        case DIALOG_LOGIN:
        {
            if ( !response ) return Kick ( playerid );
            if( response )
            {
                if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                    SpawnPlayer(playerid);
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_RED"You have entered an incorrect password.\n"COL_WHITE"Type your password below to login.","Login","Quit");
                }
                return 1;
            }
        }
    }
    return 1;
}
Reply
#2

Same here with Dini too
Reply
#3

Hmm...
Surely it's worked for other people using Dini or Y_ini?
Reply
#4

EDIT: NVM
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)