[Tutorial] How to make a Login/Register System [Saving Stats]
#1

Introduction
--> As title says, I will show you how to make a Login/Register system !

You need:
--> To can start this filescript you need Dini, Dudb, Dutils :

Dini.inc
Dudb.inc
Dutils.inc

Start:
--> After you downloaded 3 (Dini, Dudb, Dutils) we can start !

1. --> So, firsts line add #includes, like :
Code:
#include <a_samp>
#include <dini>
#include <dudb>
2. --> Then, under includes we need to add enums, like :

Code:
enum pInfo
{
    pAdmin, // will save player's Admin !
    pVip, // will save player's Vip !
    pCash, // will save player's Cash !
    pScore, // will save player's Score !
    pKills, // will save player's Kills !
    pDeaths, // will save player's Deaths!
// here you can add more enums, wich saves what do you want 
}  // Closing Brackelet !
new PlayerInfo[MAX_PLAYERS][pInfo]; // Player Info
3. --> Then under new PlayerInfo[MAX_PLAYERS][pInfo]; add :
Code:
new gPlayerLogged[MAX_PLAYERS]; // If player it's logged ! 


If you get the errors:



C:\Users\Tedi\Downloads\Desktop\samp03z_svr_R1_win32 (1)\filterscripts\H_System.pwn(58) : warning 203: symbol is never used: "PlayerInfo"
C:\Users\Tedi\Downloads\Desktop\samp03z_svr_R1_win32 (1)\filterscripts\H_System.pwn(58) : warning 203: symbol is never used: "gPlayerLogged"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


2 Warnings.

Don't worry, just says to you symbol it's never used, you will see at final will work !
4. --> Then enums we need to make an "Ini" file, wich, when a player registered, save his money/cash/admin/score/kills/death in a .ini ! So we add:
Code:
#define PATH "/Users/%s.ini" // Stats will be saved in : "scriptfiles/users/"PlayerName.ini"

*NOTE: Change "Users" to your Folder Name"
*NOTE: You need to make folder with that name, else not, player's stats will be not saved !
5. --> Then we need to go under :
[CODE]
Code:
public OnPlayerConnect(playerid);
{
And add :
Code:
public OnPlayerConnect(playerid) // OnPlayerConnect Public
{ // Open Brackelet !
    gPlayerLogged[playerid] = 0; // if player isn't registered/logged !
    new name[MAX_PLAYER_NAME], file[256]; // make variables (file--> users file); (new name --> New Player Name)
    GetPlayerName(playerid, name, sizeof(name)); // Will get that player name !
    format(file, sizeof(file), PATH, name); Will search about his .ini file !
    if (!dini_Exists(file))  // If his file doesn't exists, then :
    {  // open brackelet
        ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "-->{FF0000}Register {0066CC}Account", "{FF0000}Welcome, you are not registered!\n{0066CC}Enter your password below to can save your {FFFF00}Cash,Score {0066CC}Admin/Vip!", "Register", "Exit");  // Showin' Register Dialog 
    }  // Closing Brackelet
    if(fexist(file))  // If his .ini file exists then :
    {  // Open brackelet !
        ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "-->{FF0000}Login {0066CC}Account", "{FF0000}Welcome back !\n{0066CC}Thank you because you are playing again on our server !\n{FFFF00}To can play, please input your{FF0000} password {FF0000}below!", "Login", "Exit"); //  // Showin' Login Dialog !
    }  // Closing brackelet !
    return 1;  // to show we finished 
}  // Closing brackelet !
6. --> Then we need to go under :
[CODE][CODE]
Code:
public OnPlayerDisconnect(playerid, reason)
{
And add :
Code:
    new name[MAX_PLAYER_NAME], file[256]; // New name --> Player's name, file --> .ini player's file !
    GetPlayerName(playerid, name, sizeof(name)); // Will get player's name ! 
    format(file, sizeof(file), PATH, name); // Will search about his .ini file !
    if(gPlayerLogged[playerid] == 1) // if player it's logged !
    { // Open brackelet ! 
        dini_IntSet(file, "Score", PlayerInfo[playerid][pScore]); // His Score
        dini_IntSet(file, "Money", PlayerInfo[playerid][pCash]); // His Cash
        dini_IntSet(file, "Admin",PlayerInfo[playerid][pAdmin]); // His Admin
        dini_IntSet(file, "pVip",PlayerInfo[playerid][pVip]); // His Vip
        dini_IntSet(file, "Kills",PlayerInfo[playerid][pKills]); // His Kills
        dini_IntSet(file, "Deaths",PlayerInfo[playerid][pDeaths]); // His Deaths
    } // Closing brackelet
    gPlayerLogged[playerid] = 0; // He aren't login = 0 !
	return 1; // Finish OnPlayerDissconect
} // Closing Latest brackelet !
7. --> Now, we need to go under :
Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
--> To finish Register/Login Dialog !
--> So, we add:

