Strange issue.
#1

Hello!

I have a weird problem in OnPlayerRequestClass callback.

Whenever player fails to login at first attempt and if they enter the password at second attempt and he/she is successfully logged in, the OnPlayerRequestClass screen isn't showing up, it shows some random blank screen without classes. it only shows up correctly if they are successfully logged in at first attempt.

Everything was fine before, i made the login attempts script and the bug showed up.

Login dialog:
pawn Код:
Dialog_Login(playerid, response, inputtext[])
{
    new msg[128], Name[24];
    GetPlayerName(playerid, Name, sizeof(Name));
    if(!response)
    {
        format(msg, 128, "%s has been kicked from the server! [Quitting the Login Dialog]", Name);
        SendClientMessageToAll(RED, msg);
        SendClientMessage(playerid, DARK_RED, "You must Login to your Account before entering the server!");
        Timer_Disconnect[playerid] = SetTimerEx("DisconnectPlayer", 100, false, "d", playerid);
    }
    if(response)
    {
        if(udb_hash(inputtext) == pInfo[playerid][PlayerPassword])
        {
            pInfo[playerid][LoggedIn] = true;
            SendClientMessage(playerid, LIGHT_GREEN, "[ACCOUNT] You are successfully Logged in. Welcome back!");
            BankFile_Load(playerid);
            DeleteTextDraws(playerid);
            INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
            INI_ParseFile(InventoryPath(playerid), "LoadInventory_%s", .bExtra = true, .extra = playerid);
        }
        else
        {
            if(LoginAttempts[playerid] < MAX_FAIL_LOGINS)
            {
                LoginAttempts[playerid]++;
                ShowPlayerDialog(playerid, DialogLogin, DIALOG_STYLE_PASSWORD, "{FFFFFF}LOGIN", "{00FF00}Welcome back!\n\n{FFFFFF}Please enter your Password bellow to login:", "Login", "");
                format(msg, 128, "Wrong password! Attempts: %i/%i", LoginAttempts[playerid], MAX_FAIL_LOGINS);
                SendClientMessage(playerid, DARK_RED, msg);
            }
            else if(LoginAttempts[playerid] == MAX_FAIL_LOGINS)
            {
                format(msg, 128, "%s has been kicked from the server! [Too many login attempts]", Name);
                SendClientMessageToAll(RED, msg);
                SendClientMessage(playerid, DARK_RED, "You failed to login, you have been kicked!");
                Timer_Disconnect[playerid] = SetTimerEx("DisconnectPlayer", 100, false, "d", playerid);
            }
        }
    }
    return 1;
}
OnPlayerRequestClass:
pawn Код:
public OnPlayerRequestClass(playerid, classid)
{
    if(pInfo[playerid][LoggedIn] == true)
    {
        SetPlayerPos(playerid,-2378.0867, -579.2721, 132.1665);
        SetPlayerVirtualWorld(playerid, 1);
        SetPlayerFacingAngle(playerid, 132.1665);
        SetPlayerCameraPos(playerid, -2383.2615, -577.4695, 132.0175);
        SetPlayerCameraLookAt(playerid, -2382.3948, -577.9800, 132.1530);
        switch (classid)
        {
            case 0, 1, 2, 3, 4, 5, 6, 7:
            {
                GameTextForPlayer(playerid, "~g~Trucker", 3000, 6);
                pInfo[playerid][PlayerClass] = TRUCKER;
            }
            case 8:
            {
                GameTextForPlayer(playerid, "~y~Pilot", 3000, 6);
                pInfo[playerid][PlayerClass] = PILOT;
            }
            case 9, 10, 11:
            {
                GameTextForPlayer(playerid, "~b~Police", 3000, 6);
                pInfo[playerid][PlayerClass] = POLICE;
            }
            case 12:
            {
                GameTextForPlayer(playerid, "~p~Mechanic", 3000, 6);
                pInfo[playerid][PlayerClass] = MECHANIC;
            }
        }
    }
    return 1;
}
I have been working to fix this issue since 2 hours and couldn't figure out what is wrong, so i came here for help.
Reply
#2

https://sampwiki.blast.hk/wiki/ForceClassSelection

