[Tutorial] How to make a register system - DIALOG
#1

New tutorial, now using up-to-date methods!

It's strongly suggested that everyone takes a look at this tutorial, help will be ignored and so will the thread be locked. The tutorial is clearly out-dated.

________________________________________

Register system in Dialog
By Lorenc

So what is this?
Its a tutorial about how to make a register system in dialog. I made this because i found one which was abit faulty and to be honest in my opinion it was crap. In this tutorial I will explain most of it.

Starting
Ok in order to make this we will need 2 includes. Dini & Dudb.
pawn Code:
#include <dini>
#include <dudb>
So just hit compile and you might get a warning like:
pawn Code:
warning 203: symbol is never used: "ret_memcpy"
To prevent that warning just insert this code to the top of your script:
pawn Code:
#pragma unused ret_memcpy
^ what that does is that it tells the script that it will be unused for this moment

Scripting
Great we're on the 2nd step now! so we got our Dudb & Dini working, lets get ready for the real scripting .
pawn Code:
enum pInfo
{
    pAdminLevel,
    pCash,
    pScore,
}
new PlayerInfo[MAX_PLAYERS][pInfo];
^ What in the hell is that? It's an enum that stores things into one variable

You might get one warning but tho it will be gone throughout scripting.

Next we will need to make gPlayerLogged, that means if the player is logged or not.
pawn Code:
new gPlayerLogged[MAX_PLAYERS];
and the last define is the userfile, where the userfile will be.
pawn Code:
#define SERVER_USER_FILE "myserver/%s.ini"
___

Lets move to the onplayer connect callback
Add these codes to the call back.
pawn Code:
gPlayerLogged[playerid] = 0;
    new name[MAX_PLAYER_NAME], file[256];
    GetPlayerName(playerid, name, sizeof(name));
    format(file, sizeof(file), SERVER_USER_FILE, name);
    if (!dini_Exists(file))
    {
        ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Hi your not registered", "Welcome, your not registered mate, input your registration pw below", "Register", "Leave");
    }
    if(fexist(file))
    {
        ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Hi your registered", "Fucken awesome mate, your registered :D. Inpute your pw below", "Login", "Leave");
    }
^ what this does is that you connects you as a not logged in person and shows a dialog for if your logged or not logged.

next we have to go to the OnPlayerDisconnect Callback and put:
pawn Code:
new name[MAX_PLAYER_NAME], file[256];
    GetPlayerName(playerid, name, sizeof(name));
    format(file, sizeof(file), SERVER_USER_FILE, name);
    if(gPlayerLogged[playerid] == 1)
    {
        dini_IntSet(file, "Score", PlayerInfo[playerid][pScore]);
        dini_IntSet(file, "Money", PlayerInfo[playerid][pCash]);
        dini_IntSet(file, "AdminLevel",PlayerInfo[playerid][pAdminLevel]);
    }
    gPlayerLogged[playerid] = 0;
^What that will do for us is save our new status in-game plus it logs you out.

Dialogs
We are up to making to dialogs configure now!
so lets start off with the register dialog.

Navigate to OnDialogResponse which is at the bottom of the script usally and add this code.
pawn Code:
if (dialogid == 1)
    {
        new name[MAX_PLAYER_NAME], file[256], string[128];
        GetPlayerName(playerid, name, sizeof(name));
        format(file, sizeof(file), SERVER_USER_FILE, name);
        if(!response) return Kick(playerid);
        if (!strlen(inputtext)) return
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Hi your not registered", "Welcome, your not registered mate, input your registration pw below", "Register", "Leave");
        dini_Create(file);
        dini_IntSet(file, "Password", udb_hash(inputtext));
        dini_IntSet(file, "AdminLevel",PlayerInfo[playerid][pAdminLevel] = 0);
        dini_IntSet(file, "Money",PlayerInfo[playerid][pCash] = 500);
        dini_IntSet(file, "Score",PlayerInfo[playerid][pScore] = 0);
        format(string, 128, "[SYSTEM]: You succesfully registered the nickname %s with password %s, you have been auto logged in.", name, inputtext);
        SendClientMessage(playerid, COLOR_YELLOW, string);
        gPlayerLogged[playerid] = 1;
    }
^ That configures the dialog we've got for the register

Now lets press enter at the end of the dialog 1 (register). Below it paste:

pawn Code:
if (dialogid == 2)
    {
        new name[MAX_PLAYER_NAME], file[256], string[128];
        GetPlayerName(playerid, name, sizeof(name));
        format(file, sizeof(file), SERVER_USER_FILE, 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, COLOR_RED, "Wrong PW sir.");
            ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Hi your registered", "Fucken awesome mate, your registered :D. Inpute your pw below", "Login", "Leave");
        }
        else
        {
            gPlayerLogged[playerid] = 1;
            PlayerInfo[playerid][pAdminLevel] = dini_Int(file, "AdminLevel");
            SetPlayerScore(playerid, PlayerInfo[playerid][pScore]);
            GivePlayerMoney(playerid, dini_Int(file, "Money")-GetPlayerMoney(playerid));
            SendClientMessage(playerid,COLOR_RED, "[SYSTEM]: Successfully logged in!");
        }
    }