--> FOR REGISTER DIALOG :
Code:
if (dialogid == 1) // First Dialog (Register Dialog)
    {  // Open brackelet!
        new name[MAX_PLAYER_NAME], file[256], string[128]; // his name, .ini file, string
        GetPlayerName(playerid, name, sizeof(name));  // Will get player's name !
        format(file, sizeof(file), PATH, name);  // Search about .ini file name !
        if(!response) return Kick(playerid);  // If he hit Exit, will get kicked !
        if (!strlen(inputtext)) return  // What Password he will write in box !
        ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "-->{FF0000}Register {0066CC}Account", "{FF0000}Welcome, you are not registered!\n{0066CC}Enter your password below to can save your {FFFF00}Cash,Score {0066CC}Admin/Vip!", "Register", "Exit");  // Register Dialog !
        dini_Create(file);  // Dini will create .ini file for that player !
        dini_IntSet(file, "Password", udb_hash(inputtext));  // Will save his password ! He can login again just with his password !
        dini_IntSet(file, "AdminLevel",PlayerInfo[playerid][pAdmin] = 0);  // Will save his Admin (0 now)
        dini_IntSet(file, "Money",PlayerInfo[playerid][pCash] = 500);  // Will save his money, will be spawned with 500 $ !
        dini_IntSet(file, "Score",PlayerInfo[playerid][pScore] = 1);  // Will save his score, when he will be spawned with 1 Score !
        dini_IntSet(file, "Kills",PlayerInfo[playerid][pKills] = 0);
        dini_IntSet(file, "Deaths",PlayerInfo[playerid][pDeaths] = 0);
        format(string, 128, "{FF0000}[--> Succesfully <--]: {FFFF00}%s {0066CC} you have been succesfully registered!", name, inputtext);  // Chat Message !
        SendClientMessage(playerid, -1, string);  // Will put this message on registered player's chat!
		gPlayerLogged[playerid] = 1;  // Now, he is Auto-Logged (he don't need to put again his password, only if he exit and enter again on server !)
    }  // Closing Brackelet
--> FOR LOGIN DIALOG :

