[Tutorial] [TUT] Creating a Register System using Dini
#1

Hi, I'm making this tutorial, for people who don't know how to make a register system, "San Marino Cops n Robbers" guy asked for help and a tutorial on how to make a register and login system. This Registration System is for sa-mp 0.3

In This Tutorial you will learn
  • How to use some dini functions
  • How to create a login, register
Downloads Needed
dudb.inc
Dini.inc

I'm going to work with a new.pwn
Start off opening up new.pwn by pressing that button, on the top left corner under the word "file" when you done that. It should start off as a blank script, you should see
Код:
#include <a_samp>
under that type
Код:
#include <dini>
Ok, now under that add this
Код:
new IsLogged[MAX_PLAYERS];
This is going to be used for checking if the player is logged in or not. Now were going to make a players info using "enum pInfo" ( I use pInfo it doesnt matter you may change the name, but warning: you have to adjust the script.) Now and paste this
Код:
enum pInfo
{
	
}
new PlayerInfo[MAX_PLAYERS][pInfo];
now this is where you can add stuff (EX: Admin Level, VIP, etc..) enum can also be used to make house systems and business systems. ok, you may add data to your enum, but follow what I'm doing
Код:
enum pInfo
{
	AdminLevel,
     Cash,
}
new PlayerInfo[MAX_PLAYERS][pInfo];
Ass you can see, im adding a comma after everyone, its needed. and follow the format shown above . Now were going to make a /register command etc.... Under "OnPlayerCommandText" add this:
Код:
new cmd[256], idx, file[128], tmp[256], tmp2[256];
cmd = strtok(cmdtext, idx);
OK, now those are needed for you to make this command, but before we make the /register command we need strtok. the include "dudb" supplies us with it so copy this to the top of your script, "make sure you downloaded the one above, because thats my version, it works using my dini, and dudb"
Код:
#include <dudb>
ok now lets make the /register command copy and paste this (make sure you fill in "COLOR" with some color you have defined)
Код:
if(strcmp(cmd, "/register", true) == 0)
	{
	  new name[MAX_PLAYER_NAME];
	  tmp = strtok(cmdtext, idx);
	  GetPlayerName(playerid, name, sizeof(name));
	  if(strlen(tmp) == 0) return SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /register [password]");
	  format(file,sizeof(file),"%s.ini",name);
	  if(!fexist(file))
			{
			  dini_Create(file);
			  dini_IntSet(file, "Password", udb_hash(tmp));
			  dini_IntSet(file,"AdminLevel", 0);
			  dini_IntSet(file,"Cash", 0);
			  SendClientMessage(playerid, eadmin, "[System]: Account Created!");
			  PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
			  GetPlayerName(playerid, name, sizeof(name));
			  printf("%s has registered a account!", name);
			}
			else
			{
			  SendClientMessage(playerid, COLOR, " Account Already Found In Database");
                PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
			}
		return 1;
	}
	return 0;
}
This auto password hashes it! I get no errors, You? if so post it, now we are going to /login the /login command is like this:
Код:
	if(strcmp(cmd, "/login", true) == 0)
	{
	  new PlayerName[24];
	  tmp = strtok(cmdtext, idx);
	  if(strlen(tmp) == 0) return SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /login [password]");
		new name[MAX_PLAYER_NAME];
		if(IsLogged[playerid] == 1)
		{
			SendClientMessage(playerid, COLOR, "You already are logged in!");
			return 1;
		}
		else
		{
			GetPlayerName(playerid, name, sizeof(name));
			format(file,sizeof(file),"%s.ini",name);
			if(fexist(file))
			{
		  	tmp2 = dini_Get(file, "Password");
			 	if(udb_hash(tmp) != strval(tmp2))
				{
				  SendClientMessage(playerid, COLOR, "Login Failed!");
	 			  GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
	 			  printf("%s has failed to login", name);
				}
				else
				{
				 	IsLogged[playerid] = 1;
				 	SetPlayerMoney(playerid, dini_Int(file, "Cash"));
					PlayerInfo[playerid][AdminLevel] = dini_Int(file, "AdminLevel");
					SendClientMessage(playerid, COLOR, "[System]: Account Logged into!");
				}
			}
		}
		return 1;
	}
