[Tutorial] Dialog Register/Login System using DJson
#1

Hello. It's my 2nd tutorial and I want to show you how to make register/login system using DJson. I know there's a lot of Tutorials like this, but i want to leave something other than Offtop on this forum
We'll need:
DJson by DracoBlue
dudb by Dracoblue

We'll begin with defining dialog IDs and color. So at top of your script we should put:
pawn Код:
#include <a_samp>
#include <djson>
#include <dudb>
#define COLOR_WHITE             0xFFFFFFFF
#define DIALOG_REGISTER         1
#define DIALOG_LOGIN            2
I think everyone who looks at this topic knows what above lines do
Now lets head to OnGameModeInit()
pawn Код:
new str[128], accname[128];
format(accname, sizeof(accname), "Accounts/%s", GetPlayerName(playerid));
    if(!fexist(accname))
    {
        format(str, 128, "{FFFFFF}Welcome {FBFF00}%s \n\n{FFFFFF}Please Register!", GetName(playerid));
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Registration", str, "Register", "Quit");
    }
    if(fexist(accname))
    {
        format(str, 128, "{FFFFFF}Welcome\nAccount {FBFF00} %s\n{FFFFFF}Please Log In!", GetName(playerid));
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Log In!", str, "Login", "Quit");
    }
Now let me explain lines, that may confuse you
format(accname, sizeof(accname), "%s", GetName(playerid)); - Allows us to read data from "Accounts" folder.
if(!fexist(accname)) - Checks if there's no player file with that name already.
Rest should be pretty simple to understand

Now lets take care of dialogs. It's the most important part of the script!

Just under OnDialogResponse put this code!
pawn Код:
new accname[128], str[128];
format(accname, sizeof(accname), "Accoutns/%s", GetPlayerName(playerid));
if(dialogid == DIALOG_REGISTER)
    {
        if(!response) return Kick(playerid);
        if(response)
        {
            if(strlen(inputtext) == 0)
            {
                format(str, 128, "{FFFFFF}Welcome {FBFF00}%s \n\n{FFFFFF}Please Register!", GetName(playerid));
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Registration", str, "Register",
                return 0;
            }
            if(!fexist(accname))
            {
                djCreateFile(accname);
                djSetInt(accname,"player/password",udb_hash(inputtext),false);
                djCommit(accname);
                                format(str, 128, "{FFFFFF}Welcome\nAccount {FBFF00} %s\n{FFFFFF}Please Log In!", GetName(playerid));
                        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Log In!", str, "Login", "Quit");
            }
        }
    }
This one was for registration. I'll explain some lines.
if(!response) return Kick(playerid); - If player selects "Quit" it will kick this player.
if(strlen(inputtext) == 0) - This checks if player left the password input place blank.
djCreateFile(accname); - It creates player file in your "Accounts" folder
djSetInt(accname,"Data/Password",udb_hash(inputtext),false); - It sets the password and hashes it so noone can read it!
djCommit(accname); - This line commits changes made to the player file.

Now let's make loging in! Put this code under your register dialog
pawn Код:
if(dialogid == DIALOG_LOGIN)
    {
        if(!response) return Kick(playerid);
        if(response)
        {
            if(strlen(inputtext) == 0)
            {
                format(str, 128, "{FFFFFF}Welcome\nAccount {FBFF00} %s\n{FFFFFF}Please Log In!", GetName(playerid));
                ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Log In!", str, "Login", "Quit");
                return 0;
            }
            if(fexist(accname))
            {
                new password = djInt(accname,"player/password");
                if(udb_hash(inputtext) != password)
                {
                    format(str, 128, "{FFFFFF}Welcome\nAccount {FBFF00} %s\n{FFFFFF}Please Log In!", GetName(playerid));
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Log In!", str, "Login", "Quit");
                }
                else
                {
                    SendClientMessage(playerid, colorGreen, "You have successfully logged in.");
                    SpawnPlayer(playerid);
                    //Put here for example restoring player money after reloging :D
                }
            }
        }
    }
    return 1;
}
I don't have to explain anything here, because i explained it before.
And that's all, you can enjoy your register/login system!
Reply
#2

Why Didnt you use Y_ini? its faster, and easier to use.
Reply
#3

Hello, i just got this error?


C:\Users\vMikkelReimer\Desktop\SaC\gamemodes\SaC v0,2.pwn(36) : fatal error 100: cannot read from file: "djson"

Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


1 Error.
Reply
#4

Quote:
Originally Posted by Mikkel_RE
Посмотреть сообщение
Hello, i just got this error?


C:\Users\vMikkelReimer\Desktop\SaC\gamemodes\SaC v0,2.pwn(36) : fatal error 100: cannot read from file: "djson"

Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


1 Error.
Download DJSon, and place it in you pawn/include Folder.
Reply
#5

give me djson link
Reply
#6

Yea, can you send me a link?
Reply
#7

Here you go:

http://forum.sa-mp.com/showthread.ph...ighlight=djson
Reply
#8

tutorial missing stuff, OnGameModeInit() doesn't use playerid and about that GetName, sould i define it? This tutorial needs to be more detailed i guess.
Reply
#9

It tells me to get Dini Dutils and all that? :/
Reply
#10

Urmm? ;/?


