SA-MP Forums Archive
[Tutorial] Dialog Register/Login System using DJson - 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] Dialog Register/Login System using DJson (/showthread.php?tid=213602)



Dialog Register/Login System using DJson - sekol - 19.01.2011

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!


Re: Dialog Register/Login System using DJson - Fool - 20.01.2011

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


Re: Dialog Register/Login System using DJson - Mikkel_RE - 20.01.2011

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.


Re: Dialog Register/Login System using DJson - Fool - 21.01.2011

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.


Re: Dialog Register/Login System using DJson - ilikenuts - 21.01.2011

give me djson link


Re: Dialog Register/Login System using DJson - Mikkel_RE - 21.01.2011

Yea, can you send me a link?


Re: Dialog Register/Login System using DJson - SAW-RL - 21.01.2011

Here you go:

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


Re: Dialog Register/Login System using DJson - tuuker - 05.03.2011

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.


Re: Dialog Register/Login System using DJson - DreaD - 06.03.2011

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


Re: Dialog Register/Login System using DJson - DreaD - 06.03.2011

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.



Re: Dialog Register/Login System using DJson - tuuker - 06.03.2011

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.


Re: Dialog Register/Login System using DJson - NeroX98 - 18.03.2012

i get almost 100 errors... Im newbie


Respuesta: Dialog Register/Login System using DJson - RiChArD_A - 20.09.2012

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


Re: Dialog Register/Login System using DJson - amirm3hdi - 28.04.2015

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


Re: Respuesta: Dialog Register/Login System using DJson - JaydenJason - 28.04.2015

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.


Re: Dialog Register/Login System using DJson - amirm3hdi - 28.04.2015

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