OK finally were 90% done, We have to make it so, that when a player disconnects he's still logged in. So under "OnPlayerDisconnect" copy this
Код:
IsLogged[playerid] = 0;
and put that under OnPlayerConnect, ok all done. you made a register system. You can simply add to it by following the format, on the /register command and /login command and also adding stuff to "enum" bye

edit: So people stop asking put this if you want someone to login first before spawn:


Код:
 if(gLogged[playerid] == 0)
	{
		SendClientMessage(playerid, COLOR, "SERVER: You have not logged in yet.");
          Kick(playerid);
		return 1;
	}
Reply


Messages In This Thread
[TUT] Creating a Register System using Dini - by Eazy_Efolife - 11.10.2009, 12:25
Re: [TUT] Creating a Register System using Dini - by kLx - 11.10.2009, 12:27
Re: [TUT] Creating a Register System using Dini - by Eazy_Efolife - 11.10.2009, 12:28
Re: [TUT] Creating a Register System using Dini - by [03]Garsino - 11.10.2009, 12:28
Re: [TUT] Creating a Register System using Dini - by dirkblok - 11.10.2009, 12:43
Re: [TUT] Creating a Register System using Dini - by Eazy_Efolife - 11.10.2009, 12:47
Re: [TUT] Creating a Register System using Dini - by dirkblok - 11.10.2009, 12:52
Re: [TUT] Creating a Register System using Dini - by dirkblok - 11.10.2009, 13:12
Re: [TUT] Creating a Register System using Dini - by cepiokas - 11.10.2009, 13:25
Re: [TUT] Creating a Register System using Dini - by Eazy_Efolife - 11.10.2009, 13:34
Re: [TUT] Creating a Register System using Dini - by cepiokas - 11.10.2009, 13:37
Re: [TUT] Creating a Register System using Dini - by Eazy_Efolife - 11.10.2009, 13:39
Re: [TUT] Creating a Register System using Dini - by cepiokas - 11.10.2009, 13:46
Re: [TUT] Creating a Register System using Dini - by Eazy_Efolife - 11.10.2009, 13:48
Re: [TUT] Creating a Register System using Dini - by cepiokas - 11.10.2009, 13:53
Re: [TUT] Creating a Register System using Dini - by Eazy_Efolife - 11.10.2009, 14:02
Re: [TUT] Creating a Register System using Dini - by cepiokas - 11.10.2009, 14:17
Re: [TUT] Creating a Register System using Dini - by Eazy_Efolife - 11.10.2009, 14:24
Re: [TUT] Creating a Register System using Dini - by lolmaster - 11.10.2009, 15:17
Re: [TUT] Creating a Register System using Dini - by cepiokas - 11.10.2009, 16:55
Re: [TUT] Creating a Register System using Dini - by Eazy_Efolife - 11.10.2009, 18:43
Re: [TUT] Creating a Register System using Dini - by cepiokas - 11.10.2009, 19:10
Re: [TUT] Creating a Register System using Dini - by Abernethy - 12.10.2009, 00:30
Re: [TUT] Creating a Register System using Dini - by Niixie - 07.12.2009, 16:54
Re: [TUT] Creating a Register System using Dini - by Dodo9655 - 11.12.2009, 15:16
Re: [TUT] Creating a Register System using Dini - by rong13 - 16.12.2009, 15:06
Re: [TUT] Creating a Register System using Dini - by DeathOnaStick - 16.12.2009, 17:53
Re: [TUT] Creating a Register System using Dini - by rong13 - 16.12.2009, 18:19
Re: [TUT] Creating a Register System using Dini - by DeathOnaStick - 16.12.2009, 18:20
Re: [TUT] Creating a Register System using Dini - by LarzI - 16.12.2009, 18:32
Re: [TUT] Creating a Register System using Dini - by rong13 - 16.12.2009, 18:40
Re: [TUT] Creating a Register System using Dini - by rong13 - 16.12.2009, 18:44
Re: [TUT] Creating a Register System using Dini - by Eazy_Efolife - 16.12.2009, 19:33
Re: [TUT] Creating a Register System using Dini - by rong13 - 16.12.2009, 19:43
Re: [TUT] Creating a Register System using Dini - by Eazy_Efolife - 16.12.2009, 19:47
Re: [TUT] Creating a Register System using Dini - by rong13 - 16.12.2009, 20:26
Re: [TUT] Creating a Register System using Dini - by admantis - 17.12.2009, 16:05
Re: [TUT] Creating a Register System using Dini - by Willstah - 20.12.2009, 20:42
Re: [TUT] Creating a Register System using Dini - by Juve913 - 24.12.2009, 06:47
Re: [TUT] Creating a Register System using Dini - by LarzI - 24.12.2009, 09:27
Re: [TUT] Creating a Register System using Dini - by PotH3Ad - 28.12.2009, 02:47
Re: [TUT] Creating a Register System using Dini - by Eazy_Efolife - 04.01.2010, 19:00
Re: [TUT] Creating a Register System using Dini - by Nakki - 11.01.2010, 15:44
Re: [TUT] Creating a Register System using Dini - by [DK]JaloNik - 14.07.2010, 12:45
Re: [TUT] Creating a Register System using Dini - by sorfa - 15.07.2010, 17:44
Re: [TUT] Creating a Register System using Dini - by [DK]JaloNik - 15.07.2010, 18:17
Re: [TUT] Creating a Register System using Dini - by sorfa - 15.07.2010, 18:32
Re: [TUT] Creating a Register System using Dini - by Anthonyx3' - 24.08.2010, 05:05
Re: [TUT] Creating a Register System using Dini - by R@ger - 24.08.2010, 09:35
Re: [TUT] Creating a Register System using Dini - by r3k1lLz_ - 07.09.2010, 10:38
Re: [TUT] Creating a Register System using Dini - by Guest3598475934857938411 - 02.10.2010, 19:34
Re: [TUT] Creating a Register System using Dini - by karakana7 - 31.10.2010, 17:33
Re: [TUT] Creating a Register System using Dini - by Rabbayazza - 10.08.2011, 20:08
Re: [TUT] Creating a Register System using Dini - by Kush - 10.08.2011, 21:45
Re: [TUT] Creating a Register System using Dini - by Rabbayazza - 10.08.2011, 21:47
Re: [TUT] Creating a Register System using Dini - by rooney12 - 10.08.2011, 21:49
Re: [TUT] Creating a Register System using Dini - by Darnell - 13.08.2011, 06:02
Re: [TUT] Creating a Register System using Dini - by Shockey HD - 13.08.2011, 06:28
Re: [TUT] Creating a Register System using Dini - by Darnell - 13.08.2011, 06:35
Re: [TUT] Creating a Register System using Dini - by Kaperstone - 13.08.2011, 08:09
Re: [TUT] Creating a Register System using Dini - by Darnell - 13.08.2011, 08:17
Re: [TUT] Creating a Register System using Dini - by PhoenixB - 13.08.2011, 11:11
Re: [TUT] Creating a Register System using Dini - by Kaperstone - 14.08.2011, 12:46
Re: [TUT] Creating a Register System using Dini - by NomNom - 19.08.2011, 22:03
Re: [TUT] Creating a Register System using Dini - by Kush - 19.08.2011, 22:15
Re: [TUT] Creating a Register System using Dini - by Henkie - 24.08.2011, 07:11
AW: [TUT] Creating a Register System using Dini - by Santox14 - 27.09.2011, 16:24
AW: [TUT] Creating a Register System using Dini - by Santox14 - 27.09.2011, 16:33
Re: [TUT] Creating a Register System using Dini - by Don21x - 25.12.2012, 17:02
Re: [TUT] Creating a Register System using Dini - by Denying - 25.02.2013, 09:03
Respuesta: [TUT] Creating a Register System using Dini - by RiChArD_A - 25.02.2013, 13:15
Re: [TUT] Creating a Register System using Dini - by Joshly98 - 27.06.2013, 07:28
Re: [TUT] Creating a Register System using Dini - by freeze98 - 20.08.2014, 15:26

Forum Jump:


Users browsing this thread: 5 Guest(s)