SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 11/10/2009, 12:25 PM   #1
Eazy_Efolife
High-roller
 
Join Date: Aug 2009
Posts: 1,206
Reputation: 9
Default [TUT] Creating a Register System using Dini

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
Code:
#include <a_samp>
under that type
Code:
#include <dini>
Ok, now under that add this
Code:
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
Code:
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
Code:
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:
Code:
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"
Code:
#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)
Code:
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:
Code:
	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
Code:
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:


Code:
 if(gLogged[playerid] == 0)
	{
		SendClientMessage(playerid, COLOR, "SERVER: You have not logged in yet.");
          Kick(playerid);
		return 1;
	}
Eazy_Efolife is offline   Reply With Quote
Old 11/10/2009, 12:27 PM   #2
kLx
Huge Clucker
 
kLx's Avatar
 
Join Date: Feb 2008
Posts: 240
Reputation: 6
Default Re: [TUT] Creating a Register System using Dini

You'd better use:
Code:
new bool: IsLogged[MAX_PLAYERS];
__________________
Out of bussiness
kLx is offline   Reply With Quote
Old 11/10/2009, 12:28 PM   #3
Eazy_Efolife
High-roller
 
Join Date: Aug 2009
Posts: 1,206
Reputation: 9
Default Re: [TUT] Creating a Register System using Dini

I didn't add new bool, it doesn't effect my register system.
Eazy_Efolife is offline   Reply With Quote
Old 11/10/2009, 12:28 PM   #4
[03]Garsino
Guest
 
Posts: n/a
Default Re: [TUT] Creating a Register System using Dini

Usefull for newbies like me!
  Reply With Quote
Old 11/10/2009, 12:43 PM   #5
dirkblok
Huge Clucker
 
Join Date: Aug 2009
Posts: 337
Reputation: 0
Default Re: [TUT] Creating a Register System using Dini

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

Very good tutorial, I like it

Dirk
dirkblok is offline   Reply With Quote
Old 11/10/2009, 12:47 PM   #6
Eazy_Efolife
High-roller
 
Join Date: Aug 2009
Posts: 1,206
Reputation: 9
Default Re: [TUT] Creating a Register System using Dini

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
Eazy_Efolife is offline   Reply With Quote
Old 11/10/2009, 12:52 PM   #7
dirkblok
Huge Clucker
 
Join Date: Aug 2009
Posts: 337
Reputation: 0
Default Re: [TUT] Creating a Register System using Dini

Thanks alot man
dirkblok is offline   Reply With Quote
Old 11/10/2009, 01:12 PM   #8
dirkblok
Huge Clucker
 
Join Date: Aug 2009
Posts: 337
Reputation: 0
Default Re: [TUT] Creating a Register System using Dini

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?
dirkblok is offline   Reply With Quote
Old 11/10/2009, 01:25 PM   #9
cepiokas
Big Clucker
 
Join Date: Jun 2009
Posts: 73
Reputation: 0
Default Re: [TUT] Creating a Register System using Dini

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 (c) 1997-2006, ITB CompuPhase


13 Errors.
What's wrong?
cepiokas is offline   Reply With Quote
Old 11/10/2009, 01:34 PM   #10
Eazy_Efolife
High-roller
 
Join Date: Aug 2009
Posts: 1,206
Reputation: 9
Default Re: [TUT] Creating a Register System using Dini


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"
Eazy_Efolife 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
Creating a dynamic group system with userfiles and dini MisterTickle Help Archive 2 12/01/2010 03:56 PM
[Looking For] DINI Register/Login Niixie Help Archive 14 26/12/2009 11:08 AM
[Tutorial] Creating a simple register and login system. AcId n RaPiD Help Archive 0 21/11/2009 02:23 PM
Dini Problem, Accounts Not Creating Eazy_Efolife Help Archive 9 01/10/2009 03:42 PM


All times are GMT. The time now is 01:39 PM.


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