Jump to content

[PAWN]Cum facem pin sistem?


GigiGrasu
 Share

Recommended Posts

Astazi m-am decis sa va arat cum se face un sistem de pin. 

Acest tutorial contine toate etapele si comenzile necesare sistemului.

Nu ofer suport sa le puneti la voi in script, sper sa va fie de folos acest tutorial.

 

1.Adaugam la enum pInfo 

pUnlocked,
pPin[5]

2. la OnPlayerConnect si OnPlayerDisconnect adaugam

PlayerInfo[playerid][pUnlocked] = 0;

3. Acum adaugam un noi callback

public CheckAccount(playerid);
public CheckAccount(playerid) {
	new i;
	if(PlayerInfo[playerid][pUnlocked] == 0 && (strlen(PlayerInfo[playerid][pPin]) > 0)) {
		i = 0;
	} else i = 1;
	return i;
}

4. Facem Comenzile:

CMD:pin(playerid, params[])
{
	if(gPlayerLogged[playerid] == 0) return SendClientMessage(playerid, COLOR_LIGHTRED, "You need to login first.");
	new pin[128];
	if(PlayerInfo[playerid][pUnlocked] != 0) return SCM(playerid, COLOR_LIGHTRED, "You already unlocked your account.");
	if(sscanf(params, "s[128]", pin)) return SCM(playerid, COLOR_SYN, "Syntax: /unlockacc <4-digit-code>");
	if(strlen(pin) != 4) return SCM(playerid, COLOR_SYN, "Syntax: /unlockacc <4-digit-code>");
	if(!IsNumeric(pin)) return SCM(playerid, COLOR_SYN, "Syntax: /unlockacc <4-digit-code>");
	if(!strcmp(pin, PlayerInfo[playerid][pPin], true)) {
		PlayerInfo[playerid][pUnlocked] = 1;
		SCM(playerid, COLOR_LIGHTBLUE, "Contul tau a fost deblocat cu succes!");
	} else {
		SCM(playerid, COLOR_LIGHTRED, "Ai introdus un PIN gresit!");
	}
	return 1;
}

CMD:changepin(playerid, params[])
{
	if(gPlayerLogged[playerid] == 0) return SendClientMessage(playerid, COLOR_LIGHTRED, "You need to login first.");
	new pin[128],pin2[128], string[128];
	if(strlen(PlayerInfo[playerid][pPin]) == 0) return SCM(playerid, COLOR_LIGHTRED, "You don't have a pin code. Type [/addpin] to add one.");
	if(sscanf(params, "s[128]s[128]", pin, pin2)) return SCM(playerid, COLOR_SYN, "Syntax: /changepin <current-pin> <4-digit-new-pin>");
	if(!IsNumeric(pin)) return SCM(playerid, COLOR_SYN, "Syntax: /changepin <current-pin> <4-digit-new-pin>");
	if(strlen(pin) != 4) return SCM(playerid, COLOR_SYN, "Syntax: /changepin <current-pin> <4-digit-new-pin>");
	if(!IsNumeric(pin2)) return SCM(playerid, COLOR_SYN, "Syntax: /changepin <current-pin> <4-digit-new-pin>");
	if(strlen(pin2) != 4) return SCM(playerid, COLOR_SYN, "Syntax: /changepin <current-pin> <4-digit-new-pin>");
	if(strcmp(pin, PlayerInfo[playerid][pPin], true)) return SCM(playerid, COLOR_LIGHTRED, "You entered a wrong pin.");
	string[0] = (EOS);
	mysql_format(SQL, string, sizeof(string), "UPDATE `users` SET `Pin`='%s' WHERE `id`='%d'", pin2, PlayerInfo[playerid][pSQLID]);
	mysql_query(SQL, string);
	format(PlayerInfo[playerid][pPin], 5, "%s", pin2);
	format(string, sizeof(string), "Your new security pin code is %s. Don't forget it!", pin2);
	SCM(playerid, COLOR_LIGHTBLUE, string);
	return 1;
}
 
CMD:addpin(playerid, params[])
{
	if(gPlayerLogged[playerid] == 0) return SendClientMessage(playerid, COLOR_LIGHTRED, "You need to login first.");
	new pin[128], string[128];
	if(strlen(PlayerInfo[playerid][pPin]) > 0) return SCM(playerid, COLOR_LIGHTRED, "You already have a pin code.");
	if(sscanf(params, "s[128]", pin)) return SCM(playerid, COLOR_SYN, "Syntax: /addpin <4-digit-code>");
	if(!IsNumeric(pin)) return SCM(playerid, COLOR_SYN, "Syntax: /addpin <4-digit-code>");
	if(strlen(pin) != 4) return SCM(playerid, COLOR_SYN, "Syntax: /addpin <4-digit-code>");
	string[0] = (EOS);
	mysql_format(SQL, string, sizeof(string), "UPDATE `users` SET `Pin`='%s' WHERE `id`='%d'", pin, PlayerInfo[playerid][pSQLID]);
	mysql_query(SQL, string);
	format(PlayerInfo[playerid][pPin], 5, "%s", pin);
	format(string, sizeof(string), "Your new security pin code is %s. Don't forget it!", pin);
	SCM(playerid, COLOR_LIGHTBLUE, string);
	return 1;
}

5. La OnPlayerConnect mai adaugam

format(PlayerInfo[playerid][pPin], 5, "");

 

Edited by Cdorsu
Link to comment
Share on other sites

@Mariusik se vede ca esti incepator, nu iti recomand sa golesti un string cu "format" ci cu "strdel".

format(PlayerInfo[playerid][pPin], 5, "");

 

Edited by FnZ
Link to comment
Share on other sites

2 minutes ago, FnZ said:

@Mariusik se vede ca esti incepator, nu iti recomand niciodata sa golesti un string cu "format" ci cu "strdel".


format(PlayerInfo[playerid][pPin], 5, "");

 

Asa am folosit cand am avut server, acum un an mai exact.

Si nu au fost probleme, a mers bine

Link to comment
Share on other sites

On 8/25/2017 at 1:28 PM, SiNNeD47 said:

Daca era tutorial, trebuia sa arati si cum se pune in baza de date acel pin, cat de cat folositor. Se putea si ma bine.


Da, se putea sa fie facut mai bine.

 

Totusi, e destul pare destul de bun.

 

Nu prea mai vad activitate pe aici,  o sa inchid topicul.

 

Topic closed;

Link to comment
Share on other sites

  • Cdorsu locked this topic
Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.