SA-MP Forums Archive
[Tutorial] Register & Login System with Dialogs - DOF2 - 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: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] Register & Login System with Dialogs - DOF2 (/showthread.php?tid=281736)

Pages: 1 2


Register & Login System with Dialogs - DOF2 - Jafet_Macario - 07.09.2011

Register & Login System with Dialogs - DOF2

Introduction

This is my 2nd tutorial.
In this tutorial I'll show you how to create a register and login system, with dialogs, using DOF2.

What's DOF2?

DOF2 = Double-O-Files2, fast file reader and writer created by Double-O-Seven.
You can find more information here: https://sampforum.blast.hk/showthread.php?tid=253715

Step 1

Download Double-O-Files_2.inc from here: https://sampforum.blast.hk/showthread.php?tid=253715
Create a folder named "Users" in your scriptfiles.
Code:
..scriptfiles/Users
Step 2

At the top of your script, include Double-O-Files_2.
pawn Code:
#include <Double-O-Files_2>
This will load all the features of the Double-O-Files include, so make sure you included it.Let's define some dialog ID's also at the top.
pawn Code:
#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2
Step 3

Now, at the top of the script somewhere after includes, we got to save some variables, so we create an enum.
Enums, aka Enumerations are every useful for representing large groups of data and modifying constants quickly.
So we will store our Kills,Deaths,Money and Admin Level.
pawn Code:
enum pInfo
{
    pKills,
    pDeaths,
    pMoney,
    pAdmin
}
new PlayerInfo[MAX_PLAYERS][pInfo];
Step 4
Add
Code:
DOF2_Exit();
To your OnGameModeExit() callback.Or OnFilterScriptExit() if you're using it as a filterscript.'
Example:
pawn Code:
public OnFilterScriptExit()
{
    DOF2_Exit();
    return 1;
}
Scroll down to the OnPlayerConnect callback.
pawn Code:
public OnPlayerConnect(playerid)
{
    new file[64]; // We declare the size of the file
    GetPlayerName(playerid,file,sizeof(file)); // We get the file name
    format(file,sizeof(file),DOF2_File(file));// Here we get the path from DOF2_File (/Users)
    if(DOF2_FileExists(file)) // We check if the player is registered
    {
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Welcome.Please log-in","{FFFFFF}Type your {00FF22}password {FFFFFF}here to log-in","Log-in","Quit");
        // The log-in dialog will pop up
    }  
    else // If not registered
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,"Please register!","{FFFFFF}Type your {00FF22}password {FFFFFF}here to register.","Register","Quit");
        // The register dialog will pop up
    }
    return 1;
}
So we check if the the player is registered, if he is he will have to login, if not he will have to register.

Step 5

