11.10.2009, 12:25
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
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
under that type
Ok, now under that add this
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
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
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:
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"
ok now lets make the /register command copy and paste this (make sure you fill in "COLOR" with some color you have defined)
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:
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
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:
In This Tutorial you will learn
- How to use some dini functions
- How to create a login, register
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>
Код:
#include <dini>
Код:
new IsLogged[MAX_PLAYERS];
Код:
enum pInfo { } new PlayerInfo[MAX_PLAYERS][pInfo];
Код:
enum pInfo { AdminLevel, Cash, } new PlayerInfo[MAX_PLAYERS][pInfo];
Код:
new cmd[256], idx, file[128], tmp[256], tmp2[256]; cmd = strtok(cmdtext, idx);
Код:
#include <dudb>
Код:
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; }
Код:
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; }
Код:
IsLogged[playerid] = 0;
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; }