Only ID 1 + can use ban..
#1

Hello, I have a problem. If an admin is ID 0, they cant use the ban command, it returns "You cannot kick yourself" but, they're putting someone elses id.

Code:
http://pastebin.com/f61a8f944

Thanks
Reply
#2

Try not to use "params" for the reason-string, also you should use "z" instead of "s" for reasons, because admins don't type reasons all the time. "z" makes it an optional string parameter.
Reply
#3

Quote:
Originally Posted by player007
Try not to use "params" for the reason-string, also you should use "z" instead of "s" for reasons, because admins don't type reasons all the time. "z" makes it an optional string parameter.
I tried not using params, but then reason doesn't work at all.
Reply
#4

Try this code:
pawn Код:
dcmd_ban(playerid, params[])
{
    new
        TargetID,
        reason[128];
    if (sscanf(params, "uz", TargetID, reason) != 0)
    {
        SendClientMessage(playerid, COLOR_SERVER, "Usage: /ban <player's name or ID> <reason>");
        return 1;
    }
    if (IsPlayerConnected(TargetID))
    {
        if (strlen(reason) > 0)
        {
            // ClientMessage:
            // XY has banned XYZ, reason: blabla.
        }
        else
        {
            // ClientMessage:
            // XY has banned XYZ, [no reason given]
        }
        SetPlayerPos(TargetID, 10000.0, 10000.0, 10000.0);
        ResetPlayerWeapons(TargetID);
        GivePlayerWeapon(TargetID, 10,1);
        SetPlayerWeather(TargetID, 150);
        SetPlayerSkin(TargetID, 77);
        BanEx(TargetID, reason);
    }
    else
    {
        SendClientMessage(playerid, COLOR_SERVER, "[FAILURE] Invalid playerid.");
    }
    return 1;
}
Reply
#5

Quote:
Originally Posted by player007
Try this code:
pawn Код:
dcmd_ban(playerid, params[])
{
    new
        TargetID,
        reason[128];
    if (sscanf(params, "uz", TargetID, reason) != 0)
    {
        SendClientMessage(playerid, COLOR_SERVER, "Usage: /ban <player's name or ID> <reason>");
        return 1;
    }
    if (IsPlayerConnected(TargetID))
    {
        if (strlen(reason) > 0)
        {
            // ClientMessage:
            // XY has banned XYZ, reason: blabla.
        }
        else
        {
            // ClientMessage:
            // XY has banned XYZ, [no reason given]
        }
        SetPlayerPos(TargetID, 10000.0, 10000.0, 10000.0);
        ResetPlayerWeapons(TargetID);
        GivePlayerWeapon(TargetID, 10,1);
        SetPlayerWeather(TargetID, 150);
        SetPlayerSkin(TargetID, 77);
        BanEx(TargetID, reason);
    }
    else
    {
        SendClientMessage(playerid, COLOR_SERVER, "[FAILURE] Invalid playerid.");
    }
    return 1;
}
Hey, I'm getting a warning "loose indentation" but its not loose.. (line that im getting it on is commented.)

http://pastebin.com/f7fca6de5
Reply
#6

It is loose, look at it, correct one here:
pawn Код:
dcmd_ban(playerid,params[])
{
    new
        TargetID,
        reason[128];
    if(pInfo[playerid][Level] < 3) return SendClientMessage(playerid,COLOR_RED,"You must be level 3 to ban someone!");
    if(playerid == TargetID)
    {
        SendClientMessage(playerid, COLOR_RED, "ERROR: You cannot ban yourself.");
        return 1;
    }
    if (sscanf(params, "uz", TargetID, reason) != 0)
    {
        SendClientMessage(playerid, COLOR_WHITE, "Usage: /ban (id/name) [reason]");
        return 1;
    }
    if (IsPlayerConnected(TargetID))
    {
        if (strlen(reason) > 0)
        {
            new string[128];
            format(string,128,"%s(%d) has been banned by %s(%d). Reason [%s]",ReturnPlayerName(TargetID),TargetID,ReturnPlayerName(playerid),playerid,reason);
            SendClientMessageToAll(COLOR_RED,string);
        }
        else
        {
            new string[128];
            format(string,128,"%s(%d) has been banned by %s(%d). Reason [no reason]",ReturnPlayerName(TargetID),TargetID,ReturnPlayerName(playerid),playerid);
            SendClientMessageToAll(COLOR_RED,string);
        }
        SetPlayerPos(TargetID,10000,10000,10000);
        ResetPlayerWeapons(TargetID);
        GivePlayerWeapon(TargetID,10,1);
        SetPlayerWeather(TargetID,150);
        SetPlayerSkin(TargetID,77);
        BanEx(TargetID,reason);
    }
    else
    {
      SendClientMessage(playerid,COLOR_RED,"ERROR: Invalid ID!");
    }
    return 1;
}
Reply
#7

