SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 03/01/2012, 01:38 PM   #1
#Pwn.
Little Clucker
 
#Pwn.'s Avatar
 
Join Date: Jan 2012
Location: Oberbayern
Posts: 31
Reputation: 3
Thumbs up Register & Login System with dini

Hello and welcome to my second Tutorial!

I want to show you today, how you can script a register and login system with dini!

So..Lets go!

At the top of the Script you make an include

Code:
#include <dini>
The second part is, we have to define the dialogues:

Code:
#define DIALOG_REGISTER1 0
#define DIALOG_REGISTER2 1
#define DIALOG_REGISTER3 2
#define DIALOG_REGISTER4 3
#define DIALOG_LOGIN1 4
#define DIALOG_NOPW1 5
#define DIALOG_NOPW2 6
#define DIALOG_WRONGPW 7
You have to adapt it to your script :3

Third Part, an enum :

Code:
enum Info
{
   sex, //0= male 1=female
   age, // age :3
   logged, // If is player connected
}
A variable, which managed the enum

Code:
new pInfo[MAX_PLAYERS][Info];
You have to make a new folder in /scriptfiles

I call this folder "spieler" ("spieler", because I am German :3 xD)

The Next Time, we check, if the Player is already registered or unregistered.
Under callback "OnPlayerConnect"

Code:
new pname[MAX_PLAYER_NAME], path[200];
GetPlayerName(playerid, pname, sizeof(pname));
format(path, sizeof(path), "/spieler/%s.ini", pname);

if(!dini_Exists(path))
{
   // f the player is not registered
   ShowPlayerDialog(playerid, DIALOG_REGISTER1, DIALOG_STYLE_INPUT, "Register", "Your Password:", "OK", "Cancel");
}
else
{
   //If the player is registered
   ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Your Password", "OK", "Cancel");
}
Now the Callback
Code:
OnDialogResponse
Code:
new pname[MAX_PLAYER_NAME], path[200];
GetPlayerName(playerid, pname, sizeof(pname));
format(path, sizeof(path), "/spieler/%s.ini", pname);

