[Tutorial] Login and Register System - Dialogs - Using SII
#1

Login and Register System - Dialogs - Using SII.

I've seen numerous people, wanting to switch from the older Dini file saving system to a newer one, such as Y_INI, djSON and even Fini. Most of them understand the Dini format, and examples, even tutorials of the newer systems sometimes help, but to some of the newer 'developers' this can be a struggle. I've created this tutorial to help those wishing to upgrade' to a newer system, a better system.

What is this?
This is a simple tutorial on how to make Login and Register system with dialogs using SII.


Step 1
Firstly, your going to need to download the SII include. You can find it here: https://sampforum.blast.hk/showthread.php?tid=58458. Once downloaded, place it into your Pawno > include folder.

Step 2
Add the include at the top of the script.

pawn Code:
#include <SII>
The SII include contains all the needed functions you are going to use to create your Login and Register system.
Step 3
Let's define some dialogs:

pawn Code:
#define DIALOG_REGISTER 2000
#define DIALOG_LOGIN 2001
Step 4
Let's add some colors:

pawn Code:
#define WHITE "{FFFFFF}"
#define RED "{F81414}"
#define GREEN "{00FF22}"
#define LIGHTBLUE "{00CED1}"
Step 5
Create a new variable, somewhere below your defines.

pawn Code:
new gPlayerName[MAX_PLAYERS][MAX_PLAYER_NAME];
Step 6
Next, lets add an enum, also known as an enumeration.

pawn Code:
enum pInfo
{
    pPass,
    pScore,
    pCash,
    pAdmin
}
new PlayerInfo[MAX_PLAYERS][pInfo];
An enumeration stores many things in a variable. This is extremely efficient and effective, instead of creating a set of different variables.


Step 7
Lets create a stock function:

pawn Code:
stock getINI(playerid)
{
  new account[64];
  format(account,30,"Users/%s.ini",gPlayerName[playerid]);
  return account;
}
The stock function is going to load the user file.

Step 8
We'll be using the native 'fexist' function to search for our file. Parameters are set to our stock function which we've created. If the file exists, you will receive a 'Login' dialog. If it doesn't, you will receive a register dialog.


pawn Code:
public OnPlayerConnect(playerid)
{
    GetPlayerName(playerid, gPlayerName[playerid], MAX_PLAYER_NAME);
    if (fexist(getINI(playerid)))
    {
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""WHITE"Login",""WHITE"Type your password below to login.","Login","Quit");
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,""WHITE"Registering...",""WHITE"Type your password below to register a new account.","Register","Quit");
    }
    return 1;
}
Step 9
Go to your OnDialogResponse callback and add this in.


pawn Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch( dialogid )
    {
        case DIALOG_REGISTER:
        {
            if (!response) return Kick(playerid);
            if (response)
            {
                if(!strlen(inputtext)) {
                ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""WHITE"Registering...",""RED"You have entered an invalid password.\n"WHITE"Type your password below to register a new account.","Register","Quit");
                }

                if(INI_Open(getINI(playerid))) {
                INI_WriteString("Password",inputtext);
                INI_WriteInt("Score",1);
                INI_WriteInt("Cash",5000);
                INI_WriteInt("Admin",0);

                INI_Save();
                INI_Close();

                ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""WHITE"Login",""WHITE"Type your password below to login.","Login","Quit");
            }
        }
    }
        case DIALOG_LOGIN:
        {
            if ( !response ) return Kick ( playerid );
            if( response )
            {
                if(!strlen(inputtext)) {
                ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, ""WHITE"Login",""RED"You have entered an invalid password.\n"WHITE"Type your password below to login.","Login","Quit");
                }

                if(INI_Open(getINI(playerid))) {
                INI_ReadString(PlayerInfo[playerid][pPass],"Password",20);

                if(strcmp(inputtext,PlayerInfo[playerid][pPass],false)) {
                ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, ""WHITE"Login",""RED"You have entered an incorrect password.\n"WHITE"Type your password below to login.","Login","Quit");
                }

                SetPlayerScore( playerid, INI_ReadInt("Score" ) );
                ResetPlayerMoney( playerid );
                GivePlayerMoney( playerid, INI_ReadInt( "Cash" ) );
                PlayerInfo[playerid][pAdmin] = INI_ReadInt("Admin");
                INI_Close();
                }
            }
        }
    }
    return 1;
}
case DIALOG_REGISTER:

Instead of using the 'if' statement to define my dialogs, I've used cases as they seem to take less space and are supposedly 'faster'. The (!response) is the function if the first Button hasn't been clicked, it will then kick the player.

The if(!strlen(inputtext)) explains if nothing has been entered into the dialog (input), you would then be prompted to another dialog which shows you 'Incorrect Password'.

If all goes well, the function INI_Open is then executed which loads and opens the Userfile. Once open, other functions 'INI_WriteString' 'INI_WriteInt' can be called. It is then finished by the 'INI_Save' function which saves the values which has been set and/or strings which has been entered. Finally, 'INI_Close' closes the Userfile.