Now let's scroll down to OnDialogResponse callback.
pawn Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid) // We switch our dialog id's
    {
        case DIALOG_REGISTER: // If the dialog_register shows up ( id 1111)
        {
            if(!response) Kick(playerid); // If he click on Quit, he will get kicked
            if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,"Please register!","{FFFFFF}Type your {00FF22}password {FFFFFF}here to register.","Register","Quit");
            // If he doesn't type anything, the dialog will show again.
            if(response) // If he click on Register
            {
                new file[64]; // We declare the size of the file
                GetPlayerName(playerid,file,sizeof(file)); // We get the file name
                format(file,sizeof(file),DOF2_File(file)); // We get the path name from DOF2_File, that means from Users folder.
                DOF2_CreateFile(file, inputtext); // Creates the file and the password.
                DOF2_SetInt(file, "Kills", 0); // When the player register his kills will be set to 0, you can change
                DOF2_SetInt(file, "Deaths", 0); // His deaths will be set to 0, you can change
                DOF2_SetInt(file, "Money", 1000); // His money will be set to 1000, you can change
                DOF2_SetInt(file, "AdminLevel", 0); // His Admin Level will be set to 0, you can change
                DOF2_SaveFile(); // Saves the file.
                SetSpawnInfo(playerid, 0, 0, 1722.5123, -1912.7931, 13.5647, 269.15, 0, 0, 0, 0, 0, 0); // Sets where the player will spawn, this coordinates are from the Unity Station in Los Santos
                SpawnPlayer(playerid); // After registering, the player will spawn.
            }
        }
        case DIALOG_LOGIN: // If dialog_login (id 2222) shows up
        {
            if(!response) Kick(playerid); // If he click on Quit, he will get kicked.
            if(response) // If he click on Log-in
            {
                new file[64]; // We declare the size of the file
                GetPlayerName(playerid,file,sizeof(file)); // We get the file name
                format(file,sizeof(file),DOF2_File(file)); // We get the user path from DOF2_File ( folder Users )
                if(DOF2_FileExists(file)) // If he is registered
                {
                    if(DOF2_CheckLogin(file,inputtext)) // We check if the password match
                    {
                        PlayerInfo[playerid][pKills] = DOF2_GetInt(file,"Kills"); // We load our settings
                        PlayerInfo[playerid][pDeaths] = DOF2_GetInt(file,"Deaths");
                        PlayerInfo[playerid][pMoney] = DOF2_GetInt(file,"Money");
                        PlayerInfo[playerid][pAdmin] = DOF2_GetInt(file,"AdminLevel");
                        SetSpawnInfo(playerid, 0, 0, 1722.5123, -1912.7931, 13.5647, 269.15, 0, 0, 0, 0, 0, 0); // We set the spawn (Unity Station)
                        SpawnPlayer(playerid); // The player spawns after log-in
                        GivePlayerMoney(playerid, PlayerInfo[playerid][pMoney]); // We give the player his money
                        return 1;
                    }
                    else // If the password don't match, they will get an error
                    {
                        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Wrong Password!","{F81414}You have typed a wrong password\n{FFFFFF}Type your password here to log-in!","Log-in","Quit");
                        return 1;
                    }
                }
            }
        }
    }
    return 1;
}
Step 6

Now, we got to scroll down to OnPlayerDisconnect callback so when the player disconnects from the server his stats will be saved.
pawn Code:
public OnPlayerDisconnect(playerid, reason)
{
    new file[64]; // We declare the size of the file
    GetPlayerName(playerid,file,sizeof(file)); // We get the file name
    format(file,sizeof(file),DOF2_File(file));// We get the user path from DOF2_File (folder Users)
    DOF2_SetInt(file, "Kills",PlayerInfo[playerid][pKills]); // We set/update the players settings.
    DOF2_SetInt(file, "Deaths",PlayerInfo[playerid][pDeaths]);
    DOF2_SetInt(file, "Money",PlayerInfo[playerid][pMoney]);
    DOF2_SetInt(file, "AdminLevel",PlayerInfo[playerid][pAdmin]);
    return 1;
}
Step 7

We got also to add values at Kills and Deaths, so we go at OnPlayerDeath callback.
pawn Code:
public OnPlayerDeath(playerid, killerid, reason)
{
    PlayerInfo[killerid][pKills]++; // Will increase the killerid kills
    PlayerInfo[playerid][pDeaths]++; // Will increase the playerid ( the one who died ) the deaths.
    return 1;
}
Result
Pastebin: >>> HERE <<<
FilterScript from: >>> CLICK ME LAZY ASS <<<


End

If I missed anything, or I didn't explain something good please reply, I tried my best, thanks.

You did all correct but your accounts aren't saving?

If you did all correct, or downloaded the package and you accounts aren't saving, guess your using vista/windows7 (I had this problem, and also another got it, not all) here is how to fix it:
Code:
Right Click on samp-server.exe
Click on Properties
And Check the box that says Run as Administrator
Then Click Ok And your done it should work.
Credits

Double-O-Seven



Re: Register & Login System with Dialogs - DOF2 - Horrible - 08.09.2011

nice tutorial.....
but i am still use Y_Ini


Re: Register & Login System with Dialogs - DOF2 - Jafet_Macario - 08.09.2011

Quote:
Originally Posted by Horrible
View Post
nice tutorial.....
but i am still use Y_Ini
Thanks mate.


Re: Register & Login System with Dialogs - DOF2 - Jack_Leslie - 08.09.2011

DOF2 is unstable and even the creator said it can crash your server. I would recommend not using DOF2, but good job with the tutorial.


Re: Register & Login System with Dialogs - DOF2 - Kush - 08.09.2011

Quote:
Originally Posted by Jack_Leslie
View Post
DOF2 is unstable and even the creator said it can crash your server. I would recommend not using DOF2, but good job with the tutorial.
Mind referring to the post?

