Ban command help.
#1

Hi, I'm attempting to create a /ban command here's what I have.

PHP код:
CMD:ban(playeridparams[])
{
    new 
string[144], IDname[30], reason[30], adminname[MAX_PLAYER_NAME], ID[128];
    if(
PlayerInfo[playerid][AdminLevel] < 2)  return 0;
    if(
sscanf(params,"us[128]"IDnamereason)) return SCM(playeridCOLOR_ADMIN"Usage: /ban [Player ID] [Reason]");
    if(
IsPlayerConnected(ID)) return SCM(playeridCOLOR_RED"Error: You IDIOT; you cannot ban yourself!");
    
GetPlayerName(IDIDnamesizeof(IDname)); GetPlayerName(playeridadminnamesizeof(adminname));
    if(
AdminLevel[ID] >= AdminLevel[playerid] && AdminUC[ID] == 0) return SendPlayerFormattedText(playeridCOLOR_RED"Error: You cannot ban %s"IDname);
    
INT_WriteInt(File,"Banned",1);
    
INT_WriteString(File,"BannedBy"adminname);
    if(
AdminUC[playerid] == 0);
    {
        
format(string,sizeof(string), "~You have been banned from the server by Administrator %s [Reason: %s]"adminnamereason);
        
SCM(IDCOLOR_GREENstring)
        
CMDMessToAdmins(playerid"BAN");
        
SaveToFile("BanLog"string);
        
SendAllFormattedText(COLOR_RED"~ %s has been banned from the server. [Reason: %s]"IDnamereason);
    }
    else
    {
        
format(stringsizeof(string),"~You have been banned from the server. [Reason: %s]"reason)
        
SCM(IDCOLOR_GREENstring)
        
SaveToFile("BanLog"string);
        
SendAllFormattedText(COLOR_RED"~ %s has been banned from the server. [Reason: %s]"IDnamereason);
    }
    
PlayerInfo[ID][Banned] = reason;
    
PlayerInfo[ID][BannedBy] = adminname;
     return 
1;

However I get 6 errors.

Код:
(479) : error 035: argument type mismatch (argument 1)
(480) : error 035: argument type mismatch (argument 1)
(481) : error 028: invalid subscript (not an array or too many subscripts): "AdminLevel"
(481) : warning 215: expression has no effect
(481) : error 001: expected token: ";", but found "]"
(481) : error 029: invalid expression, assumed zero
(481) : fatal error 107: too many error messages on one line
Line 479 is
Код:
if(IsPlayerConnected(ID)) return SCM(playerid, COLOR_RED, "Error: You IDIOT; you cannot ban yourself!");
Line 480 is
Код:
GetPlayerName(ID, IDname, sizeof(IDname)); GetPlayerName(playerid, adminname, sizeof(adminname));
And Line 481 is
Код:
	if(AdminLevel[ID] >= AdminLevel[playerid] && AdminUC[ID] == 0) return SendPlayerFormattedText(playerid, COLOR_RED, "Error: You cannot ban %s", IDname);
Anyone whom takes time to help out will get + 1 Rep.

Cheers.
Reply
#2

PHP код:
    if(IsPlayerConnected(ID)) return SCM(playeridCOLOR_RED"Error: You IDIOT; you cannot ban yourself!"); 
This should be something like
PHP код:
if(IDname(playerid) == IDname(playerid)) return SCM(playerid, -1"You can't ban yourself blah blah"); 
Not sure why both your GetName functions are on the same line, should probably return that.

Why do you use
PHP код:
AdminLevel[ID
and
PHP код:
PlayerInfo[playerid][AdminLevel
Also what's the point of 'SCM' apposed to SendClientMessage, it doesn't serve any purpose other than catering to laziness.
Reply
#3

I'm pretty sure that the ID variable shouldn't be a string. When using sscanf, the "u" specifier will check if the playerid parameter is a player name or a player id, so you could type in the ID of the player or the name of the player and it should work as normal.
Reply
#4

Quote:
Originally Posted by Flake.
Посмотреть сообщение
PHP код:
    if(IsPlayerConnected(ID)) return SCM(playeridCOLOR_RED"Error: You IDIOT; you cannot ban yourself!"); 
This should be something like
PHP код:
if(IDname(playerid) == IDname(playerid)) return SCM(playerid, -1"You can't ban yourself blah blah"); 
Not sure why both your GetName functions are on the same line, should probably return that.

Why do you use
PHP код:
AdminLevel[ID
and
PHP код:
PlayerInfo[playerid][AdminLevel
Also what's the point of 'SCM' apposed to SendClientMessage, it doesn't serve any purpose other than catering to laziness.
Thanks for your input. I added what you suggested for line 480. Now i'm only getting 4 error's but they are the same on the line 480
Код:
(480) : error 012: invalid function call, not a valid address
(480) : warning 215: expression has no effect
(480) : error 001: expected token: ";", but found ")"
(480) : error 029: invalid expression, assumed zero
(480) : fatal error 107: too many error messages on one line
I changed all the Adminlevel[ID]'s to the PlayerInfo do you have any suggestions to help me out?

PHP код:
CMD:ban(playeridparams[])
{
    new 
string[144], IDname[30], reason[30], adminname[MAX_PLAYER_NAME], ID[128];
    if(
PlayerInfo[playerid][AdminLevel] < 2)  return 0;
    if(
sscanf(params,"us[128]"IDnamereason)) return SendClientMessage(playeridCOLOR_ADMIN"Usage: /ban [Player ID] [Reason]");
    if(
IDname(playerid) == IDname(playerid))    return SendClientMessage(playerid, -1"Error: You IDIOT; you cannot ban yourself!");
    
GetPlayerName(IDIDnamesizeof(IDname));
    
GetPlayerName(playeridadminnamesizeof(adminname));
    if(
PlayerInfo[ID][AdminLevel] >= PlayerInfo[playerid][AdminLevel] && PlayerInfo[ID][AdminUC] == 0) return SendClientMessageToAll(playeridCOLOR_RED"Error: You cannot ban %s"IDname);
    new 
INI:File INI_Open(Path(playerid)); //Opening the user file
    
INI_WriteInt(File,"Banned",1);
    
INI_WriteString(File,"BannedBy"adminname);
    
INI_Close(File);
    if(
PlayerInfo[playerid][AdminUC] == 1);
    {
        
format(stringsizeof(string),"~You have been banned from the server. [Reason: %s]"reason);
        
SendClientMessage(IDCOLOR_GREENstring);
        
SaveToFile("BanLog"string);
        
SendClientMessageToAll(COLOR_RED"~ %s has been banned from the server. [Reason: %s]"IDnamereason);
    }
    else
    {
        
format(string,sizeof(string), "~You have been banned from the server by Administrator %s [Reason: %s]"adminnamereason);
        
SendClientMessage(IDCOLOR_GREENstring);
        
CMDMessageToAdmins(playerid"BAN");
        
SaveToFile("BanLog"string);
        
SendClientMessageToAll(COLOR_RED"~ %s has been banned from the server. [Reason: %s]"IDnamereason);
    }
    
PlayerInfo[ID][Banned] = reason;
    
PlayerInfo[ID][BannedBy] = adminname;
     return 
1;

Reply
#5

I've managed to get it down to 3 errors.

Код:
(483) : error 035: argument type mismatch (argument 2)
(488) : error 036: empty statement
(493) : warning 202: number of arguments does not match definition
(493) : warning 202: number of arguments does not match definition
(495) : error 029: invalid expression, assumed zero
(501) : warning 202: number of arguments does not match definition
(501) : warning 202: number of arguments does not match definition
Line 483 is
PHP код:
if(PlayerInfo[ID][AdminLevel] >= PlayerInfo[playerid][AdminLevel] && PlayerInfo[ID][AdminUC] == 0) return SendClientMessageToAll(playeridCOLOR_RED"Error: You cannot ban %s"IDname); 
493
PHP код:
        SendClientMessageToAll(COLOR_RED"~ %s has been banned from the server. [Reason: %s]"IDnamereason); 
495
PHP код:
    else 
and 501
PHP код:
SendClientMessageToAll(COLOR_RED"~ %s has been banned from the server. [Reason: %s]"IDnamereason); 
Reply
#6

I made the code little simple you were getting name too much times while you could do it in one line
PHP код:
CMD:ban(playeridparams[])
{
    new 
string[144], idreason[30]
    if(
PlayerInfo[playerid][AdminLevel] < 2)  return 0;
    if(
sscanf(params,"us[128]"idreason)) return SCM(playeridCOLOR_ADMIN"Usage: /ban [Player ID] [Reason]");
    if(
id == playerid) return SCM(playeridCOLOR_RED"Error: You IDIOT; you cannot ban yourself!");
    if(
AdminLevel[id] >= AdminLevel[playerid] && AdminUC[id] == 0) return SendPlayerFormattedText(playeridCOLOR_RED"Error: You cannot ban %s"pName(id));
    
INT_WriteInt(File,"Banned",1);
    
INT_WriteString(File,"BannedBy"pName(playerid));
    if(
AdminUC[playerid] == 0);
    {
        
format(string,sizeof(string), "~You have been banned from the server by Administrator %s [Reason: %s]"pName(playerid), reason);
        
SCM(idCOLOR_GREENstring)
        
CMDMessToAdmins(playerid"BAN");
        
SaveToFile("BanLog"string);
        
SendAllFormattedText(COLOR_RED"~ %s has been banned from the server. [Reason: %s]"pName(id,1), reason);
    }
    else
    {
        
format(stringsizeof(string),"~You have been banned from the server. [Reason: %s]"reason)
        
SCM(idCOLOR_GREENstring)
        
SaveToFile("BanLog"string);
        
SendAllFormattedText(COLOR_RED"~ %s has been banned from the server. [Reason: %s]"pName(id,1), reason);
    }
    
PlayerInfo[id][Banned] = reason;
    
PlayerInfo[id][BannedBy] = pName(playerid);
     return 
1;

This function is very helpful for getting player name and target name..
PHP код:
pName(playeridshowplayerid 0)
{
    new 
string[64], name[MAX_PLAYER_NAME];
    
GetPlayerName(playeridnamesizeof(name));
    if(
showplayerid != 0format(string64"%s (%d)"nameplayerid);
    else 
format(string64"%s"name);
    return 
string;

hope it works..
Reply
#7

Quote:
Originally Posted by gurmani11
Посмотреть сообщение
I made the code little simple you were getting name too much times while you could do it in one line
PHP код:
CMD:ban(playeridparams[])
{
    new 
string[144], idreason[30]
    if(
PlayerInfo[playerid][AdminLevel] < 2)  return 0;
    if(
sscanf(params,"us[128]"idreason)) return SCM(playeridCOLOR_ADMIN"Usage: /ban [Player ID] [Reason]");
    if(
id == playerid) return SCM(playeridCOLOR_RED"Error: You IDIOT; you cannot ban yourself!");
    if(
AdminLevel[id] >= AdminLevel[playerid] && AdminUC[id] == 0) return SendPlayerFormattedText(playeridCOLOR_RED"Error: You cannot ban %s"pName(id));
    
INT_WriteInt(File,"Banned",1);
    
INT_WriteString(File,"BannedBy"adminname);
    if(
AdminUC[playerid] == 0);
    {
        
format(string,sizeof(string), "~You have been banned from the server by Administrator %s [Reason: %s]"pName(playerid), reason);
        
SCM(idCOLOR_GREENstring)
        
CMDMessToAdmins(playerid"BAN");
        
SaveToFile("BanLog"string);
        
SendAllFormattedText(COLOR_RED"~ %s has been banned from the server. [Reason: %s]"pName(id,1), reason);
    }
    else
    {
        
format(stringsizeof(string),"~You have been banned from the server. [Reason: %s]"reason)
        
SCM(idCOLOR_GREENstring)
        
SaveToFile("BanLog"string);
        
SendAllFormattedText(COLOR_RED"~ %s has been banned from the server. [Reason: %s]"pName(id,1), reason);
    }
    
PlayerInfo[id][Banned] = reason;
    
PlayerInfo[id][BannedBy] = pName(playerid);
     return 
1;

This function is very helpful for getting player name and target name..
PHP код:
pName(playeridshowplayerid 0)
{
    new 
string[64], name[MAX_PLAYER_NAME];
    
GetPlayerName(playeridnamesizeof(name));
    if(
showplayerid != 0format(string64"%s (%d)"nameplayerid);
    else 
format(string64"%s"name);
    return 
string;

hope it works..
Thanks for your help, however I still get the same errors and warnings...
Reply
#8

You need to format those SendClientMessageToAll's
Reply
#9

Quote:
Originally Posted by Flake.
Посмотреть сообщение
You need to format those SendClientMessageToAll's
Did that now I've got
Код:
(473) : warning 202: number of arguments does not match definition
(478) : error 036: empty statement
(487) : error 029: invalid expression, assumed zero
Reply
#10

show those lines
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)