Code:
if (dialogid == 2) // Dialog 2 (Login Dialog)
    { // Open brackelet
        new name[MAX_PLAYER_NAME], file[256], string[128]; // player's name, .ini file, string
        GetPlayerName(playerid, name, sizeof(name)); // Will get player's name !
        format(file, sizeof(file), PATH, name); // Search about .ini file from that player !
        if(!response) return Kick(playerid); // If he hit Exit he will be kicked !
        if (!strlen(inputtext)) return ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "-->{FF0000}Login {0066CC}Account", "{FF0000}Welcome back !\n{0066CC}Thank you because you are playing again on our server !\n{FFFF00}To can play, please input your{FF0000} password {FF0000}below!", "Login", "Exit"); // Our Login Dialog !
        new tmp; // Variable !
        tmp = dini_Int(file, "Password"); // Password !
        if(udb_hash(inputtext) != tmp) // In that box if he don't put correct password from .ini file then :
       { // Open Brackelet 
            SendClientMessage(playerid, -1, "{FF0000}Wrong password! {0066CC}Try another one !"); // He will cannot login !
            ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "-->{FF0000}Login {0066CC}Account", "{FF0000}Welcome back !\n{0066CC}Thank you because you are playing again on our server !\n{FFFF00}To can player, please input your{FF0000}password {FF0000}below!", "Login", "Exit"); // And if his password it's wrong he will saw again our Login Dialog, to try again log in !
        } // Closin brackelet !
        else // Else
        { // Open brackelet !
            gPlayerLogged[playerid] = 1; // 1 = He it's logged !
            PlayerInfo[playerid][pAdmin] = dini_Int(file, "AdminLevel"); // If he have Admin, in .ini file will load his Admin before login !
            SetPlayerScore(playerid, PlayerInfo[playerid][pScore]); // Will sets his score from last time , from .ini file !
            GivePlayerMoney(playerid, dini_Int(file, "Money")-GetPlayerMoney(playerid)); // He will get money from last time, from .ini file !
            SendClientMessage(playerid, -1, "{FF0000}[--> Succesfully <--]: {0066CC}You have been {FFFF00}successfully {0066CC}logged in!"); // This he will saw after Login !
        } // Closing brackelet *1 !
    } // Closing brackelet *2!
} // Closing latest brackele *2!
All Code:
Code:
#include <a_samp>
#include <dini>
#include <dudb>

enum pInfo
{
    pAdmin,
	pVip,
	pCash,
    pScore,
    pKills,
    pDeaths,
}
new PlayerInfo[MAX_PLAYERS][pInfo];
new gPlayerLogged[MAX_PLAYERS];


#define PATH "/Users/%s.ini"

#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
	print("\n--------------------------------------");
	print("       *LOGIN/REGISTER SGYSTEM          ");
	print("--------------------------------------\n");
	return 1;
}

#else
#endif

public OnGameModeInit()
{
	SetGameModeText("H_System");
	AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
	return 1;
}

public OnGameModeExit()
{
	return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
	SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
	SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
	SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
	return 1;
}
public OnPlayerConnect(playerid)
{
    gPlayerLogged[playerid] = 0;
    new name[MAX_PLAYER_NAME], file[256];
    GetPlayerName(playerid, name, sizeof(name));
    format(file, sizeof(file), PATH, name);
    if (!dini_Exists(file))
    {
        ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "-->{FF0000}Register {0066CC}Account", "{FF0000}Welcome, you are not registered!\n{0066CC}Enter your password below to can save your {FFFF00}Cash,Score {0066CC}Admin/Vip!", "Register", "Exit");
    }
    if(fexist(file))
    {
        ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "-->{FF0000}Login {0066CC}Account", "{FF0000}Welcome back !\n{0066CC}Thank you because you are playing again on our server !\n{FFFF00}To can play, please input your{FF0000} password {FF0000}below!", "Login", "Exit");
    }
	return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new name[MAX_PLAYER_NAME], file[256];
    GetPlayerName(playerid, name, sizeof(name));
    format(file, sizeof(file), PATH, name);
    if(gPlayerLogged[playerid] == 1)
    {
        dini_IntSet(file, "Score", PlayerInfo[playerid][pScore]);
        dini_IntSet(file, "Money", PlayerInfo[playerid][pCash]);
        dini_IntSet(file, "Admin",PlayerInfo[playerid][pAdmin]);
        dini_IntSet(file, "pVip",PlayerInfo[playerid][pVip]);
        dini_IntSet(file, "Kills",PlayerInfo[playerid][pKills]);
        dini_IntSet(file, "Deaths",PlayerInfo[playerid][pDeaths]);
    }
    gPlayerLogged[playerid] = 0;
	return 1;
}