^ That configures the dialog we've got for the login

Summary
There you go you've just got a dialog reg/log system. You can now claim it as yours and edit it. Well done. Please note if i made a lil error tell me, i was acctaully trying to get the codes outta my gm. I hope i didnt fail something. If i did, tell me ill fix it.

Credits
Lorenc - Mostly creating TUT & Script parts.
-Rebel Son- - Got some codes off him.
Dracoblue - DINI & Dudb
SAMP for their new gui.


Download for the pwn
http://pastebin.com/Ygy5z1d8

Bugs bugs bugs, tell me if there is one, ill try my hardest to fix it. If i made mistakes in this tut tell me soz for awful english
Reply
#2

For the saving part, I suggest you to use "if(gPlayerLogged[playerid] == 1)", instead of "if(fexists(file)), so the account won't save when somebody else then the original player joins the server under that name.
Reply
#3

Quote:
Originally Posted by Hiddos
View Post
For the saving part, I suggest you to use "if(gPlayerLogged[playerid] == 1)", instead of "if(fexists(file)), so the account won't save when somebody else then the original player joins the server under that name.
Ok thanks, just edited
Reply
#4

More detail would be better :X
Reply
#5

Nice tutorial
Reply
#6

Stats don't save please help
Reply
#7

Quote:
Originally Posted by EllipseRage
View Post
More detail would be better :X
Yeh sorry about that, kind of in a rush lols

Quote:
Originally Posted by Mimic
Nice tutorial
Thanks
Reply
#8

Quote:
Originally Posted by Hor1z0n
View Post
Stats don't save please help
Sorry for this awful double post

You sure you've added the stuff on onplayerdisconnect, else if you did

Quote:
Originally Posted by Hiddos
For the saving part, I suggest you to use "if(gPlayerLogged[playerid] == 1)", instead of "if(fexists(file)), so the account won't save when somebody else then the original player joins the server under that name.
I followed him.

Admin scripts might disturb its saving.
Reply
#9

This is my OnPlayerDisconect

Code:
public OnPlayerDisconnect(playerid, reason)
{
    //--------------------------------------------------------------------------
    new String[128];
    new PName[MAX_PLAYER_NAME];
	new name[MAX_PLAYER_NAME], file[256];
    GetPlayerName(playerid, name, sizeof(name));
    format(file, sizeof(file), SERVER_USER_FILE, name);
   	if(gPlayerLogged[playerid] == 1)
    {
        dini_IntSet(file, "Score", PlayerInfo[playerid][pScore]);
        dini_IntSet(file, "Money", PlayerInfo[playerid][pCash]);
        dini_IntSet(file, "AdminLevel",PlayerInfo[playerid][pAdminLevel]);
    }
    gPlayerLogged[playerid] = 0;
    
 	switch(reason)
    {
        case 0: format(String, sizeof(String), "%s a lost the connection with server(Crash).", PName);
        case 1: format(String, sizeof(String), "%s quit the server(Quit).", PName);
        case 2: format(String, sizeof(String), "%s quit the server. (Kicked)", PName);
    }
	return 1;
}
Reply
#10

Quote:
Originally Posted by Hor1z0n
View Post
Stats don't save please help
Have you created the "myserver" directory in your scriptfiles folder?
Reply
#11

Quote:
Originally Posted by Hiddos
View Post
Have you created the "myserver" directory in your scriptfiles folder?
Yus just wat i was gunna say
Reply
#12

yes,i created the directory
Reply
#13

Ok, try
pawn Code:
if(dini_Exists(file))
instead of your current. If it dont work idk because it does for me..
Reply
#14

It woulda crashed when he tried to save a file in a incorrect directory.
Reply
#15

Quote:
Originally Posted by Lorenc_
View Post
Ok, try
pawn Code:
if(dini_Exists(file))
instead of your current. If it dont work idk because it does for me..
where to put that code
Reply
#16

Quote:
Originally Posted by Hor1z0n
View Post
where to put that code
Onplayerdisconnect. Replace it with gPlayerLogged
Reply
#17

can you leave here your yahoo id or something to chat ?
Reply
#18

For the second dialogid check, you do not need the string[128]... since it is not used :P
Reply
#19

How would you make a register system like this if you had MySQL?
Reply
#20

Great tutorial but mine doesnt work.... i got all the right things its just it doesnt create the file or display that i have registered etc..... it does show the register dialog but it doesnt work :S i can login once :S,here is my script:

pawn Code:
// This is a comment
// uncomment the line below if you want to write a filterscript
#define FILTERSCRIPT

