Check if player is banned (y_ini)
#1

Hi, I'm trying to work out how to check if a player is banned using y_ini.. as I'm writing a unban command and even if the player is unbanned it still says you have unbanned this player.. I'm trying to write an if statement to check if the players file has the variable pBanned == 1.

Here is my code:
Код:
CMD:unban(playerid, params[])
{
	if(PlayerInfo[playerid][pAdminLevel] >= 2)
	{
		new path[124];
		if(isnull(params)) return SendClientMessage(playerid, -1, "Syntax - /unban <Player Name>");
	    format(path,sizeof(path),"Accounts/%s.ini",params);
	    if(fexist(path))
	    {
	        new INI:file = INI_Open(path);
	        INI_SetTag(file,"data");
	        INI_WriteInt(file,"Banned",0);
	        INI_Close(file);
	        new unbanstring[124];
	        format(unbanstring, sizeof(unbanstring), "You have unbanned the account: (%s)", params);
	        SendClientMessage(playerid, -1, unbanstring);
		}else SendClientMessage(playerid,-1,"Account not found, make sure you type the exact name.");
	}else SendClientMessage(playerid, -1, "Error: You must be admin level 2 or higher.");
	return 1;
}
And now I'll add where I want the if statement to be:
Код:
CMD:unban(playerid, params[])
{
	if(PlayerInfo[playerid][pAdminLevel] >= 2)
	{
		new path[124];
		if(isnull(params)) return SendClientMessage(playerid, -1, "Syntax - /unban <Player Name>");
	    format(path,sizeof(path),"Accounts/%s.ini",params);
	    if(fexist(path))
	    {
	        if(IS THE PLAYER ISN'T ALREADY BANNED)
	        {
	        new INI:file = INI_Open(path);
	        INI_SetTag(file,"data");
	        INI_WriteInt(file,"Banned",0);
	        INI_Close(file);
	        new unbanstring[124];
	        format(unbanstring, sizeof(unbanstring), "You have unbanned the account: (%s)", params);
	        SendClientMessage(playerid, -1, unbanstring);
	        }else SendClientMessage(playerid,-1,"This account is not banned.");
		}else SendClientMessage(playerid,-1,"Account not found, make sure you type the exact name.");
	}else SendClientMessage(playerid, -1, "Error: You must be admin level 2 or higher.");
	return 1;
}
I hope you understand me, and help. Thanks in advance.
Reply
#2

Aha! It took me a while to understand your problem, mate.

I have been struggling with /unban for a long time. My suggestion to you is to use a boolean.
A boolean is a function which checks if the variable is true or false, nothing else.

Код:
new bool:test //Creates a boolean called "test" and it is automatically on false.        
new bool:Banned=true  //A boolean called "Banned and it has been set to true.
here's how you should add it to the script:

Код:
new bool:Banned[MAX_PLAYERS]; //global variable
CMD:unban(playerid, params[])
{
	if(PlayerInfo[playerid][pAdminLevel] >= 2)
	{
		new path[124];
		if(isnull(params)) return SendClientMessage(playerid, -1, "Syntax - /unban <Player Name>");
	    format(path,sizeof(path),"Accounts/%s.ini",params);
	    if(fexist(path))
	    {
	        if(Banned[Here the variable to define target id] == false)
	        {
	        new INI:file = INI_Open(path);
	        INI_SetTag(file,"data");
	        INI_WriteInt(file,"Banned",0);
	        INI_Close(file);
	        new unbanstring[124];
	        format(unbanstring, sizeof(unbanstring), "You have unbanned the account: (%s)", params);
	        SendClientMessage(playerid, -1, unbanstring);
	        }else SendClientMessage(playerid,-1,"This account is not banned.");
		}else SendClientMessage(playerid,-1,"Account not found, make sure you type the exact name.");
	}else SendClientMessage(playerid, -1, "Error: You must be admin level 2 or higher.");
	return 1;
}
hope this works for you
Reply
#3

Quote:
Originally Posted by xCrazyMonkey
Посмотреть сообщение
Aha! It took me a while to understand your problem, mate.

I have been struggling with /unban for a long time. My suggestion to you is to use a boolean.
A boolean is a function which checks if the variable is true or false, nothing else.

Код:
new bool:test //Creates a boolean called "test" and it is automatically on false.        
new bool:Banned=true  //A boolean called "Banned and it has been set to true.
here's how you should add it to the script:

Код:
new bool:Banned[MAX_PLAYERS]; //global variable
CMD:unban(playerid, params[])
{
	if(PlayerInfo[playerid][pAdminLevel] >= 2)
	{
		new path[124];
		if(isnull(params)) return SendClientMessage(playerid, -1, "Syntax - /unban <Player Name>");
	    format(path,sizeof(path),"Accounts/%s.ini",params);
	    if(fexist(path))
	    {
	        if(Banned[Here the variable to define target id] == false)
	        {
	        new INI:file = INI_Open(path);
	        INI_SetTag(file,"data");
	        INI_WriteInt(file,"Banned",0);
	        INI_Close(file);
	        new unbanstring[124];
	        format(unbanstring, sizeof(unbanstring), "You have unbanned the account: (%s)", params);
	        SendClientMessage(playerid, -1, unbanstring);
	        }else SendClientMessage(playerid,-1,"This account is not banned.");
		}else SendClientMessage(playerid,-1,"Account not found, make sure you type the exact name.");
	}else SendClientMessage(playerid, -1, "Error: You must be admin level 2 or higher.");
	return 1;
}
hope this works for you
This didn't work, I'm trying to utilise something with the y_ini..

Theres INI_WriteInt to write an ini to the file, but I want something like INI_GetIni(file, pBanned)
Reply
#4

Hmm, I'm a bit confused now. Do you want to unban someone or check if someone is banned with the command "unban"?
Reply
#5

Quote:
Originally Posted by xCrazyMonkey
Посмотреть сообщение
Hmm, I'm a bit confused now. Do you want to unban someone or check if someone is banned with the command "unban"?
He wants at first, check if the player is banned. And if the player is banned, then he is unbanned
Reply
#6

Checking the account file if the player is banned, is rather unnecessary due to the name might change of the player. So i am assuming you did save the bans in separate files named with their IP somewhere.

https://sampforum.blast.hk/showthread.php?tid=175565

pawn Код:
INI:filename[tag](name[], value[])
{
    INI_Int("LEVEL", gLevel);
}
That is how you read an Integer, right?

Now, in order to read the correct file you need to have saved the IP of the player into the account-file (i presume you did). Then you can load that IP, and set that as "filename" in the case above. If it finds any matching files with the same filename, you can make it delete the file. Simply enough you can use "fremove(pathhere)". Please Ignore the [tag] if you didn't add tags in your ini-file (simply remove it from the line)


Makes more sense now ?
Reply
#7

Quote:
Originally Posted by airplanesimen
Посмотреть сообщение
Checking the account file if the player is banned, is rather unnecessary due to the name might change of the player. So i am assuming you did save the bans in separate files named with their IP somewhere.

https://sampforum.blast.hk/showthread.php?tid=175565

pawn Код:
INI:filename[tag](name[], value[])
{
    INI_Int("LEVEL", gLevel);
}
That is how you read an Integer, right?

Now, in order to read the correct file you need to have saved the IP of the player into the account-file (i presume you did). Then you can load that IP, and set that as "filename" in the case above. If it finds any matching files with the same filename, you can make it delete the file. Simply enough you can use "fremove(pathhere)". Please Ignore the [tag] if you didn't add tags in your ini-file (simply remove it from the line)


Makes more sense now ?
Actually, I have the pBanned variable inside of a big file for each players stats, and if the pBanned variable is set to 1 and saved this is checked when the player joins.
Reply
#8

if(PlayerInfo[playerid][pBanned]==0)
Reply
#9

Quote:
Originally Posted by Pawnify
Посмотреть сообщение
Actually, I have the pBanned variable inside of a big file for each players stats, and if the pBanned variable is set to 1 and saved this is checked when the player joins.
Okay, so lets say that the player changes his name then. Then the pBanned variable won't be found and the player is not banned anymore.

Are you sure you aren't also adding a new INI file containing the IP of the player as the "filename" ? Because if you unban you can:

1. read from the file containing the "pBanned" variable, and find the IP in there aswell.
2. save the IP you found saved in the file, and use it to find the banned ip (the file containing the IP)
3. remove the IP-file, and set the pBanned to 0.


Reply
#10

Quote:
Originally Posted by Camorra
Посмотреть сообщение
if(PlayerInfo[playerid][pBanned]==0)
That would make the system to check if the player who wrote the command is banned or not, it wouldn't make the system check if a specific player is banned or not. So your code makes next to no sense.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)