public OnPlayerText(playerid, text[])
{
	return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if (dialogid == 1)
    {
        new name[MAX_PLAYER_NAME], file[256], string[128];
        GetPlayerName(playerid, name, sizeof(name));
        format(file, sizeof(file), PATH, name);
        if(!response) return Kick(playerid);
        if (!strlen(inputtext)) return
        ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "-->{FF0000}Register {0066CC}Account", "{FF0000}Welcome, you are not registered!\n{0066CC}Enter your password below to can save your {FFFF00}Cash,Score {0066CC}Admin/Vip!", "Register", "Exit");
        dini_Create(file);
        dini_IntSet(file, "Password", udb_hash(inputtext));
        dini_IntSet(file, "AdminLevel",PlayerInfo[playerid][pAdmin] = 0);
        dini_IntSet(file, "Money",PlayerInfo[playerid][pCash] = 500);
        dini_IntSet(file, "Score",PlayerInfo[playerid][pScore] = 0);
        dini_IntSet(file, "Kills",PlayerInfo[playerid][pKills] = 0);
        dini_IntSet(file, "Deaths",PlayerInfo[playerid][pDeaths] = 0);
        format(string, 128, "{FF0000}[--> Succesfully <--]: {FFFF00}%s {0066CC} you have been succesfully registered!", name, inputtext);
        SendClientMessage(playerid, -1, string);
        ShowPlayerDialog(playerid, 3, DIALOG_STYLE_MSGBOX, "{FF0000}IMPORTANT!", "{FF0000}*NOTE:{0066CC}Thanks because you have registered on our server !\n{FFFF00}We hope you will enjoy him and our Staff wish you {0066CC}welcome ! :)","Exit", "");
		gPlayerLogged[playerid] = 1;
    }
    if (dialogid == 2)
    {
        new name[MAX_PLAYER_NAME], file[256], string[128];
        GetPlayerName(playerid, name, sizeof(name));
        format(file, sizeof(file), PATH, name);
        if(!response) return Kick(playerid);
        if (!strlen(inputtext)) return ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Hi your registered", "Fucken awesome mate, your registered :D. Inpute your pw below", "Login", "Leave");
        new tmp;
        tmp = dini_Int(file, "Password");
        if(udb_hash(inputtext) != tmp) {
            SendClientMessage(playerid, -1, "{FF0000}Wrong password! {0066CC}Try another one !");
            ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "-->{FF0000}Login {0066CC}Account", "{FF0000}Welcome back !\n{0066CC}Thank you because you are playing again on our server !\n{FFFF00}To can player, please input your{FF0000}password {FF0000}below!", "Login", "Exit");
        }
        else
        {
            gPlayerLogged[playerid] = 1;
            PlayerInfo[playerid][pAdmin] = dini_Int(file, "AdminLevel");
            SetPlayerScore(playerid, PlayerInfo[playerid][pScore]);
            GivePlayerMoney(playerid, dini_Int(file, "Money")-GetPlayerMoney(playerid));
            SendClientMessage(playerid, -1, "{FF0000}[--> Succesfully <--]: {0066CC}You have been {FFFF00}successfully {0066CC}logged in!");
        }
    }
	return 1;
}
Last Words:
--> I explained to all can understand !
--> If I made a mistake, tell me !
--> Cheers! <--

Bugs:
*Tested Code:
--> This code (Login/Register Dialog) was tested and no bugs, it's workin' fine !
--> If you find an bug, tell me, I will solve them !



Preview:







Reply
#2

Ain't explained enough edit and explain little bit more/

4/10
Reply
#3

Why use Dini while yini is much better than that?
Reply
#4

Quote:
Originally Posted by YanLanger
View Post
Ain't explained enough edit and explain little bit more/

4/10
I'm sorry if you don't like, but I explained line with line!

Quote:
Originally Posted by DavidBilla
View Post
Why use Dini while yini is much better than that?
I work better with Dini !
Reply
#5

I didn't say i didn't like it i like it

And i said it's a little bit not explained anyways good job

And explaining it's something like

Explain What it suppost to do, when do i use it how do i use it where i put it etc..
Reply
#6