#include <a_samp>
//#include <strtok>
#include <dini>
#include <dudb>
#pragma unused ret_memcpy
#define SERVER_USER_FILE "cslogin/users/%s.ini"
#define COLOR_RED 0xFFF0000FF
#define COLOR_BLUE 0x0000BBAA
#define COLOR_YELLOW 0xFFFF00AA


#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Blank Filterscript by your name here");
    print("--------------------------------------\n");
    return 1;
}

public OnFilterScriptExit()
{
    return 1;
}

#else

main()
{
    print("\n----------------------------------");
    print(" Blank Gamemode by your name here");
    print("----------------------------------\n");
}

#endif
enum pInfo
{
 pAdminLevel,
 pScore,
 pCash,
};
new PlayerInfo [MAX_PLAYERS] [pInfo];
new gPlayerLogged[MAX_PLAYERS];

public OnGameModeInit()
{
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    return 1;
}

public OnPlayerConnect(playerid)
{
    gPlayerLogged[playerid] = 0;
    new name[MAX_PLAYERS],file[128];
    GetPlayerName(playerid,name,sizeof(name));
    format(file,sizeof(file),SERVER_USER_FILE,name);
    if(!dini_Exists(file))
    {
        ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Welcome You are not registered!","You are not registered\nplease register now!","Register","Cancel");
    }
    if(fexist(file))
    {
        ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"Your registered!","Welcome back :P\nPlease sign-in below:","Login","Cancel");
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new name[MAX_PLAYERS],file[128];
    GetPlayerName(playerid,name,sizeof(name));
    format(file,sizeof(file),SERVER_USER_FILE,name);
    if(gPlayerLogged[playerid] == 1)
    {
        dini_IntSet(file,"AdminLevel",PlayerInfo[playerid] [pAdminLevel]);
        dini_IntSet(file,"Score",PlayerInfo[playerid] [pScore]);
        dini_IntSet(file,"Cash",PlayerInfo[playerid] [pCash]);
    }
    gPlayerLogged[playerid] = 0;
    return 1;
}

public OnPlayerSpawn(playerid)
{
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    return 1;
}

public OnVehicleSpawn(vehicleid)
{
    return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
    return 1;
}

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

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/mycommand", cmdtext, true, 10) == 0)
    {
        // Do something here
        return 1;
    }
    return 0;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
    return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
    return 1;
}

public OnRconCommand(cmd[])
{
    return 1;
}

public OnPlayerRequestSpawn(playerid)
{
    return 1;
}

public OnObjectMoved(objectid)
{
    return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
    return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
    return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
    return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
    return 1;
}

public OnPlayerExitedMenu(playerid)
{
    return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
    return 1;
}

public OnPlayerUpdate(playerid)
{
    return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
    return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
    return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
    return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == 1)
    {
        new name[MAX_PLAYER_NAME], file[128], string[128];
        GetPlayerName(playerid, name, sizeof(name));
        format(file, sizeof(file), SERVER_USER_FILE, name);
        if(!response)return Kick(playerid);
        if(!strlen(inputtext))return ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Welcome You are not registered!","You are not registered\nplease register now!","Register","Cancel");
        {
            dini_Create(file);
            dini_IntSet(file,"Password",udb_hash(inputtext));
            dini_IntSet(file,"AdminLevel",PlayerInfo[playerid] [pAdminLevel] = 0);
            dini_IntSet(file,"Score",PlayerInfo[playerid] [pScore] = 0);
            dini_IntSet(file,"Cash",PlayerInfo[playerid] [pCash] = 100);
            format(string,sizeof(string),"[LoginSys]: You succesfully registered the name %s with password %s, you have been auto logged in.",name,inputtext);
            SendClientMessage(playerid, COLOR_YELLOW, string);
            gPlayerLogged[playerid] = 1;
        }
    }
    if(dialogid == 2)
    {
        new name[MAX_PLAYER_NAME], file[128];
        GetPlayerName(playerid, name, sizeof(name));
        format(file, sizeof(file), SERVER_USER_FILE, name);
        if(!response) return Kick(playerid);
        if(!strlen(inputtext))return ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"Your registered!","Welcome back :P\nPlease sign-in below:","Login","Cancel");
        new tmp;
        tmp = dini_Int(file,"Password");
        if(udb_hash(inputtext) != tmp)
        {
            SendClientMessage(playerid,COLOR_RED,"Sorry Wrong Password!");
            ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"Your registered!","Welcome back :P\nPlease sign-in below:","Login","Cancel");
        }
        else
        {
        gPlayerLogged[playerid] = 1;
        PlayerInfo[playerid] [pAdminLevel] = dini_Int(file,"AdminLevel");
        SetPlayerScore(playerid,PlayerInfo[playerid] [pScore]);
        GivePlayerMoney(playerid,dini_Int(file,"Cash")-GetPlayerMoney(playerid));
        SendClientMessage(playerid,COLOR_BLUE,"[LoginSys]: Successfully Logged In!");
        }
    }
       
    return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)