switch(dialogid)
{
   case DIALOG_REGISTER1:
   {
  	if(!response)
  	{
      	Kick(playerid);
  	}
  	else
  	{
     	new pwlength = strlen(inputtext);
     	if(pwlength > 0)
     	{
        	dini_Create(path); /i
        	dini_Set(path, "password", inputtext); 
        	ShowPlayerDialog(playerid, DIALOG_REGISTER2, DIALOG_STYLE_LIST, "male\r\female", "OK", "Cancel");
     	}
     	else
     	{
        	ShowPlayerDialog(playerid, DIALOG_NOPW1, DIALOG_STYLE_MSGBOX, "Register", "You have to enter a password!", "OK", "Cancel");
     	}
  	}
   }
   case DIALOG_REGISTER2:
   {
  	if(!response)
  	{
     	dini_Remove(path); 
     	Kick(playerid);
  	}
  	else
  	{
     	dini_IntSet(path, "sex", listitem); 
     	ShowPlayerDialog(playerid, DIALOG_REGISTER3, DIALOG_STYLE_INPUT, "Register", "Your Age?", "OK", "Cancel");
  	}
   }
   case DIALOG_REGISTER3:
   {
  	if(!response)
  	{
     	dini_Remove(path); 
      	Kick(playerid);
  	}
  	else
	  {
     	dini_Set(path, "age", inputtext);
     	ShowPlayerDialog(playerid, DIALOG_REGISTER4, DIALOG_STYLE_MSGBOX, "Register", "Your Register is complete!", "OK", "OK");
      }
   }
   case DIALOG_REGISTER4:
   {
  	pInfo[playerid][sex] = dini_Int(path, "sex");
  	pInfo[playerid][age] = dini_Int(path, "age");
  	pInfo[playerid][logged] = 1;
   }
   case DIALOG_LOGIN1:
   {
  	if(!response)
  	{
     	Kick(playerid);
  	}
  	else
  	{
     	new pwlength = strlen(inputtext);
     	if(pwlength > 0)
     	{
        	new pw[200];
        	format(pw, sizeof(pw), "%s", dini_Get(path, "password");
        	if(strcmp(inputtext, pw) == 0) 
        	{
           	pInfo[playerid][sex] = dini_Int(path, "sex");
           	pInfo[playerid][age] = dini_Int(path, "age");
           	pInfo[playerid][logged] = 1;
        	}
        	else
        	{
           	ShowPlayerDialog(playerid, DIALOG_WRONGPW, DIALOG_STYLE_MSGBOX, "Login", "Wrong Password!", "OK", "Cancel");
        	}
     	}
     	else
     	{
        	ShowPlayerDialog(playerid, DIALOG_NOPW2, DIALOG_STYLE_MSGBOX,  "Login", "SYou have to enter a password!", "OK", "Cancel");
     	}
  	}
   }
  case DIALOG_NOPW1: 
  {
 	if(!response)
 	{
    	Kick(playerid);
 	} 
 	else
 	{
    	ShowPlayerDialog(playerid, DIALOG_REGISTER1, DIALOG_STYLE_INPUT,  "Register", "Your Password", "OK",  "Cancel");
 	}
  }
  case DIALOG_NOPW2: 
  {
 	if(!response)
 	{
    	Kick(playerid);
 	} 
 	else
 	{
    	 ShowPlayerDialog(playerid, DIALOG_LOGIN1, DIALOG_STYLE_INPUT,   "Login", "Your Password:", "OK",   "Abbrechen");
 	}
  }
  case DIALOG_WRONGPW:
  {
 	if(!response)
 	{
    	Kick(playerid);
 	}
 	else
 	{
    	 ShowPlayerDialog(playerid, DIALOG_LOGIN1, DIALOG_STYLE_INPUT,    "Login", "Your Password:", "OK",   "Cancel");
 	}
  }
}
So now the player wouldn`t be saved, if he logged out!

We change it!

Callback
Code:
OnPlayerDisconnect
Code:
new pname[MAX_PLAYER_NAME], path[200];
GetPlayerName(playerid, pname, sizeof(pname));
format(path, sizeof(path), "/spieler/%s.ini", pname);

dini_IntSet(path, "sex", pInfo[playerid][sex]);
dini_IntSet(path, "age", pInfo[playerid][age]);

pInfo[playerid][logged] = 0;
Now you can expand the enum with Money,Skin or whatever!

Greets,

#Pwn.
__________________
#Pwn. what else?
Progress of [SAL]San Andreas Live

5%/100 %

HP: www.sal-roleplay.de

My Tutorials :
Yes, I am German :3
#Pwn. is offline   Reply With Quote
Old 03/01/2012, 01:44 PM   #2
#Pwn.
Little Clucker
 
#Pwn.'s Avatar
 
Join Date: Jan 2012
Location: Oberbayern
Posts: 31
Reputation: 3
Default Re: Register & Login System with dini

Dini download

http://dracoblue.net/download/dini-16/35/

Put it in :

/pawno/include
__________________
#Pwn. what else?
Progress of [SAL]San Andreas Live

5%/100 %

HP: www.sal-roleplay.de

My Tutorials :
Yes, I am German :3
#Pwn. is offline   Reply With Quote
Old 03/01/2012, 03:39 PM   #3
Littlehelper
Gangsta
 
Littlehelper's Avatar
 
Join Date: Nov 2011
Location: 420
Posts: 972
Reputation: 178
Default Re: Register & Login System with dini

You have not explained some parts.
However, nice.
__________________
Quote:
<Norsehawk> If pigs flew, we'd need stronger umbrellas
<Norsehawk> and if my cat shat gold, I would be rich...

Last edited by Littlehelper; 28/06/2012 at 03:57 PM.
Littlehelper is offline   Reply With Quote
Old 03/01/2012, 03:40 PM   #4
#Pwn.
Little Clucker
 
#Pwn.'s Avatar
 
Join Date: Jan 2012
Location: Oberbayern
Posts: 31
Reputation: 3
Default Re: Register & Login System with dini

Thanks man! (:
__________________
#Pwn. what else?
Progress of [SAL]San Andreas Live

5%/100 %

HP: www.sal-roleplay.de

My Tutorials :
Yes, I am German :3
#Pwn. is offline   Reply With Quote
Old 03/01/2012, 04:09 PM   #5
[DOG]irinel1996
High-roller
 
[DOG]irinel1996's Avatar
 
Join Date: Jan 2010
Location: Canary Islands, Spain
Posts: 1,626
Reputation: 213
Default Respuesta: Register & Login System with dini

Why so much dialogs, you can do it just with 2.
Anyway, good job.
I hate Dini. lol (MySQL rules! xD)
______________________
Best regards!
__________________
STELLA HOSTING
Coming Soon
[DOG]irinel1996 is offline   Reply With Quote
Old 03/01/2012, 04:12 PM   #6
#Pwn.
Little Clucker
 
#Pwn.'s Avatar
 
Join Date: Jan 2012
Location: Oberbayern
Posts: 31
Reputation: 3
Default Re: Register & Login System with dini

Well ...you can make it with 2 dialogs or with 7.

With 7. you know, which sex he has etc..

btw..:

Thanks (:
__________________
#Pwn. what else?
Progress of [SAL]San Andreas Live

5%/100 %

HP: www.sal-roleplay.de

My Tutorials :
Yes, I am German :3
#Pwn. is offline   Reply With Quote
Old 03/01/2012, 04:38 PM   #7
[DOG]irinel1996
High-roller
 
[DOG]irinel1996's Avatar
 
Join Date: Jan 2010
Location: Canary Islands, Spain
Posts: 1,626
Reputation: 213
Default Respuesta: Register & Login System with dini

You can make it with 1 too, hehehe... :O
__________________
STELLA HOSTING
Coming Soon
[DOG]irinel1996 is offline   Reply With Quote
Old 03/01/2012, 04:49 PM   #8
#Pwn.
Little Clucker
 
#Pwn.'s Avatar
 
Join Date: Jan 2012
Location: Oberbayern
Posts: 31
Reputation: 3
Default Re: Register & Login System with dini

Yes :O :3 but it`s for "newbies" harder :3
__________________
#Pwn. what else?
Progress of [SAL]San Andreas Live

5%/100 %

HP: www.sal-roleplay.de

My Tutorials :
Yes, I am German :3
#Pwn. is offline   Reply With Quote
Old 03/01/2012, 06:12 PM   #9
T0pAz
Guest
 
Posts: n/a
Default Re: Register & Login System with dini

Please do something different than usual. And also dINI is decrepit.
  Reply With Quote
Old 03/01/2012, 07:09 PM   #10
FireCat
Banned
 
Join Date: Jul 2010
Posts: 2,470
Reputation: 596
Default Re: Register & Login System with dini

How dare you use dini <.<
FireCat is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Register/login system problem using Dini sim_sima Help Archive 10 09/03/2011 04:53 PM
[FilterScript] Register/login system (Dini, dialogs) pantelimonfl Filterscripts 6 08/03/2011 05:13 PM
Dini Login/Register Issue iNoT Help Archive 7 17/06/2010 06:24 PM
[Looking For] DINI Register/Login Niixie Help Archive 14 26/12/2009 11:08 AM


All times are GMT. The time now is 05:06 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.