Go to MySQL R39 XD
Reply
#7

Quote:
Originally Posted by YanLanger
View Post
Ain't explained enough edit and explain little bit more/

4/10
I also think so but i will give you 6/10.
You just said: add that and add that and now add that...
In the Code you made a Little commentary but in ms view that's not enough.
Reply
#8

That code could use some work, it's not very efficient.

Also, i've heard a lot of bad things about DINI. Try Y_ini

ALSO, don't use OnFilterScriptInit and OnGameModeInit.
Reply
#9

nice
Reply
#10

Why if I include sscanf and zcmd the script for registering and loging don't work? when I try to enter in the server, didn't show me the dialogs, how i can fix it?

Quote:
Originally Posted by HY
View Post
Introduction
--> As title says, I will show you how to make a Login/Register system !

You need:
--> To can start this filescript you need Dini, Dudb, Dutils :

Dini.inc
Dudb.inc
Dutils.inc

Start:
--> After you downloaded 3 (Dini, Dudb, Dutils) we can start !

1. --> So, firsts line add #includes, like :
Code:
#include <a_samp>
#include <dini>
#include <dudb>
2. --> Then, under includes we need to add enums, like :

Code:
enum pInfo
{
    pAdmin, // will save player's Admin !
    pVip, // will save player's Vip !
    pCash, // will save player's Cash !
    pScore, // will save player's Score !
    pKills, // will save player's Kills !
    pDeaths, // will save player's Deaths!
// here you can add more enums, wich saves what do you want 
}  // Closing Brackelet !
new PlayerInfo[MAX_PLAYERS][pInfo]; // Player Info
3. --> Then under new PlayerInfo[MAX_PLAYERS][pInfo]; add :
Code:
new gPlayerLogged[MAX_PLAYERS]; // If player it's logged ! 


If you get the errors:



C:\Users\Tedi\Downloads\Desktop\samp03z_svr_R1_win32 (1)\filterscripts\H_System.pwn(58) : warning 203: symbol is never used: "PlayerInfo"
C:\Users\Tedi\Downloads\Desktop\samp03z_svr_R1_win32 (1)\filterscripts\H_System.pwn(58) : warning 203: symbol is never used: "gPlayerLogged"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


2 Warnings.

Don't worry, just says to you symbol it's never used, you will see at final will work !
4. --> Then enums we need to make an "Ini" file, wich, when a player registered, save his money/cash/admin/score/kills/death in a .ini ! So we add:
Code:
#define PATH "/Users/%s.ini" // Stats will be saved in : "scriptfiles/users/"PlayerName.ini"

