SA-MP Forums Archive
Something wrong with ban commands - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Something wrong with ban commands (/showthread.php?tid=226454)



Something wrong with ban commands - Libra_PL - 15.02.2011

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;
}



Re: Something wrong with ban commands - Unknown123 - 15.02.2011

Please use sscanf... makes the job more easy...


Re: Something wrong with ban commands - Ultima - 15.02.2011

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.


Re: Something wrong with ban commands - Mean - 15.02.2011

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!" );



Re: Something wrong with ban commands - Libra_PL - 16.02.2011

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!


Re: Something wrong with ban commands - _Tommy - 16.02.2011

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


Re: Something wrong with ban commands - Unknown123 - 16.02.2011

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!");
}