[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
#2

You'd better use:
Код:
new bool: IsLogged[MAX_PLAYERS];
Reply
#3

I didn't add new bool, it doesn't effect my register system.
Reply
#4

Usefull for newbies like me!
Reply
#5

Hey, can you add something in your tutorial, how to save skins when you logout?

Very good tutorial, I like it

Dirk
Reply
#6

Quote:
Originally Posted by dirkblok
Hey, can you add something in your tutorial, how to save skins when you logout?

Very good tutorial, I like it

Dirk
Follow the format remember that: in the enum pInfo add "skin,"
Then when you do /login, put under
Code:
SetPlayerMoney(playerid, dini_Int(file, "Cash"));
put:
Code:
SetPlayerSkin(playerid, dini_Int(file, "Skin"));
and in /register command include this:
Code:
dini_IntSet(file,"Skin", 50);
You can change the "50" to any number, that in the Skin ID limit. So when they spawn, they will spawn with the skin id. Is that what your asking? It autosaves btw
Reply
#7

Thanks alot man
Reply
#8

Hey,
I'm sorry but it don't work...?

When I do /login password
I just get the CJ skin?

Can you help me with this?
Reply
#9

Code:
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(184) : warning 219: local variable "name" shadows a variable at a preceding level
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(179) : warning 204: symbol is assigned a value that is never used: "tmp2"
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(179 -- 211) : error 010: invalid function or declaration
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(214) : error 010: invalid function or declaration
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(215) : error 010: invalid function or declaration
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(217) : error 010: invalid function or declaration
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(220) : error 010: invalid function or declaration
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(222) : error 010: invalid function or declaration
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(226) : error 010: invalid function or declaration
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(229) : error 010: invalid function or declaration
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(235) : error 010: invalid function or declaration
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(238) : error 021: symbol already defined: "SetPlayerMoney"
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(238) : error 010: invalid function or declaration
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(238 -- 244) : error 010: invalid function or declaration
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(238 -- 244) : fatal error 107: too many error messages on one line

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


13 Errors.
What's wrong?
Reply
#10


Code:
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(184) : warning 219: local variable "name" shadows a variable at a preceding level
Delete: new name[MAX_PLAYER_NAME];

Code:
error 021: symbol already defined: "SetPlayerMoney"
I dont know what you did but SetPlayerMoney should be already defined as its included.

Code:
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(179 -- 211) : error 010: invalid function or declaration
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(214) : error 010: invalid function or declaration
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(215) : error 010: invalid function or declaration
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(217) : error 010: invalid function or declaration
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(220) : error 010: invalid function or declaration
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(222) : error 010: invalid function or declaration
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(226) : error 010: invalid function or declaration
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(229) : error 010: invalid function or declaration
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(235) : error 010: invalid function or declaration
Show me those lines,
Code:
warning 204: symbol is assigned a value that is never used: "tmp2"
delete "tmp2"
Reply
#11

I'm just delete
Code:
new name[MAX_PLAYER_NAME];
And now left just these errors
Code:
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(184) : error 017: undefined symbol "name"
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(184) : error 017: undefined symbol "name"
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(184) : error 029: invalid expression, assumed zero
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(184) : fatal error 107: too many error messages on one line

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


4 Errors.
184:
Code:
 GetPlayerName(playerid, name, sizeof(name));
Reply
#12

Quote:
Originally Posted by cepiokas
I'm just delete
Code:
new name[MAX_PLAYER_NAME];
And now left just these errors
Code:
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(184) : error 017: undefined symbol "name"
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(184) : error 017: undefined symbol "name"
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(184) : error 029: invalid expression, assumed zero
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(184) : fatal error 107: too many error messages on one line

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


4 Errors.
184:
Code:
 GetPlayerName(playerid, name, sizeof(name));
You must have another, "new name[MAX_PLAYER_NAME];" in your script, delete ALL of them! and put

"new name[MAX_PLAYER_NAME];" on top of your script so you wont have to deal with it
Reply
#13

That new name[MAX_PLAYER_NAME]; is in /login. Then i remove it and put it on the top i'm get errors:
Code:
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(179) : warning 204: symbol is assigned a value that is never used: "tmp2"
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(179 -- 209) : error 010: invalid function or declaration
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(212) : error 010: invalid function or declaration
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(213) : error 010: invalid function or declaration
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(214) : error 021: symbol already defined: "name"
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(215) : error 010: invalid function or declaration
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(218) : error 010: invalid function or declaration
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(220) : error 010: invalid function or declaration
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(224) : error 010: invalid function or declaration
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(227) : error 010: invalid function or declaration
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(233) : error 010: invalid function or declaration
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(236) : error 021: symbol already defined: "SetPlayerMoney"
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(236) : error 010: invalid function or declaration
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(236 -- 242) : error 010: invalid function or declaration
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(236 -- 242) : fatal error 107: too many error messages on one line

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

I don't know why this is happening to you, show me your script in PM if you want?
Reply
#15

I'm already send. Wait for answer. Thanks Compton.
Reply
#16

I'm still looking for the problem but Just In Case this is my script, and this is what it should look like

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

#include <a_samp>
#include <dini>
#include <dudb>

#define eadmin     0x33660000

new IsLogged[MAX_PLAYERS];

enum pInfo
{
	AdminLevel,
	Cash,
}
new PlayerInfo[MAX_PLAYERS][pInfo];
#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

public OnGameModeInit()
{
	// Don't use these lines if it's a filterscript
	SetGameModeText("Blank Script");
	AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
	return 1;
}

public OnGameModeExit()
{
	return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
	SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
	SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
	SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
	return 1;
}

public OnPlayerConnect(playerid)
{
  IsLogged[playerid] = 0;
	return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
  IsLogged[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[])
{
  new cmd[256], idx, file[128], tmp[256], tmp2[256];
	cmd = strtok(cmdtext, idx);
	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, eadmin, "[System]: Account Already Found In Database");
        PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
			}
		return 1;
	}
	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, eadmin, "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, eadmin, "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, eadmin, "[System]: Account Logged into!");
				}
			}
		}
		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[])
{
	return 1;
}

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

Ok. I found my own mistake. The problem was
Code:
return 0;
, this one must be OnPlayerCommandText return, but i make it as /login return, so my /login have 2 returns. I see when i copyied everything from you. Everything ok, thanks alot. Jus one warning:
Code:
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(492) : warning 203: symbol is never used: "ret_memcpy"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Warning.
And i didn't have 492 line.
Reply
#18

Quote:
Originally Posted by cepiokas
Ok. I found my own mistake. The problem was
Code:
return 0;
, this one must be OnPlayerCommandText return, but i make it as /login return, so my /login have 2 returns. I see when i copyied everything from you. Everything ok, thanks alot. Jus one warning:
Code:
C:\Documents and Settings\Samsung\Desktop\sLife v1.0\gamemodes\sLife.pwn(492) : warning 203: symbol is never used: "ret_memcpy"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Warning.
And i didn't have 492 line.
i forgot how to ah, I think you put
#pragma unused ret_memcpy
Reply
#19

Hi, guys.

I have a problem with the Register login system.

When im logget in with a wrong passwort.
logget he in.
Wehn im logget in with a right passwort.
logget he in.
why?



Sorry for my bad english.
Reply
#20

Some question about it.
1st - How to make, that server didn't spawn to play or let to do something ( type commands ), if you didn't logged in?
2nd - How to save your last X, Y and Z coordinates.
3rd - How to make, that you can save with pickup ( game saved just when, when you take a savedisket pickup )
Thanks.
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)