DOF2 is fast no doubt about that. It does contain lots of features and it seems to be reliable.

Nice work Jafet.


Re: Register & Login System with Dialogs - DOF2 - Jafet_Macario - 08.09.2011

Quote:
Originally Posted by Jack_Leslie
View Post
DOF2 is unstable and even the creator said it can crash your server. I would recommend not using DOF2, but good job with the tutorial.
Thank you mate.

Quote:
Originally Posted by Kush
View Post
Mind referring to the post?

DOF2 is fast no doubt about that. It does contain lots of features and it seems to be reliable.

Nice work Jafet.
Thank you mate.


Re: Register & Login System with Dialogs - DOF2 - Darnell - 08.09.2011

Great work, excellent.


Re: Register & Login System with Dialogs - DOF2 - Davz*|*Criss - 08.09.2011

Nice work Jafet.


Re: Register & Login System with Dialogs - DOF2 - Jafet_Macario - 08.09.2011

Thanks guys. <3


Re: Register & Login System with Dialogs - DOF2 - Darnell - 08.09.2011

Hmmm, it's kinda bummer that DOF2 crashing the server >.>.


Re: Register & Login System with Dialogs - DOF2 - Jafet_Macario - 08.09.2011

Yeah, hope Double-O-Seven fix it.


Re: Register & Login System with Dialogs - DOF2 - Basicz - 09.09.2011

Or you could use DOF2_ParseFile for a better performance ?

Nice job on the tutorial though.


Re: Register & Login System with Dialogs - DOF2 - Jafet_Macario - 09.09.2011

Quote:
Originally Posted by Basicz
View Post
Or you could use DOF2_ParseFile for a better performance ?

Nice job on the tutorial though.
Thank you.


Re: Register & Login System with Dialogs - DOF2 - Issam - 16.09.2011

Step 5

Now we got to save some variables, so we create an enum.
Enums, aka Enumerations are every useful for representing large groups of data and modifying constants quickly.
So we will store our Kills,Deaths,Money and Admin Level.
pawn Code:
enum pInfo
{
    pKills,
    pDeaths,
    pMoney,
    pAdmin
}
new PlayerInfo[MAX_PLAYERS][pInfo];
Where to exactly ADD THIS? someone HELP HERE!!


Re: Register & Login System with Dialogs - DOF2 - Jafet_Macario - 16.09.2011

Quote:
Originally Posted by Issam
View Post
Step 5

Now we got to save some variables, so we create an enum.
Enums, aka Enumerations are every useful for representing large groups of data and modifying constants quickly.
So we will store our Kills,Deaths,Money and Admin Level.
pawn Code:
enum pInfo
{
    pKills,
    pDeaths,
    pMoney,
    pAdmin
}
new PlayerInfo[MAX_PLAYERS][pInfo];
Where to exactly ADD THIS? someone HELP HERE!!
Edited, take a look now.


Re: Register & Login System with Dialogs - DOF2 - Issam - 16.09.2011

Can you make a FILTERSCRIPT of this,please
Adding to GM is kinda hard,and gives me bunch of errors,like 9
+1rep.



Re: Register & Login System with Dialogs - DOF2 - Jafet_Macario - 16.09.2011

It's already there.
Quote:
http://solidfiles.com/d/1cade/



Re: Register & Login System with Dialogs - DOF2 - Issam - 16.09.2011

Quote:
Originally Posted by Jafet_Macario
View Post
It's already there.
I Tested it,its working but.. its not a filterscript,its a GM
its located on GameModes
and when you open it
its
OnGameModeInit
not
OnFilterScriptinIT
Correct me,if i'm wrong,please!


Re: Register & Login System with Dialogs - DOF2 - Jafet_Macario - 16.09.2011

Here you go: http://solidfiles.com/d/854be/


Re: Register & Login System with Dialogs - DOF2 - Issam - 16.09.2011

Quote:
Originally Posted by Jafet_Macario
View Post
Thank you! but.. i did load this time,when i went in,there is no DIALOG.. strange
I Checked Scriptfiles/Users and found Issam.inc,but its empty when i open it.
If you need any info,tell me so i can post it,please help and already +rep.