Register & Login Dialogs..
#1

Yeah, i've never been good with these things.. What am I doing wrong? (I used djson, by the way)

OnDialogResponse:
pawn Code:
if(dialogid == 1) { //Register
        if(response) {
            new PlayerName[MAX_PLAYER_NAME], string[128];
            GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
            format(string, sizeof(string), "Elimination/Accounts/%s.json", PlayerName);
            if(!djIsSet(string,"Key"))
            {
                registerPlayer(playerid,inputtext);
                PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
                return 1;
            }
            else return ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Invalid Password!", "Warning: This server contains alot of action, and is not for the faint of heart.\nBe advised.\nPlease enter your password below:", "Submit", "Cancel");
        }
        else
        {
            ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Invalid Password!", "Warning: This server contains alot of action, and is not for the faint of heart.\nBe advised.\nPlease enter your password below:", "Submit", "Cancel");
        }
    }
    else if(dialogid == 2) { //Login
        if(response) {
            new PlayerName[MAX_PLAYER_NAME], string[128];
            GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
            format(string, sizeof(string), "Elimination/Accounts/%s.json", PlayerName);
            if(djIsSet(string,"Key"))
            {
                if(playerLoggedIn[playerid] == 1) return SendClientMessage(playerid, sc_LightRed, "ERROR: You are already logged in.");
                loginPlayer(playerid,inputtext);
                return 1;
            }
            else return ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Invalid Password!", "Warning: This server contains alot of action, and is not for the faint of heart.\nBe advised.\nPlease enter your password below:", "Submit", "Cancel");
        }
        else
        {
            ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Invalid Password!", "Warning: This server contains alot of action, and is not for the faint of heart.\nBe advised.\nPlease enter your password below:", "Submit", "Cancel");
        }
    }
Login & Register publics:
pawn Code:
public loginPlayer(playerid,password[])
{
    new string[80], CharName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, CharName, sizeof(CharName));
    format(string, sizeof(string), "Elimination/Accounts/%s.json", CharName);
    if(strcmp(dj(string,"Key"),password, true ) == 0 )
    {
        playerInfo[playerid][IsRegistered]=djInt(string,"IsRegistered");
        playerInfo[playerid][Administrator]=djInt(string,"Administrator");
        playerInfo[playerid][Cash]=djInt(string,"Cash");
        playerInfo[playerid][Skin]=djInt(string,"Skin");
        playerInfo[playerid][Experience]=djInt(string,"Experience");
        playerInfo[playerid][TimeOnline]=djInt(string,"TimeOnline");
        playerInfo[playerid][AccountStatus]=djInt(string,"AccountStatus");
    }
    else { GameTextForPlayer(playerid, "~w~Authentication~n~~r~rejected", 3000, 1); return 1; }
    if(playerInfo[playerid][IsRegistered] == 0)
    {
        playerInfo[playerid][Cash]=250;
        playerInfo[playerid][IsRegistered] = 1;
        playerInfo[playerid][AccountStatus] = 0;
        playerInfo[playerid][Administrator] = 0;
        playerInfo[playerid][TimeOnline] = 0;
        playerInfo[playerid][Experience] = 0;
        playerInfo[playerid][Skin] = random(300);
    }
    playerLoggedIn[playerid] = 1;
    format(string, sizeof(string), "[script] %s has logged in.", ReturnPlayerName(playerid));
    printf(string);
    SetPlayerColor(playerid, sc_White);
    SetPlayerScore(playerid, playerInfo[playerid][Experience]);
    SendClientMessage(playerid, sc_White, " Account found...");
    SendClientMessage(playerid, sc_White, " Password correct...");
    format(string, sizeof(string), " You have been logged in as '%s'!", ReturnPlayerName(playerid));
    SendClientMessage(playerid, sc_Lime, string);
    return 1;
}

