Something wrong with ban commands
#1

Hello, sorry again for asking questions But I kinda need help with /ban command. When I type "/ban 0" (my ID), it says "ERROR: You must give a reason!". It's ok. But if I add any reason (example "test") it says player is not connected. I used ID 0, it's mine ID. Could anyone solve this? Beer is waiting!

Код:
dcmd_ban(playerid,params[]) {
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, red, "ERROR: You must to be an admin before using this command!");
	new tmp[256], tmp2[256], Index; tmp = strtok(params,Index), tmp2 = strtok(params,Index);
	if(!strlen(params)) return SendClientMessage(playerid, red, "USAGE: /ban [playerid] [reason]");
	if(!strlen(tmp2)) return SendClientMessage(playerid, red, "ERROR: You must give a reason!");
	new player1, playername[MAX_PLAYER_NAME], adminname[MAX_PLAYER_NAME], string[128];
	player1 = strval(tmp);
		if(IsPlayerConnected(player1) && player1 != INVALID_PLAYER_ID && player1 != playerid) {
		GetPlayerName(player1, playername, sizeof(playername)); GetPlayerName(playerid, adminname, sizeof(adminname));
		format(string,sizeof(string),"%s has been banned by Administrator %s (Reason: %s)",playername,adminname,params[2]);
		SendClientMessageToAll(red,string);
		BanEx(player1, string);
	} else return SendClientMessage(playerid, red, "ERROR: Player is not connected!");
	return 1;
}
Reply
#2

Please use sscanf... makes the job more easy...
Reply
#3

Quote:
Originally Posted by Unknown123
Посмотреть сообщение
Please use sscanf... makes the job more easy...
If you wont offer any guy help, why the hell should you bullpost about using sscanf?

@ OP
Sorry mate, but i can't help as im not into dcmd etc, i just wanted to reply to the guy that replied.
Reply
#4

Not sure, but:
pawn Код:
if( !strlen( tmp ) ) return SendClientMessage( playerid, red, "USAGE: /ban [playerid] [reason]" ); // This is what I've changed
if( !strlen( tmp2 ) ) return SendClientMessage( playerid, red, "ERROR: You must give a reason!" );
Reply
#5

Quote:
Originally Posted by Mean
Посмотреть сообщение
Not sure, but:
pawn Код:
if( !strlen( tmp ) ) return SendClientMessage( playerid, red, "USAGE: /ban [playerid] [reason]" ); // This is what I've changed
if( !strlen( tmp2 ) ) return SendClientMessage( playerid, red, "ERROR: You must give a reason!" );
Still same problem.

Unknown123, yeah, I would use sscanf, but I don't know how to use it (I downloaded it yesterday).

If someone is a good person, he could change it to sscanf? Beer still waiting!
Reply
#6

pawn Код:
&& player1 != playerid
Ofcourse it tells you that the player is not connected. You can not ban yourself.
Reply
#7

Quote:
Originally Posted by Ultima
Посмотреть сообщение
If you wont offer any guy help, why the hell should you bullpost about using sscanf?

@ OP
Sorry mate, but i can't help as im not into dcmd etc, i just wanted to reply to the guy that replied.
I acctualy offred help to him... I told him to use sscanf, that would help him because sscanf if 85%++ much easier... So actually your post is "bullpost" (Think before you post...)
Just look here (This should work, using 'sscanf2' plugin):

pawn Код:
//#include <sscanf2>

dcmd_ban(playerid, params[])
{
    if(!IsPlayerAdmin(playerid))
    {
        new targetid, reason[128];
        if(sscanf(params, "us[128]", targetid, reason)) return SendClientMessage(playerid, red, "USAGE: /ban [playerid] [reason]");
        else if(IsPlayerConnected(targetid)) return SendClientMessage(playerid, red, "ERROR: Player is not connected!");
        {
            new playername[MAX_PLAYER_NAME], targetname[MAX_PLAYER_NAME], string[128];
            GetPlayerName(playerid, playername, sizeof(playername));
            GetPlayerName(targetid, targetname, sizeof(targetname));
           
            format(string,sizeof(string),"%s has been banned by Administrator %s (Reason: %s)",targetname, playername, reason);
            SendClientMessageToAll(red,string);
           
            BanEx(targetid, reason);
        }
    }
    else return  SendClientMessage(playerid, red, "ERROR: You must to be an admin before using this command!");
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)