*NOTE: Change "Users" to your Folder Name"
*NOTE: You need to make folder with that name, else not, player's stats will be not saved !
5. --> Then we need to go under :
[CODE]
Code:
public OnPlayerConnect(playerid);
{
And add :
Code:
public OnPlayerConnect(playerid) // OnPlayerConnect Public
{ // Open Brackelet !
    gPlayerLogged[playerid] = 0; // if player isn't registered/logged !
    new name[MAX_PLAYER_NAME], file[256]; // make variables (file--> users file); (new name --> New Player Name)
    GetPlayerName(playerid, name, sizeof(name)); // Will get that player name !
    format(file, sizeof(file), PATH, name); Will search about his .ini file !
    if (!dini_Exists(file))  // If his file doesn't exists, then :
    {  // open brackelet
        ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "-->{FF0000}Register {0066CC}Account", "{FF0000}Welcome, you are not registered!\n{0066CC}Enter your password below to can save your {FFFF00}Cash,Score {0066CC}Admin/Vip!", "Register", "Exit");  // Showin' Register Dialog 
    }  // Closing Brackelet
    if(fexist(file))  // If his .ini file exists then :
    {  // Open brackelet !
        ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "-->{FF0000}Login {0066CC}Account", "{FF0000}Welcome back !\n{0066CC}Thank you because you are playing again on our server !\n{FFFF00}To can play, please input your{FF0000} password {FF0000}below!", "Login", "Exit"); //  // Showin' Login Dialog !
    }  // Closing brackelet !
    return 1;  // to show we finished 
}  // Closing brackelet !
6. --> Then we need to go under :
[CODE][CODE]
Code:
public OnPlayerDisconnect(playerid, reason)
{
And add :
Code:
    new name[MAX_PLAYER_NAME], file[256]; // New name --> Player's name, file --> .ini player's file !
    GetPlayerName(playerid, name, sizeof(name)); // Will get player's name ! 
    format(file, sizeof(file), PATH, name); // Will search about his .ini file !
    if(gPlayerLogged[playerid] == 1) // if player it's logged !
    { // Open brackelet ! 
        dini_IntSet(file, "Score", PlayerInfo[playerid][pScore]); // His Score
        dini_IntSet(file, "Money", PlayerInfo[playerid][pCash]); // His Cash
        dini_IntSet(file, "Admin",PlayerInfo[playerid][pAdmin]); // His Admin
        dini_IntSet(file, "pVip",PlayerInfo[playerid][pVip]); // His Vip
        dini_IntSet(file, "Kills",PlayerInfo[playerid][pKills]); // His Kills
        dini_IntSet(file, "Deaths",PlayerInfo[playerid][pDeaths]); // His Deaths
    } // Closing brackelet
    gPlayerLogged[playerid] = 0; // He aren't login = 0 !
	return 1; // Finish OnPlayerDissconect
} // Closing Latest brackelet !
7. --> Now, we need to go under :
Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
--> To finish Register/Login Dialog !
--> So, we add:

--> FOR REGISTER DIALOG :
Code:
if (dialogid == 1) // First Dialog (Register Dialog)
    {  // Open brackelet!
        new name[MAX_PLAYER_NAME], file[256], string[128]; // his name, .ini file, string
        GetPlayerName(playerid, name, sizeof(name));  // Will get player's name !
        format(file, sizeof(file), PATH, name);  // Search about .ini file name !
        if(!response) return Kick(playerid);  // If he hit Exit, will get kicked !
        if (!strlen(inputtext)) return  // What Password he will write in box !
        ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "-->{FF0000}Register {0066CC}Account", "{FF0000}Welcome, you are not registered!\n{0066CC}Enter your password below to can save your {FFFF00}Cash,Score {0066CC}Admin/Vip!", "Register", "Exit");  // Register Dialog !
        dini_Create(file);  // Dini will create .ini file for that player !
        dini_IntSet(file, "Password", udb_hash(inputtext));  // Will save his password ! He can login again just with his password !
        dini_IntSet(file, "AdminLevel",PlayerInfo[playerid][pAdmin] = 0);  // Will save his Admin (0 now)
        dini_IntSet(file, "Money",PlayerInfo[playerid][pCash] = 500);  // Will save his money, will be spawned with 500 $ !
        dini_IntSet(file, "Score",PlayerInfo[playerid][pScore] = 1);  // Will save his score, when he will be spawned with 1 Score !
        dini_IntSet(file, "Kills",PlayerInfo[playerid][pKills] = 0);
        dini_IntSet(file, "Deaths",PlayerInfo[playerid][pDeaths] = 0);
        format(string, 128, "{FF0000}[--> Succesfully <--]: {FFFF00}%s {0066CC} you have been succesfully registered!", name, inputtext);  // Chat Message !
        SendClientMessage(playerid, -1, string);  // Will put this message on registered player's chat!
		gPlayerLogged[playerid] = 1;  // Now, he is Auto-Logged (he don't need to put again his password, only if he exit and enter again on server !)
    }  // Closing Brackelet
--> FOR LOGIN DIALOG :

