SA-MP Forums Archive
How would i turn these into dialogs - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: How would i turn these into dialogs (/showthread.php?tid=122917)



How would i turn these into dialogs - Torran - 23.01.2010

How would i turn these 2 commands into dialogs,
I know the dialog code, But which bit of these commands goes where?
Heres the code, Could someone tell me?

pawn Код:
if(strcmp(cmd, "/register", true) == 0)
    {
      new name[MAX_PLAYER_NAME];
      tmp = strtok(cmdtext, idx);
      GetPlayerName(playerid, name, sizeof(name));
      if(strlen(tmp) == 0) return SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /register [password]");
      format(file,sizeof(file),"%s.ini",name);
      if(!fexist(file))
            {
              dini_Create(file);
              dini_IntSet(file, "Password", udb_hash(tmp));
              dini_IntSet(file,"AdminLevel", 0);
              dini_IntSet(file,"Cash", 0);
              SendClientMessage(playerid, 0xFFFFFFFF, "[System]: Account Created!");
              PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
              GetPlayerName(playerid, name, sizeof(name));
              printf("%s has registered a account!", name);
            }
            else
            {
              SendClientMessage(playerid, 0xFFFFFFFF, " Account Already Found In Database");
        PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
            }
        return 1;
    }
   
    if(strcmp(cmd, "/login", true) == 0)
    {
      new PlayerName[24];
      tmp = strtok(cmdtext, idx);
      if(strlen(tmp) == 0) return SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /login [password]");
        new name[MAX_PLAYER_NAME];
        if(IsLogged[playerid] == 1)
        {
            SendClientMessage(playerid, 0xFFFFFFFF, "You already are logged in!");
            return 1;
        }
        else
        {
            GetPlayerName(playerid, name, sizeof(name));
            format(file,sizeof(file),"%s.ini",name);
            if(fexist(file))
            {
            tmp2 = dini_Get(file, "Password");
                if(udb_hash(tmp) != strval(tmp2))
                {
                  SendClientMessage(playerid, 0xFFFFFFFF, "Login Failed!");
                  GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
                  printf("%s has failed to login", name);
                }
                else
                {
                    IsLogged[playerid] = 1;
                    SetPlayerMoney(playerid, dini_Int(file, "Cash"));
                    PlayerInfo[playerid][AdminLevel] = dini_Int(file, "AdminLevel");
                    SendClientMessage(playerid, 0xFFFFFFFF, "[System]: Account Logged into!");
                }
            }
        }
        return 1;
    }



Re: How would i turn these into dialogs - MaykoX - 24.01.2010

Use search (Dialog Register/login) and you found it.


Re: How would i turn these into dialogs - Torran - 24.01.2010

That would give me a registration system, I dont want a registration system,
I just wanna know which part of the login/register commands goes where when creating a dialog


Re: How would i turn these into dialogs - MadeMan - 24.01.2010

Put them under OnDialogResponse and instead of tmp use inputtext to get the password.


Re: How would i turn these into dialogs - Torran - 24.01.2010

So all of the command goes there but just change the tmp?


Re: How would i turn these into dialogs - MadeMan - 24.01.2010

Also change

pawn Код:
if(strcmp(cmd, "/register", true) == 0)
...
if(strcmp(cmd, "/login", true) == 0)
to

pawn Код:
if(dialogid == 10) // change 10 to your register dialogid
...
if(dialogid == 11) // change 11 to your login dialogid



Re: How would i turn these into dialogs - Torran - 24.01.2010

Quote:
Originally Posted by MadeMan
Also change

pawn Код:
if(strcmp(cmd, "/register", true) == 0)
...
if(strcmp(cmd, "/login", true) == 0)
to

pawn Код:
if(dialogid == 10) // change 10 to your register dialogid
...
if(dialogid == 11) // change 11 to your login dialogid
Thanks


Re: How would i turn these into dialogs - mansonh - 24.01.2010

A few seconds late but hope it helps. Again change the dialog numbers to whatever you need.

