dinitut filterscript
#1

hi everyone !

iam using dinitut filterscript as for register and login command but the problem is that when a player registers so its name not saving in scriptfiles can any one tell me that why its happening .
Код:
#include <a_samp>
#include <dini>

//First we should want to create some variables to store the admin level, whether the player is logged in and we should want to define dcmd, too:
#define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
#define COLOR_RED      	0xFF0000FF
#define COLOR_YELLOW     	0xFFFF00AA
#define COLOR_WHITE 0xFFFFFFAA

new level[MAX_PLAYERS];
new logged[MAX_PLAYERS];

//Taken from dudb.inc
stock udb_hash(buf[]) {
	new length=strlen(buf);
  new s1 = 1;
  new s2 = 0;
  new n;
  for (n=0; n<length; n++)
  {
    s1 = (s1 + buf[n]) % 65521;
    s2 = (s2 + s1)   % 65521;
  }
  return (s2 << 16) + s1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
	//Ok, now we can start creating our commands. First, put
	dcmd(register, 8, cmdtext);
	dcmd(login, 5, cmdtext);
	//into your OnPlayerCommandText callback!
	return 0;
}

//Now let's start creating our /register command!
dcmd_register(playerid, params[])
{
  new file[256], pname[MAX_PLAYER_NAME];
  GetPlayerName(playerid, pname, sizeof(pname));
  format(file, sizeof(file), "../Scriptfiles/Users%s.ini", pname);
  if(!strlen(params)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE:/register [password]");
	//This script created a variable to store the file path and the player's name, it wrote the file path to the variable "file" and checked if there is anything in the params. Now we can start checking, if the player's stats file exists:
	
  if(dini_Exists(file)) return SendClientMessage(playerid, COLOR_RED, "You are already registered!");
	/*Now our script checks if a file stored in the variable "file" exists, if it does, returns an error message.
	Let's start writing into our file:*/
  dini_Create(file);
  dini_IntSet(file, "hashPW", udb_hash(params));
  dini_Set(file, "password", params);
  dini_IntSet(file, "level", 0);
  dini_IntSet(file, "score", GetPlayerScore(playerid));
  dini_IntSet(file, "money", GetPlayerMoney(playerid));
	/*
		Ok, now our little script created the file in the "file" variable, then set some things in the file:
		hashPW - Identifying later in our /login command
		password - Just the password the player sent us
		level - The player's admin level
		score - The player's score
		money - The player's money
	*/
	//Now let's add some messages and automatically login the player:
  new string[256];
  format(string, 256, "You succesfully registered the nickname %s with password %s", pname, params);
  SendClientMessage(playerid, COLOR_YELLOW, string);
  logged[playerid] = 1;
  SendClientMessage(playerid, COLOR_YELLOW, "You have been automatically logged in!");
  //Now it sent a message displaying the password and logged the player in!
	return 1;
}

/*
	This completes the /register command! Now we can start creating the /login command. 

	This is basically the same process as in /register: Create the variables, store the path, check if the file exists.
	But there is a difference, that we have to read the file instead of writing. I'll create the command and explain it after creating:
*/
dcmd_login(playerid, params[])
{
  new file[256];
  new string[256], pname[MAX_PLAYER_NAME];
  GetPlayerName(playerid, pname, sizeof(pname));
  format(file, sizeof(string), "\\Users\\%s.ini", pname);
  if(!strlen(params)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /login [password]");
  if(!dini_Exists(file)) return SendClientMessage(playerid, COLOR_RED, "You are not registered!");
  if(logged[playerid]) return SendClientMessage(playerid, COLOR_RED, "You are already logged in!");
  new tmp[256];
  tmp = dini_Get(file, "hashPW");
  if(udb_hash(params) != strval(tmp)) 
  {
    format(string, 256, "You specified the wrong password for %s!", pname);
    SendClientMessage(playerid, COLOR_RED, string);
  }
  else
  {
    logged[playerid] = 1;
    level[playerid] = dini_Int(file, "level");
		SetPlayerScore(playerid, dini_Int(file, "score"));
		GivePlayerMoney(playerid, dini_Int(file, "money")-GetPlayerMoney(playerid));
    SendClientMessage(playerid, COLOR_YELLOW, "You have succesfully logged in!");
    printf("%s (%i) logged in with password %s", pname, playerid, params);
  }
  return 1;
}
/*
	Ok, this script, like in the /register command, creates the "file" variable to store the file path, a "string" for the messages, and "pname" to store the player's name. 
	Then some basic if() statements to check if the player is registered, logged in or there are no params.

	Then it creates a variable "tmp" to store the hashed version of the password. 
	Then it hashes the player's inputted password and checks if the two passwords match, if they do, logs the player in, sets the "level" variable to the level, their score to the score and their money to the money in the player's stats file!
*/

/* See, wasn't that hard! =) */
Reply
#2

EDIT:

Well, theres scripting failture in that.. use another
Reply
#3

Quote:
Originally Posted by Niixie
EDIT:

Well, theres scripting failture in that.. use another
are u really sure ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)