pawn Код:
Dialog_Login(playerid, response, inputtext[])
{
    new msg[128], Name[24];
    GetPlayerName(playerid, Name, sizeof(Name));
    if(!response)
    {
        format(msg, 128, "%s has been kicked from the server! [Quitting the Login Dialog]", Name);
        SendClientMessageToAll(RED, msg);
        SendClientMessage(playerid, DARK_RED, "You must Login to your Account before entering the server!");
        Timer_Disconnect[playerid] = SetTimerEx("DisconnectPlayer", 100, false, "d", playerid);
    }
    if(response)
    {
        if(udb_hash(inputtext) == pInfo[playerid][PlayerPassword])
        {
            pInfo[playerid][LoggedIn] = true;
            SendClientMessage(playerid, LIGHT_GREEN, "[ACCOUNT] You are successfully Logged in. Welcome back!");
            BankFile_Load(playerid);
            DeleteTextDraws(playerid);
            INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
            INI_ParseFile(InventoryPath(playerid), "LoadInventory_%s", .bExtra = true, .extra = playerid);
            if(LoginAttempts[playerid] > 0)
            {
                ForceClassSelection(playerid);
                TogglePlayerSpectating(playerid, true);
                TogglePlayerSpectating(playerid, false);
            }
        }
        else
        {
            if(LoginAttempts[playerid] < MAX_FAIL_LOGINS)
            {
                LoginAttempts[playerid]++;
                ShowPlayerDialog(playerid, DialogLogin, DIALOG_STYLE_PASSWORD, "{FFFFFF}LOGIN", "{00FF00}Welcome back!\n\n{FFFFFF}Please enter your Password bellow to login:", "Login", "");
                format(msg, 128, "Wrong password! Attempts: %i/%i", LoginAttempts[playerid], MAX_FAIL_LOGINS);
                SendClientMessage(playerid, DARK_RED, msg);
            }
            else if(LoginAttempts[playerid] == MAX_FAIL_LOGINS)
            {
                format(msg, 128, "%s has been kicked from the server! [Too many login attempts]", Name);
                SendClientMessageToAll(RED, msg);
                SendClientMessage(playerid, DARK_RED, "You failed to login, you have been kicked!");
                Timer_Disconnect[playerid] = SetTimerEx("DisconnectPlayer", 100, false, "d", playerid);
            }
        }
    }
    return 1;
}
Reply
#3

Nope, that didn't work. Its still the same.
Reply
#4

PHP код:
Dialog_Login(playeridresponseinputtext[])
{
    new 
msg[128], Name[24];
    
GetPlayerName(playeridNamesizeof(Name));
    if(!
response)
    {
        
format(msg128"%s has been kicked from the server! [Quitting the Login Dialog]"Name);
        
SendClientMessageToAll(REDmsg);
        
SendClientMessage(playeridDARK_RED"You must Login to your Account before entering the server!");
        
Timer_Disconnect[playerid] = SetTimerEx("DisconnectPlayer"100false"d"playerid);
    }
    if(
response)
    {
        if(
udb_hash(inputtext) == pInfo[playerid][PlayerPassword])
        {
            
pInfo[playerid][LoggedIn] = true;
            
SendClientMessage(playeridLIGHT_GREEN"[ACCOUNT] You are successfully Logged in. Welcome back!");
            
BankFile_Load(playerid);
            
DeleteTextDraws(playerid);
            
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra true, .extra playerid);
            
INI_ParseFile(InventoryPath(playerid), "LoadInventory_%s", .bExtra true, .extra playerid);
        }
        else
        {
            if(
LoginAttempts[playerid] < MAX_FAIL_LOGINS)
            {
                
LoginAttempts[playerid]++;
                
pInfo[playerid][LoggedIn] = true//// this 
                
ShowPlayerDialog(playeridDialogLoginDIALOG_STYLE_PASSWORD"{FFFFFF}LOGIN""{00FF00}Welcome back!\n\n{FFFFFF}Please enter your Password bellow to login:""Login""");
                
format(msg128"Wrong password! Attempts: %i/%i"LoginAttempts[playerid], MAX_FAIL_LOGINS);
                
SendClientMessage(playeridDARK_REDmsg);
            }
            else if(
LoginAttempts[playerid] == MAX_FAIL_LOGINS)
            {
                
format(msg128"%s has been kicked from the server! [Too many login attempts]"Name);
                
SendClientMessageToAll(REDmsg);
                
SendClientMessage(playeridDARK_RED"You failed to login, you have been kicked!");
                
Timer_Disconnect[playerid] = SetTimerEx("DisconnectPlayer"100false"d"playerid);
            }
        }
    }
    return 
1;

Reply
#5

None of them worked as i wanted. The screen is still set to somewhere else blank, and these stuffs
pawn Код:
SetPlayerPos(playerid,-2378.0867, -579.2721, 132.1665);
SetPlayerVirtualWorld(playerid, 1);
SetPlayerFacingAngle(playerid, 132.1665);
SetPlayerCameraPos(playerid, -2383.2615, -577.4695, 132.0175);
SetPlayerCameraLookAt(playerid, -2382.3948, -577.9800, 132.1530);
aren't setting after player has successfully logged in. I don't know whats wrong this is very strange. Someone please help me to fix this issue. Its urgent.
Reply
#6

If the player entered the password once false do the arrows from the selection appear ?
If yes OnPlayerRequestClass has been called between the dialogs and you need to recall it after the player entered the password correctly
Reply
#7

Yes, if the player has entered the wrong password there are arrows showing. And how do i recall it when they enter the correct password?
Reply
#8

You wont. You will only recall the dialog when the player enter wrong password.
Reply
#9