Code:
if (dialogid == 2) // Dialog 2 (Login Dialog)
    { // Open brackelet
        new name[MAX_PLAYER_NAME], file[256], string[128]; // player's name, .ini file, string
        GetPlayerName(playerid, name, sizeof(name)); // Will get player's name !
        format(file, sizeof(file), PATH, name); // Search about .ini file from that player !
        if(!response) return Kick(playerid); // If he hit Exit he will be kicked !
        if (!strlen(inputtext)) return ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "-->{FF0000}Login {0066CC}Account", "{FF0000}Welcome back !\n{0066CC}Thank you because you are playing again on our server !\n{FFFF00}To can play, please input your{FF0000} password {FF0000}below!", "Login", "Exit"); // Our Login Dialog !
        new tmp; // Variable !
        tmp = dini_Int(file, "Password"); // Password !
        if(udb_hash(inputtext) != tmp) // In that box if he don't put correct password from .ini file then :
       { // Open Brackelet 
            SendClientMessage(playerid, -1, "{FF0000}Wrong password! {0066CC}Try another one !"); // He will cannot login !
            ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "-->{FF0000}Login {0066CC}Account", "{FF0000}Welcome back !\n{0066CC}Thank you because you are playing again on our server !\n{FFFF00}To can player, please input your{FF0000}password {FF0000}below!", "Login", "Exit"); // And if his password it's wrong he will saw again our Login Dialog, to try again log in !
        } // Closin brackelet !
        else // Else
        { // Open brackelet !
            gPlayerLogged[playerid] = 1; // 1 = He it's logged !
            PlayerInfo[playerid][pAdmin] = dini_Int(file, "AdminLevel"); // If he have Admin, in .ini file will load his Admin before login !
            SetPlayerScore(playerid, PlayerInfo[playerid][pScore]); // Will sets his score from last time , from .ini file !
            GivePlayerMoney(playerid, dini_Int(file, "Money")-GetPlayerMoney(playerid)); // He will get money from last time, from .ini file !
            SendClientMessage(playerid, -1, "{FF0000}[--> Succesfully <--]: {0066CC}You have been {FFFF00}successfully {0066CC}logged in!"); // This he will saw after Login !
        } // Closing brackelet *1 !
    } // Closing brackelet *2!
} // Closing latest brackele *2!
All Code:
Code:
#include <a_samp>
#include <dini>
#include <dudb>

enum pInfo
{
    pAdmin,
	pVip,
	pCash,
    pScore,
    pKills,
    pDeaths,
}
new PlayerInfo[MAX_PLAYERS][pInfo];
new gPlayerLogged[MAX_PLAYERS];


#define PATH "/Users/%s.ini"

#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
	print("\n--------------------------------------");
	print("       *LOGIN/REGISTER SGYSTEM          ");
	print("--------------------------------------\n");
	return 1;
}

#else
#endif

public OnGameModeInit()
{
	SetGameModeText("H_System");
	AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
	return 1;
}

public OnGameModeExit()
{
	return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
	SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
	SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
	SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
	return 1;
}
public OnPlayerConnect(playerid)
{
    gPlayerLogged[playerid] = 0;
    new name[MAX_PLAYER_NAME], file[256];
    GetPlayerName(playerid, name, sizeof(name));
    format(file, sizeof(file), PATH, name);
    if (!dini_Exists(file))
    {
        ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "-->{FF0000}Register {0066CC}Account", "{FF0000}Welcome, you are not registered!\n{0066CC}Enter your password below to can save your {FFFF00}Cash,Score {0066CC}Admin/Vip!", "Register", "Exit");
    }
    if(fexist(file))
    {
        ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "-->{FF0000}Login {0066CC}Account", "{FF0000}Welcome back !\n{0066CC}Thank you because you are playing again on our server !\n{FFFF00}To can play, please input your{FF0000} password {FF0000}below!", "Login", "Exit");
    }
	return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new name[MAX_PLAYER_NAME], file[256];
    GetPlayerName(playerid, name, sizeof(name));
    format(file, sizeof(file), PATH, name);
    if(gPlayerLogged[playerid] == 1)
    {
        dini_IntSet(file, "Score", PlayerInfo[playerid][pScore]);
        dini_IntSet(file, "Money", PlayerInfo[playerid][pCash]);
        dini_IntSet(file, "Admin",PlayerInfo[playerid][pAdmin]);
        dini_IntSet(file, "pVip",PlayerInfo[playerid][pVip]);
        dini_IntSet(file, "Kills",PlayerInfo[playerid][pKills]);
        dini_IntSet(file, "Deaths",PlayerInfo[playerid][pDeaths]);
    }
    gPlayerLogged[playerid] = 0;
	return 1;
}