public registerPlayer(playerid, password[])
{
    new string[50], CharName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, CharName, sizeof(CharName));
    format(string, sizeof(string), "Elimination/Accounts/%s.json", CharName);
    djCreateFile(string);
    djSet(string,"Key",password);
    djSetInt(string,"IsRegistered\n",playerInfo[playerid][IsRegistered]);
    djSetInt(string,"AdminLevel\n",playerInfo[playerid][Administrator]);
    djSetInt(string,"Cash\n",playerInfo[playerid][Cash]);
    djSetInt(string,"Skin\n",playerInfo[playerid][Skin]);
    djSetInt(string,"TimeOnline\n",playerInfo[playerid][TimeOnline]);
    djSetInt(string,"Experience\n",playerInfo[playerid][Experience]);
    djSetInt(string,"AccountStatus\n",playerInfo[playerid][AccountStatus]);
    djCommit(string);
    loginPlayer(playerid,password);
    return 1;
}
Reply
#2

What is (not?) happening?
Explain deeper please.

[This forum requires that you wait 120 seconds between posts. Please try again in 79 seconds.] I know I'm whining alot, but seriously.. This is ANNOYING!
Reply
#3

Quote:
Originally Posted by LarzI
View Post
What is (not?) happening?
Explain deeper please.

[This forum requires that you wait 120 seconds between posts. Please try again in 79 seconds.] I know I'm whining alot, but seriously.. This is ANNOYING!
Sure, and I agree with you, lol.

Well, I type in a password, and for some reason it doesn't create the file at all, but it works perfectly fine with accounts. Not to mention, it's showing the login dialog when it should be the register dialog.
Reply
#4

Show us where you show the dialogs to the player.
I recommend defining names to the dialogids
Example:
pawn Code:
#define DIALOG_REGISTER (0)
#define DIALOG_LOGIN (1)
And do
pawn Code:
if( dialogid == DIALOG_REGISTER )
More comfortable if you need to edit.
Reply
#5

Quote:
Originally Posted by LarzI
View Post
Show us where you show the dialogs to the player.
I recommend defining names to the dialogids
Example:
pawn Code:
#define DIALOG_REGISTER (0)
#define DIALOG_LOGIN (1)
That's a great idea, and sure, he's the OnPlayerConnect code.

pawn Code:
public OnPlayerConnect(playerid)
{
    new string[128];
    if(djIsSet(string,"Key")) { //Register
        SendClientMessage(playerid, sc_Lime, "Welcome to the Elimination Server!");
        SendClientMessage(playerid, sc_White, " This server is currently running version 1.0_R1 of 'Elimination'");
        SendClientMessage(playerid, sc_Grey, " Analyzing account status...");
        SendClientMessage(playerid, sc_Grey, " Showing register dialog...");
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Welcome to the Elimination Server!", "Warning: This server contains alot of action, and is not for the faint of heart.\nBe advised.\nPlease enter your password below:", "Submit", "Cancel");
        playerLoggedIn[playerid] = 0;
    }
    else { //Login
        SendClientMessage(playerid, sc_Lime, "Welcome to the Elimination Server!");
        SendClientMessage(playerid, sc_White, "This server is currently running version 1.0_R1 of 'Elimination'");
        SendClientMessage(playerid, sc_Grey, " Analyzing account status...");
        SendClientMessage(playerid, sc_Grey, " Showing login dialog...");
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Welcome to the Elimination Server!", "Warning: This server contains alot of action, and is not for the faint of heart.\nBe advised.\nPlease enter your password below:", "Submit", "Cancel");
        playerLoggedIn[playerid] = 0;
    }
    return 1;
}
Reply
#6

Should it be
pawn Code:
if(!djIsSet(string,"Key"))
?
Reply
#7

Quote:
Originally Posted by LarzI
View Post
Should it be
pawn Code:
if(!djIsSet(string,"Key"))
?
I'll try it.

EDIT: Still does not work, it enters, but it doesn't create the file.
Reply
#8

Hmm, I don't want to change all your code, that's up to you.
If you haven't already, you should check this tutorial: https://sampforum.blast.hk/showthread.php?tid=76634
I've never used DJson myself, only Dini.
I don't think I'm able to help you more, I'm sorry.

Good luck!
Reply
#9

Well, the thing that's confusing me is the command version works perfectly fine, and that's what's in the dialog response.
Reply
#10

Hmm, strange..
Try remaking the whole code. That usually helps me fix my errors when scripting.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)