use this
pawn Код:
public OnPlayerRequestClass(playerid, classid)
{
    if(pInfo[playerid][LoggedIn] != true)return 0;
   
        SetPlayerPos(playerid,-2378.0867, -579.2721, 132.1665);
        SetPlayerVirtualWorld(playerid, 1);
        SetPlayerFacingAngle(playerid, 132.1665);
        SetPlayerCameraPos(playerid, -2383.2615, -577.4695, 132.0175);
        SetPlayerCameraLookAt(playerid, -2382.3948, -577.9800, 132.1530);
        switch (classid)
        {
            case 0, 1, 2, 3, 4, 5, 6, 7:
            {
                GameTextForPlayer(playerid, "~g~Trucker", 3000, 6);
                pInfo[playerid][PlayerClass] = TRUCKER;
            }
            case 8:
            {
                GameTextForPlayer(playerid, "~y~Pilot", 3000, 6);
                pInfo[playerid][PlayerClass] = PILOT;
            }
            case 9, 10, 11:
            {
                GameTextForPlayer(playerid, "~b~Police", 3000, 6);
                pInfo[playerid][PlayerClass] = POLICE;
            }
            case 12:
            {
                GameTextForPlayer(playerid, "~p~Mechanic", 3000, 6);
                pInfo[playerid][PlayerClass] = MECHANIC;
            }
        }
   
    return 1;
}
Reply
#10

I would alter your code a little so the arrows are always showing
To prevent these arrows completely you would need to toggle the player spectating in OnPlayerConnect and than toggle it of if he logged in but I think with that you can't choose the backgroud of the log in

pawn Код:
Dialog_Login(playerid, response, inputtext[])
{
    new msg[128], Name[24];
    GetPlayerName(playerid, Name, sizeof(Name));
    if(!response)
    {
        format(msg, 128, "%s has been kicked from the server! [Quitting the Login Dialog]", Name);
        SendClientMessageToAll(RED, msg);
        SendClientMessage(playerid, DARK_RED, "You must Login to your Account before entering the server!");
        Timer_Disconnect[playerid] = SetTimerEx("DisconnectPlayer", 100, false, "d", playerid);
    }
    if(response)
    {
        if(udb_hash(inputtext) == pInfo[playerid][PlayerPassword])
        {
            pInfo[playerid][LoggedIn] = true;
            SendClientMessage(playerid, LIGHT_GREEN, "[ACCOUNT] You are successfully Logged in. Welcome back!");
            BankFile_Load(playerid);
            DeleteTextDraws(playerid);
            INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
            INI_ParseFile(InventoryPath(playerid), "LoadInventory_%s", .bExtra = true, .extra = playerid);
            // moved this part form OnPlayerRequestClass to here
            SetPlayerPos(playerid,-2378.0867, -579.2721, 132.1665);
            SetPlayerVirtualWorld(playerid, 1);
            SetPlayerFacingAngle(playerid, 132.1665);
            SetPlayerCameraPos(playerid, -2383.2615, -577.4695, 132.0175);
            SetPlayerCameraLookAt(playerid, -2382.3948, -577.9800, 132.1530);
        }
        else
        {
            if(LoginAttempts[playerid] < MAX_FAIL_LOGINS)
            {
                LoginAttempts[playerid]++;
                ShowPlayerDialog(playerid, DialogLogin, DIALOG_STYLE_PASSWORD, "{FFFFFF}LOGIN", "{00FF00}Welcome back!\n\n{FFFFFF}Please enter your Password bellow to login:", "Login", "");
                format(msg, 128, "Wrong password! Attempts: %i/%i", LoginAttempts[playerid], MAX_FAIL_LOGINS);
                SendClientMessage(playerid, DARK_RED, msg);
            }
            else if(LoginAttempts[playerid] == MAX_FAIL_LOGINS)
            {
                format(msg, 128, "%s has been kicked from the server! [Too many login attempts]", Name);
                SendClientMessageToAll(RED, msg);
                SendClientMessage(playerid, DARK_RED, "You failed to login, you have been kicked!");
                Timer_Disconnect[playerid] = SetTimerEx("DisconnectPlayer", 100, false, "d", playerid);
            }
        }
    }
    return 1;
}
pawn Код:
public OnPlayerRequestClass(playerid, classid)
{
    if(pInfo[playerid][LoggedIn] != true)
    {
        // Remove the ShowPlayerDialog from OnPlayerConnect and put it here
        ShowPlayerDialog(playerid, DialogLogin, DIALOG_STYLE_PASSWORD, "{FFFFFF}LOGIN", "{00FF00}Welcome back!\n\n{FFFFFF}Please enter your Password bellow to login:", "Login", "");
        return false;
    }
    switch (classid)
    {
        case 0, 1, 2, 3, 4, 5, 6, 7:
        {
            GameTextForPlayer(playerid, "~g~Trucker", 3000, 6);
            pInfo[playerid][PlayerClass] = TRUCKER;
        }
        case 8:
        {
            GameTextForPlayer(playerid, "~y~Pilot", 3000, 6);
            pInfo[playerid][PlayerClass] = PILOT;
        }
        case 9, 10, 11:
        {
            GameTextForPlayer(playerid, "~b~Police", 3000, 6);
            pInfo[playerid][PlayerClass] = POLICE;
        }
        case 12:
        {
            GameTextForPlayer(playerid, "~p~Mechanic", 3000, 6);
            pInfo[playerid][PlayerClass] = MECHANIC;
        }
    }
    return true;
}
With that OnPlayerRequestClass will be called before the dialog and now we only set the positions if the player logged in successfully
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)