Class selection problem after login/register
#1

I made it so that you cannot spawn if you're still at the register/login screen by adding the following to the OnPlayerSpawn callback:

Код HTML:
	if (IsLoggedIn[playerid] == 0)
	{
	    ForceClassSelection(playerid);
    	    TogglePlayerSpectating(playerid, true);
    	    TogglePlayerSpectating(playerid, false);
        }
If the player succesfully registers or logs in the IsLoggedIn gets set to 1.
This works, however now if you log in or register, and you press spawn it doesn't work, you first need to select a different class before the spawn button works again..

I tried this at OnPlayerRequestSpawn:
Код HTML:
    if (IsLoggedIn[playerid] == 1)
    {
	    SpawnPlayer(playerid)
    }
But that doesn't work either.

Here is my log in/register system:


LOG IN/REGISTER:

Код HTML:
public OnPlayerRequestClass(playerid, classid)
{
/*	if (GodMode[playerid] == 1)
	{
	SpawnPlayer(playerid);
	SetPlayerPos
	}
	
	else
	{*/
		SetPlayerInterior(playerid,11);
		SetPlayerPos(playerid,508.7362,-87.4335,998.9609);
		SetPlayerFacingAngle(playerid,0.0);
	    SetPlayerCameraPos(playerid,508.7362,-83.4335,998.9609);
		SetPlayerCameraLookAt(playerid,508.7362,-87.4335,998.9609);
	   	if (IsLoggedIn[playerid] == 0)
	   	{
			if(fexist(UserPath(playerid)))
	    	{
	        	INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
	        	ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_WHITE"Type your password below to login.","Login","Quit");
	    	}
	    	else
	    	{
	        	ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,""COL_WHITE"Registering...",""COL_WHITE"Type your password below to register a new account.","Register","Quit");
	    	}
    	}
		else
		{
			switch(classid)
			{
				case 105, 106, 107:
		        {
		            GameTextForPlayer(playerid, "~g~Grove", 3000, 3);
		        }
		        case 102, 103, 104:
		        {
		            GameTextForPlayer(playerid, "~g~Ballas", 3000, 3);
		        }
			}
		}
		return 1;
}
DIALOGS:

Код HTML:
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");
				}
				else if(strlen(inputtext) < 4)
				{
					return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_WHITE"Registering...",""COL_RED"Your password needs to have atleast 4 characters.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
				}
				else if(strlen(inputtext) > 16)
				{
					return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_WHITE"Registering...",""COL_RED"Your password can only have a maximum of 16 characters.\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,"PasswordLength",strlen(inputtext));
                INI_WriteString(File,"PasswordDecrypted",inputtext);
            	INI_WriteInt(File,"Admin",0);
     			INI_WriteInt(File,"Kills",0);
            	INI_WriteInt(File,"Deaths",0);
				INI_Close(File);

				IsLoggedIn[playerid] = 1;
				SpawnPlayer(playerid);
				ForceClassSelection(playerid);
    			TogglePlayerSpectating(playerid, true);
		    	TogglePlayerSpectating(playerid, false);
				
				new name[MAX_PLAYER_NAME+1], string[64+MAX_PLAYER_NAME+1];
				GetPlayerName(playerid, name, sizeof(name));
				
				format(string, sizeof(string), "%s has joined the server for the first time, be sure to welcome him/her!", name);
				SendClientMessageToAll(0xC4C4C4FF, string);
            }
        }

        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]);
                    ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"You have successfully logged in!","Ok","");
       				IsLoggedIn[playerid] = 1;
       				SpawnPlayer(playerid);
       				ForceClassSelection(playerid);
			 		TogglePlayerSpectating(playerid, true);
    				TogglePlayerSpectating(playerid, false);
                }
                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

return 0 at OnPlayerRequestSpawn to prevent him from spawning, return 1 to allow him to spawn, you don't need to SpawnPlayer (which will bug if you haven't used SetSpawnInfo).
Reply
#3

Quote:
Originally Posted by CuervO
Посмотреть сообщение
return 0 at OnPlayerRequestSpawn to prevent him from spawning, return 1 to allow him to spawn, you don't need to SpawnPlayer (which will bug if you haven't used SetSpawnInfo).
I did that, however the Spawn button still worked?

Hmm, now it works.

Код HTML:
public OnPlayerRequestSpawn(playerid)
{
	/*if (IsLoggedIn[playerid] == 0)
	{
	    ForceClassSelection(playerid);
    	TogglePlayerSpectating(playerid, true);
    	TogglePlayerSpectating(playerid, false);
    }*/
    if (IsLoggedIn[playerid] == 1)
	{
	    return 1;
    }
	return 0;
}
Before I had it the other way around,

Код HTML:
if (IsLoggedIn[playerid] == 0
{
    return 0;
}
else
{
    return 1;
}
Any idea what I did wrong before?

Also; why does the GameTextForPlayer not work?
Reply
#4

Apart from the missing parenthesis at the end of the statement, there's no need to do the else statement; If the player is not logged in it will return 0, if not, the code will continue anyways.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)