Thursday, April 28, 2011

Making a simple Register/Login dialog.


First we will need the "Dini" include, so the information can be saved on ".ini " file!
Download and put the "Dini" include in /pawno/includes folder.


Now... Let's begin scripting.
Open Pawno and load your GameMode.
On top of it we must include the "Dini" file so add :
#include <Dini>

Then, we will identify every dialog with a number like this :
#define Register 0
#define Logged 1

Also, we must add a new condition:
new Login[MAX_PLAYERS];

Then, we must put this under OnPlayerConnect :
Login[playerid] = 0;
new nombre[MAX_PLAYER_NAME], archivo[256];
GetPlayerName(playerid, nombre, sizeof(nombre));
format(archivo, sizeof(archivo), "/Users/%s.ini", nombre);
if (!dini_Exists(archivo))
{
    ShowPlayerDialog(playerid, Register, DIALOG_STYLE_INPUT, "Register", "He writes your password:", "Acept", "Cancel");
}
else
{
    ShowPlayerDialog(playerid, Logged, DIALOG_STYLE_INPUT, "Login", "He writes your password", "Acept", "Cancel");
}

This will check if the player is registered and will show the dialog box for registration.


Now, under the callback OnDialogResponse we will put the following thing:
if (dialogid == Register)
{
    new nombrejugador[MAX_PLAYER_NAME], archivo[256];
    if (!strlen(inputtext)) return ShowPlayerDialog(playerid, Register, DIALOG_STYLE_INPUT, "Register", "He writes your password", "Acept", "Cancel");
    if (!response) return ShowPlayerDialog(playerid, Register, DIALOG_STYLE_INPUT, "Register", "He writes your password:", "Acept", "Cancel");
    GetPlayerName(playerid, nombrejugador, sizeof(nombrejugador));
    format(archivo, sizeof(archivo), "/Users/%s.ini", nombrejugador);
    dini_Create(archivo);
    dini_Set(archivo, "User", nombrejugador);
    dini_Set(archivo, "Password", inputtext);
    ShowPlayerDialog(playerid, Logged, DIALOG_STYLE_INPUT, "Login", "He writes your password", "Acept", "Cancel");
}

This will make sure that if a player is not registered, he will get the proper dialog.
If the dialog is closed it will be shown again, so that the player cannot spawn.


The last thing we need is the dialog for the login function.
So we add this:
if (dialogid == Logged)
{
    new nombrejugador[MAX_PLAYER_NAME], archivo[256], comprobante[256];
    if (!strlen(inputtext)) return ShowPlayerDialog(playerid, Logged, DIALOG_STYLE_INPUT, "Login", "He writes your password", "Acept", "Cancel");
    if (!response) return ShowPlayerDialog(playerid, Logged, DIALOG_STYLE_INPUT, "Login", "He writes your password", "Acept", "Cancel");
    GetPlayerName(playerid, nombrejugador, sizeof(nombrejugador));
    format(archivo, sizeof(archivo), "/Users/%s.ini", nombrejugador);
    format(comprobante, sizeof(comprobante), "%s", dini_Get(archivo, "Password"));
    if (!strcmp (inputtext, comprobante))
    {
        Login[playerid] = 1;
    }
    else
    {
        ShowPlayerDialog(playerid, Logged, DIALOG_STYLE_INPUT, "Login", "He writes your password", "Acept", "Cancel");
    }
}

Now compile the script and create a new folder called "users" in your Scriptfiles folder!

If you do everything properly the script will work 100%

No comments:

Post a Comment