Код:
C:\Documents and Settings\Administrator\Desktop\Stunt Server\gamemodes\stuntage101.pwn(45) : warning 225: unreachable code
C:\Documents and Settings\Administrator\Desktop\Stunt Server\gamemodes\stuntage101.pwn(46) : error 017: undefined symbol "playerid"
C:\Documents and Settings\Administrator\Desktop\Stunt Server\gamemodes\stuntage101.pwn(49) : error 017: undefined symbol "GetName"
C:\Documents and Settings\Administrator\Desktop\Stunt Server\gamemodes\stuntage101.pwn(50) : error 017: undefined symbol "playerid"
C:\Documents and Settings\Administrator\Desktop\Stunt Server\gamemodes\stuntage101.pwn(54) : error 017: undefined symbol "GetName"
C:\Documents and Settings\Administrator\Desktop\Stunt Server\gamemodes\stuntage101.pwn(55) : error 017: undefined symbol "playerid"
C:\Documents and Settings\Administrator\Desktop\Stunt Server\gamemodes\stuntage101.pwn(245) : warning 202: number of arguments does not match definition
C:\Documents and Settings\Administrator\Desktop\Stunt Server\gamemodes\stuntage101.pwn(245) : warning 202: number of arguments does not match definition
C:\Documents and Settings\Administrator\Desktop\Stunt Server\gamemodes\stuntage101.pwn(254) : error 017: undefined symbol "GetName"
C:\Documents and Settings\Administrator\Desktop\Stunt Server\gamemodes\stuntage101.pwn(255 -- 256) : error 029: invalid expression, assumed zero
C:\Documents and Settings\Administrator\Desktop\Stunt Server\gamemodes\stuntage101.pwn(256) : warning 215: expression has no effect
C:\Documents and Settings\Administrator\Desktop\Stunt Server\gamemodes\stuntage101.pwn(263) : error 017: undefined symbol "GetName"
C:\Documents and Settings\Administrator\Desktop\Stunt Server\gamemodes\stuntage101.pwn(275) : warning 203: symbol is never used: "djson_GameModeExit"
C:\Documents and Settings\Administrator\Desktop\Stunt Server\gamemodes\stuntage101.pwn(275) : warning 203: symbol is never used: "djson_GameModeInit"
C:\Documents and Settings\Administrator\Desktop\Stunt Server\gamemodes\stuntage101.pwn(275) : warning 203: symbol is never used: "ret_memcpy"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


8 Errors.
Reply
#11

Quote:
Originally Posted by DreaD
View Post
Urmm? ;/?


Code:
C:\Documents and Settings\Administrator\Desktop\Stunt Server\gamemodes\stuntage101.pwn(45) : warning 225: unreachable code
C:\Documents and Settings\Administrator\Desktop\Stunt Server\gamemodes\stuntage101.pwn(46) : error 017: undefined symbol "playerid"
C:\Documents and Settings\Administrator\Desktop\Stunt Server\gamemodes\stuntage101.pwn(49) : error 017: undefined symbol "GetName"
C:\Documents and Settings\Administrator\Desktop\Stunt Server\gamemodes\stuntage101.pwn(50) : error 017: undefined symbol "playerid"
C:\Documents and Settings\Administrator\Desktop\Stunt Server\gamemodes\stuntage101.pwn(54) : error 017: undefined symbol "GetName"
C:\Documents and Settings\Administrator\Desktop\Stunt Server\gamemodes\stuntage101.pwn(55) : error 017: undefined symbol "playerid"
C:\Documents and Settings\Administrator\Desktop\Stunt Server\gamemodes\stuntage101.pwn(245) : warning 202: number of arguments does not match definition
C:\Documents and Settings\Administrator\Desktop\Stunt Server\gamemodes\stuntage101.pwn(245) : warning 202: number of arguments does not match definition
C:\Documents and Settings\Administrator\Desktop\Stunt Server\gamemodes\stuntage101.pwn(254) : error 017: undefined symbol "GetName"
C:\Documents and Settings\Administrator\Desktop\Stunt Server\gamemodes\stuntage101.pwn(255 -- 256) : error 029: invalid expression, assumed zero
C:\Documents and Settings\Administrator\Desktop\Stunt Server\gamemodes\stuntage101.pwn(256) : warning 215: expression has no effect
C:\Documents and Settings\Administrator\Desktop\Stunt Server\gamemodes\stuntage101.pwn(263) : error 017: undefined symbol "GetName"
C:\Documents and Settings\Administrator\Desktop\Stunt Server\gamemodes\stuntage101.pwn(275) : warning 203: symbol is never used: "djson_GameModeExit"
C:\Documents and Settings\Administrator\Desktop\Stunt Server\gamemodes\stuntage101.pwn(275) : warning 203: symbol is never used: "djson_GameModeInit"
C:\Documents and Settings\Administrator\Desktop\Stunt Server\gamemodes\stuntage101.pwn(275) : warning 203: symbol is never used: "ret_memcpy"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


8 Errors.
Its because on OnGameModInt haven't been defined playerid and there are not defined GetName. Like i said this tutorial misses alot of explaining, lets hope that tutorial maker will add more info.
Reply
#12

i get almost 100 errors... Im newbie
Reply
#13

Where can i find this: OnDialogResponse hurry i need it now.
Reply
#14

What the hell dude??
Define stuff, this tut is missing some stuff, and how can you get "playerid" in "OnGameModeInit()"
Please update this tut.

Tnx
Reply
#15

Quote:
Originally Posted by RiChArD_A
View Post
Where can i find this: OnDialogResponse hurry i need it now.
...

your reputation explains it all

anyways if you don't have a
Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
in your gamemode you can copy that and put your code in the braces.
Reply
#16

I made a complete Registering, Loading, Saving and Logging in system by myself...
and it looks nothing like this dumb tut.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)