public OnPlayerText(playerid, text[])
{
	return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if (dialogid == 1)
    {
        new name[MAX_PLAYER_NAME], file[256], string[128];
        GetPlayerName(playerid, name, sizeof(name));
        format(file, sizeof(file), PATH, name);
        if(!response) return Kick(playerid);
        if (!strlen(inputtext)) return
        ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "-->{FF0000}Register {0066CC}Account", "{FF0000}Welcome, you are not registered!\n{0066CC}Enter your password below to can save your {FFFF00}Cash,Score {0066CC}Admin/Vip!", "Register", "Exit");
        dini_Create(file);
        dini_IntSet(file, "Password", udb_hash(inputtext));
        dini_IntSet(file, "AdminLevel",PlayerInfo[playerid][pAdmin] = 0);
        dini_IntSet(file, "Money",PlayerInfo[playerid][pCash] = 500);
        dini_IntSet(file, "Score",PlayerInfo[playerid][pScore] = 0);
        dini_IntSet(file, "Kills",PlayerInfo[playerid][pKills] = 0);
        dini_IntSet(file, "Deaths",PlayerInfo[playerid][pDeaths] = 0);
        format(string, 128, "{FF0000}[--> Succesfully <--]: {FFFF00}%s {0066CC} you have been succesfully registered!", name, inputtext);
        SendClientMessage(playerid, -1, string);
        ShowPlayerDialog(playerid, 3, DIALOG_STYLE_MSGBOX, "{FF0000}IMPORTANT!", "{FF0000}*NOTE:{0066CC}Thanks because you have registered on our server !\n{FFFF00}We hope you will enjoy him and our Staff wish you {0066CC}welcome ! :)","Exit", "");
		gPlayerLogged[playerid] = 1;
    }
    if (dialogid == 2)
    {
        new name[MAX_PLAYER_NAME], file[256], string[128];
        GetPlayerName(playerid, name, sizeof(name));
        format(file, sizeof(file), PATH, name);
        if(!response) return Kick(playerid);
        if (!strlen(inputtext)) return ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Hi your registered", "Fucken awesome mate, your registered :D. Inpute your pw below", "Login", "Leave");
        new tmp;
        tmp = dini_Int(file, "Password");
        if(udb_hash(inputtext) != tmp) {
            SendClientMessage(playerid, -1, "{FF0000}Wrong password! {0066CC}Try another one !");
            ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "-->{FF0000}Login {0066CC}Account", "{FF0000}Welcome back !\n{0066CC}Thank you because you are playing again on our server !\n{FFFF00}To can player, please input your{FF0000}password {FF0000}below!", "Login", "Exit");
        }
        else
        {
            gPlayerLogged[playerid] = 1;
            PlayerInfo[playerid][pAdmin] = dini_Int(file, "AdminLevel");
            SetPlayerScore(playerid, PlayerInfo[playerid][pScore]);
            GivePlayerMoney(playerid, dini_Int(file, "Money")-GetPlayerMoney(playerid));
            SendClientMessage(playerid, -1, "{FF0000}[--> Succesfully <--]: {0066CC}You have been {FFFF00}successfully {0066CC}logged in!");
        }
    }
	return 1;
}
Last Words:
--> I explained to all can understand !
--> If I made a mistake, tell me !
--> Cheers! <--

Bugs:
*Tested Code:
--> This code (Login/Register Dialog) was tested and no bugs, it's workin' fine !
--> If you find an bug, tell me, I will solve them !



Preview:







Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)