Once finished, you will then be prompted to the 'Login' dialog.

case DIALOG_LOGIN:

The only thing which is happening (with the exception of the Userfile being opened and closed) the 'INI_ReadInt' and 'INI_ReadString' function is called. When the player logs in, it loads the players 'stats' or so to say.

Example: If the player had, $1000 dollars before he disconnected, the function 'INI_ReadInt' would read that value, which would be called with GivePlayerMoney to load the player's Money value.

Step 10
Finally, we'll need to save the player stats, when he disconnects.

pawn Code:
public OnPlayerDisconnect(playerid, reason)
{
    if(INI_Open(getINI(playerid))) {
   
    INI_WriteInt("Score",PlayerInfo[playerid][pScore]);
    INI_WriteInt("Cash",GetPlayerMoney(playerid));
    INI_WriteInt("Admin",PlayerInfo[playerid][pAdmin]);

    INI_Save();
    INI_Close();
    }
    return 1;
}
I've chose the OnPlayerDisconnect callback to save player 'stats' because this creates MUCH less lag as opposed to the OnPlayerUpdate.


Downloads:


Pastebin - http://pastebin.com/kgvZGm3e


Credits:
[DRuG]Slick - SII Include
Las Venturas CNR - The man who showed me Dini was shit!
Reply


Messages In This Thread
Login and Register System - Dialogs - Using SII - by Kush - 10.07.2011, 00:02
Re: Login and Register System - Dialogs - Using SII - by Calgon - 10.07.2011, 00:24
Re: Login and Register System - Dialogs - Using SII - by Kush - 10.07.2011, 00:31
Re: Login and Register System - Dialogs - Using SII - by HyperZ - 10.07.2011, 03:57
Re: Login and Register System - Dialogs - Using SII - by Steven82 - 10.07.2011, 04:50
Re: Login and Register System - Dialogs - Using SII - by dowster - 10.07.2011, 06:22
Re: Login and Register System - Dialogs - Using SII - by Basicz - 10.07.2011, 07:36
Re: Login and Register System - Dialogs - Using SII - by Davz*|*Criss - 10.07.2011, 09:44
Re: Login and Register System - Dialogs - Using SII - by Kush - 10.07.2011, 14:52
Re: Login and Register System - Dialogs - Using SII - by Coffeemonster - 11.07.2011, 16:12
Re: Login and Register System - Dialogs - Using SII - by Kush - 11.07.2011, 16:33
Re: Login and Register System - Dialogs - Using SII - by GoldenM4 - 12.07.2011, 16:25
Re: Login and Register System - Dialogs - Using SII - by Coffeemonster - 15.07.2011, 12:55
Re: Login and Register System - Dialogs - Using SII - by Kush - 15.07.2011, 19:54
Re: Login and Register System - Dialogs - Using SII - by Seven_of_Nine - 15.07.2011, 20:16
Re: Login and Register System - Dialogs - Using SII - by Kush - 15.07.2011, 20:17
Re: Login and Register System - Dialogs - Using SII - by Seven_of_Nine - 15.07.2011, 20:18
Re: Login and Register System - Dialogs - Using SII - by Coffeemonster - 15.07.2011, 22:01
Re: Login and Register System - Dialogs - Using SII - by Ehab1911 - 17.07.2011, 15:40
Re: Login and Register System - Dialogs - Using SII - by Dark.Angel - 20.07.2011, 17:36
AW: Re: AW: Login and Register System - Dialogs - Using SII - by samtey - 20.07.2011, 19:16
Re: Login and Register System - Dialogs - Using SII - by System64 - 20.07.2011, 19:56
AW: Login and Register System - Dialogs - Using SII - by samtey - 20.07.2011, 20:01
AW: Login and Register System - Dialogs - Using SII - by samtey - 20.07.2011, 20:08
Re: Login and Register System - Dialogs - Using SII - by System64 - 20.07.2011, 20:28
Re: Login and Register System - Dialogs - Using SII - by Kush - 20.07.2011, 20:56
Re: AW: Login and Register System - Dialogs - Using SII - by Shockey HD - 22.07.2011, 22:12
Re: Login and Register System - Dialogs - Using SII - by Mustafa6155 - 10.10.2012, 10:44
Re: Login and Register System - Dialogs - Using SII - by danilonba - 23.10.2012, 16:06
Re: Login and Register System - Dialogs - Using SII - by burnfire - 17.04.2013, 13:07
Re: Login and Register System - Dialogs - Using SII - by Player23 - 28.06.2013, 05:00
Re: Login and Register System - Dialogs - Using SII - by Hardy - 28.06.2013, 19:57
Re: Login and Register System - Dialogs - Using SII - by Akira297 - 02.07.2013, 03:52
Re: Login and Register System - Dialogs - Using SII - by AntmanCow - 02.07.2013, 17:19

Forum Jump:


Users browsing this thread: 3 Guest(s)