pawn Код:
if(strcmp(cmd, "/register", true) == 0)
{
    ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Register","", "Register", "Cancel");
}
if(strcmp(cmd, "/login", true) == 0)
{
    ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Enter Password","", "Login", "Cancel");
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == 1)
    {
    if(response == 1)
    {
      new name[MAX_PLAYER_NAME];
      tmp = strval(inputtext)
      GetPlayerName(playerid, name, sizeof(name));
      if(strlen(tmp) == 0) return SendClientMessage(playerid, 0xFFFFFFFF, "Password cannot be blank");
      format(file,sizeof(file),"%s.ini",name);
      if(!fexist(file))
      {
            dini_Create(file);
            dini_IntSet(file, "Password", udb_hash(tmp));
            dini_IntSet(file,"AdminLevel", 0);
            dini_IntSet(file,"Cash", 0);
            SendClientMessage(playerid, 0xFFFFFFFF, "[System]: Account Created!");
            PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
            GetPlayerName(playerid, name, sizeof(name));
            printf("%s has registered a account!", name);
        }
        else
        {
          SendClientMessage(playerid, 0xFFFFFFFF, " Account Already Found In Database");
      PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
        }
    }
    return 1;
    }
    if(dialogid == 2)
    {
    if(response == 1)
    {
      new PlayerName[24];
      tmp = strtok(cmdtext, idx);
      if(strlen(tmp) == 0) return SendClientMessage(playerid, 0xFFFFFFFF, "Password cannot be blank");
        new name[MAX_PLAYER_NAME];
        if(IsLogged[playerid] == 1)
        {
            SendClientMessage(playerid, 0xFFFFFFFF, "You already are logged in!");
            return 1;
        }
        else
        {
            GetPlayerName(playerid, name, sizeof(name));
            format(file,sizeof(file),"%s.ini",name);
            if(fexist(file))
            {
            tmp2 = dini_Get(file, "Password");
                if(udb_hash(tmp) != strval(tmp2))
                {
                  SendClientMessage(playerid, 0xFFFFFFFF, "Login Failed!");
                  GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
                  printf("%s has failed to login", name);
                }
                else
                {
                    IsLogged[playerid] = 1;
                    SetPlayerMoney(playerid, dini_Int(file, "Cash"));
                    PlayerInfo[playerid][AdminLevel] = dini_Int(file, "AdminLevel");
                    SendClientMessage(playerid, 0xFFFFFFFF, "[System]: Account Logged into!");
                }
            }
        }
    }
    return 1;
    }
}



Re: How would i turn these into dialogs - Torran - 24.01.2010

So like this:

pawn Код:
if(dialogid == 2)
{
    if(gPlayerInfo[playerid][PLAYER_REGGED] == 1)
    {
        SendClientMessage(playerid, COLOUR_ORANGE, "ERROR: You have already registered!");
        return 1;
    }
    else if(!params[0])
    {
        SendClientMessage(playerid, COLOUR_ORANGE, "USAGE: /register [password]");
        return 1;
    }
    else if(strlen(params) < gSettings[PASS_MIN] || strlen(params) > gSettings[PASS_MAX])
    {
    new string[200];
      format(string, sizeof(string), "ERROR: Password must be between %d and %d characters long!", gSettings[PASS_MIN], gSettings[PASS_MAX]);
    return SendClientMessage(playerid, COLOUR_ORANGE, string);
    }
    else
    {
        new password = num_hash(params);
        gPlayerInfo[playerid][PLAYER_PASS] = password;
        gPlayerInfo[playerid][PLAYER_REGGED] = 1;
        gPlayerInfo[playerid][PLAYER_LOGGED] = 1;
        GetPlayerIp(playerid, gPlayerInfo[playerid][PLAYER_IP], 16);
        new string[256];
        format(string, sizeof(string), "You have successfully registered your account with the password \'%s\'. You have been automatically logged in.", params);
        SendClientMessage(playerid, COLOUR_LIGHTBLUE, string);
        return 1;
    }
}

if(dialogid == 2)
{
    if(gPlayerInfo[playerid][PLAYER_REGGED] != 1)
    {
        SendClientMessage(playerid, COLOUR_ORANGE, "ERROR: You must register first to do that! Use /register [password] to register and login.");
        return 1;
    }
    else if(gPlayerInfo[playerid][PLAYER_LOGGED] == 1)
    {
        SendClientMessage(playerid, COLOUR_ORANGE, "ERROR: You are already logged-in.");
        return 1;
    }
    else if(!params[0])
    {
        SendClientMessage(playerid, COLOUR_ORANGE, "USAGE: /login [password]");
        return 1;
    }
    else
    {
        new password = num_hash(params);
        if(gPlayerInfo[playerid][PLAYER_PASS] == password)
        {
          gPlayerInfo[playerid][PLAYER_LOGGED] = 1;
            GetPlayerIp(playerid, gPlayerInfo[playerid][PLAYER_IP], 16);
          SendClientMessage(playerid, COLOUR_LIGHTBLUE, "You have successfully logged in to your account.");
          return 1;
        }
        else
        {
          SendClientMessage(playerid, COLOUR_ORANGE, "ERROR: Incorrect password.");
          return 1;
        }
    }
}



Re: How would i turn these into dialogs - mansonh - 24.01.2010

No. Try taking what I just posted.

You need to show the dialogs, then check for their responce.