Quote:
Originally Posted by player007
It is loose, look at it, correct one here:
pawn Код:
dcmd_ban(playerid,params[])
{
    new
        TargetID,
        reason[128];
    if(pInfo[playerid][Level] < 3) return SendClientMessage(playerid,COLOR_RED,"You must be level 3 to ban someone!");
    if(playerid == TargetID)
    {
        SendClientMessage(playerid, COLOR_RED, "ERROR: You cannot ban yourself.");
        return 1;
    }
    if (sscanf(params, "uz", TargetID, reason) != 0)
    {
        SendClientMessage(playerid, COLOR_WHITE, "Usage: /ban (id/name) [reason]");
        return 1;
    }
    if (IsPlayerConnected(TargetID))
    {
        if (strlen(reason) > 0)
        {
            new string[128];
            format(string,128,"%s(%d) has been banned by %s(%d). Reason [%s]",ReturnPlayerName(TargetID),TargetID,ReturnPlayerName(playerid),playerid,reason);
            SendClientMessageToAll(COLOR_RED,string);
        }
        else
        {
            new string[128];
            format(string,128,"%s(%d) has been banned by %s(%d). Reason [no reason]",ReturnPlayerName(TargetID),TargetID,ReturnPlayerName(playerid),playerid);
            SendClientMessageToAll(COLOR_RED,string);
        }
        SetPlayerPos(TargetID,10000,10000,10000);
        ResetPlayerWeapons(TargetID);
        GivePlayerWeapon(TargetID,10,1);
        SetPlayerWeather(TargetID,150);
        SetPlayerSkin(TargetID,77);
        BanEx(TargetID,reason);
    }
    else
    {
      SendClientMessage(playerid,COLOR_RED,"ERROR: Invalid ID!");
    }
    return 1;
}
Oh :P thanks.
Reply
#8

I've gotten it to comile, but Im having the same problem, it doesnt work for id 0.
Reply
#9

Now I know why !
You have a bad order of code, the "playerid == TargetID" check is actually done before sscanf, so it is always 0, as newly created variables will always be set to 0 by default.
Therefore the check is like "if playerid (which is 0, because only you are in the test server) is equal to 0"
Bottom line, use this order:
pawn Код:
if (sscanf(params, "uz", TargetID, reason) != 0)
    {
        SendClientMessage(playerid, COLOR_WHITE, "Usage: /ban (id/name) [reason]");
        return 1;
    }
    if(playerid == TargetID)
    {
        SendClientMessage(playerid, COLOR_RED, "ERROR: You cannot ban yourself.");
        return 1;
    }
Reply
#10

Quote:
Originally Posted by player007
Now I know why !
You have a bad order of code, the "playerid == TargetID" check is actually done before sscanf, so it is always 0, as newly created variables will always be set to 0 by default.
Therefore the check is like "if playerid (which is 0, because only you are in the test server) is equal to 0"
Bottom line, use this order:
pawn Код:
if (sscanf(params, "uz", TargetID, reason) != 0)
    {
        SendClientMessage(playerid, COLOR_WHITE, "Usage: /ban (id/name) [reason]");
        return 1;
    }
    if(playerid == TargetID)
    {
        SendClientMessage(playerid, COLOR_RED, "ERROR: You cannot ban yourself.");
        return 1;
    }
Would this work?

pawn Код:
dcmd_ban(playerid,params[])
{
    new giveplayerid,string[128], name[24];
    if(pInfo[playerid][Level] < 3) return SendClientMessage(playerid,COLOR_RED,"You must be level 3 to ban someone!");
    if(sscanf(params,"uz",giveplayerid,params)) return SendClientMessage(playerid,COLOR_WHITE,"Usage: /ban (id) [reason]");
    if(giveplayerid == playerid) return SendClientMessage(playerid,COLOR_RED,"ERROR: You cannot ban yourself.");
    if(!IsPlayerConnected(giveplayerid)) return SendClientMessage(playerid,COLOR_RED,"ERROR: Invalid ID!");

    GetPlayerName(giveplayerid, name,sizeof(name));
    format(string,128,"%s(%d) has been banned by %s(%d). [Reason: %s]",name,giveplayerid,ReturnPlayerName(playerid),playerid,params);
    SendClientMessageToAll(COLOR_RED,string);
    SendClientMessage(giveplayerid,COLOR_RED,"SERVER: You have been banned from the server.");

    ResetPlayerWeapons(giveplayerid);
    GivePlayerWeapon(giveplayerid,10,1);
    SetPlayerWeather(giveplayerid,150);
    SetPlayerSkin(giveplayerid,77);
    BanEx(giveplayerid,params);
    return 1;
}
Also, my kick command was exactly like my first posted ban command (first post), accept i made it ban instead of kick, and the kick works fine :P
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)