TogglePlayerSpectating Causes server disconnecting the user.
#1

So here's my issue, i have
Код:
TogglePlayerSpectating(playerid, 1);
in the class selection so that it can not do the class selection, here's the full code
Код:
public OnPlayerRequestClass(playerid, classid)
{
    TogglePlayerSpectating(playerid, 1);
    if(fexist(UserPath(playerid)))
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_data", .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");
    }
    return 1;
}
Now that works fine if the user is registering, but if the user is logging, the user will be disconnected after being spawned,

Код:
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_PASSWORD, ""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");
                new HashPass[129];
                WP_Hash(HashPass, sizeof(HashPass), inputtext);
                INI_WriteString(File, "Password", HashPass);
                INI_WriteInt(File,"Cash",1000);
                INI_WriteInt(File,"Skin",1);
                INI_WriteInt(File,"AdminLevel",0);
                INI_WriteInt(File,"Vip",0);
                INI_Close(File);
                TogglePlayerSpectating(playerid, 0);
                SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
                SpawnPlayer(playerid);
            }
        }

        case DIALOG_LOGIN:
        {
            if ( !response ) return Kick ( playerid );
            if( response )
            {
                new HashPass[129];
                WP_Hash(HashPass, sizeof(HashPass), inputtext);
                if(strcmp(HashPass, PlayerInfo[playerid][pPass]) == 0)
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    TogglePlayerSpectating(playerid, 0);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                    SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
                    ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"You have successfully logged in!","Ok","");
                    SetPlayerPos( playerid, PosX[ playerid ], PosY[ playerid ], PosZ[ playerid ] );
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,""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;
}
Now i am trying to figure out why it's doing this.
Reply
#2

Quote:
Originally Posted by Cole_William
Посмотреть сообщение
So here's my issue, i have
Код:
        case DIALOG_LOGIN:
        {
            if ( !response ) return Kick ( playerid );
            if( response )
            {
                new HashPass[129];
                WP_Hash(HashPass, sizeof(HashPass), inputtext);
                if(strcmp(HashPass, PlayerInfo[playerid][pPass], true) == 0)
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    TogglePlayerSpectating(playerid, 0);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                    SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
                    ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"You have successfully logged in!","Ok","");
                    SetPlayerPos( playerid, PosX[ playerid ], PosY[ playerid ], PosZ[ playerid ] );
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,""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;
}
Try adding what's in green. Also, your login dialog doesn't actually spawn the player.
Reply
#3

Quote:
Originally Posted by austin070
Посмотреть сообщение
Try adding what's in green. Also, your login dialog doesn't spawn the player.
Cause after
Код:
TogglePlayerSpectating(playerid, 0);
The wiki said,

Quote:

When spectator mode is disabled, OnPlayerSpawn will automatically be called.

The code for OnPlayerSpawn is
Код:
public OnPlayerSpawn(playerid)
{
    if ( PosX[ playerid ] != 0 && PosY[ playerid ] != 0 && PosZ[ playerid ] != 0 && Angle[ playerid ] != 0 )
    {
        SetPlayerPos( playerid, PosX[ playerid ], PosY[ playerid ], PosZ[ playerid ] );
        SetPlayerFacingAngle( playerid, Angle[ playerid ] );
        SetPlayerInterior( playerid, Interior[ playerid ] );
        SetPlayerVirtualWorld( playerid, VirtualWorld[ playerid ] );
    }
	return 1;
}
and when i try to SpawnPlayer(playerid); it just spawns them in blueberry that's why im going the spectating mode route.
Reply
#4

I beleive this is the Dialog which spawns the player
pawn Код:
ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"You have successfully logged in!","Ok","");
Reply
#5

Quote:
Originally Posted by Clad
Посмотреть сообщение
I beleive this is the Dialog which spawns the player
pawn Код:
ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"You have successfully logged in!","Ok","");
Yes so it's
Код:
        case DIALOG_LOGIN:
        {
            if ( !response ) return Kick ( playerid );
            if( response )
            {
                new HashPass[129];
                WP_Hash(HashPass, sizeof(HashPass), inputtext);
                if(strcmp(HashPass, PlayerInfo[playerid][pPass]) == 0)
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    TogglePlayerSpectating(playerid, 0);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                    SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
                    ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"You have successfully logged in!","Ok","");
                    SetPlayerPos( playerid, PosX[ playerid ], PosY[ playerid ], PosZ[ playerid ] );
But as you can see, i highlighted the "TogglePlayerSpectating" code which should do it.

I tried
Quote:

Try adding what's in green.

but it still does the same thing.
Reply
#6

Quote:
Originally Posted by Cole_William
Посмотреть сообщение
But as you can see, i highlighted the "TogglePlayerSpectating" code which should do it.
I'm not sure it works that way when being used in OnPlayerRequestClass(). Create a variable that indicates that it's the players first spawn since joining the server. Spawn them with the login dialog and set the location in OnPlayerSpawn using the variable to determine if it is their first spawn.
Reply
#7

pawn Код:
case DIALOG_LOGIN:
        {
            if ( !response ) return Kick ( playerid );
            if( response )
            {
                new HashPass[129];
                WP_Hash(HashPass, sizeof(HashPass), inputtext);
                if(strcmp(HashPass, PlayerInfo[playerid][pPass]) == 0)
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    TogglePlayerSpectating(playerid, 0);
                    SpawnPlayer(playerid);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                    SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
                    ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"You have successfully logged in!","Ok","");
                    SetPlayerPos( playerid, PosX[ playerid ], PosY[ playerid ], PosZ[ playerid ] );
Reply
#8

Quote:
Originally Posted by Clad
Посмотреть сообщение
pawn Код:
case DIALOG_LOGIN:
        {
            if ( !response ) return Kick ( playerid );
            if( response )
            {
                new HashPass[129];
                WP_Hash(HashPass, sizeof(HashPass), inputtext);
                if(strcmp(HashPass, PlayerInfo[playerid][pPass]) == 0)
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    TogglePlayerSpectating(playerid, 0);
                    SpawnPlayer(playerid);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                    SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
                    ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"You have successfully logged in!","Ok","");
                    SetPlayerPos( playerid, PosX[ playerid ], PosY[ playerid ], PosZ[ playerid ] );
I'll give it a try.

EDIT: Thanks! It worked.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)