My /warn command kick ppl
#1

i use /warn <id> and its kicking player, help

pawn Код:
CMD:warn(playerid, params[])
{
        if (PlayerInfo[playerid][pAdmin] < 3 && !IsPlayerAdmin(playerid)) return SendClientMessage( playerid, -1, "You Must Be Level 2 To Use This Command");

        new ID, R[200], string[100];
        new WarnC[MAX_PLAYERS];
        new name[MAX_PLAYER_NAME], name2[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        GetPlayerName(ID, name2, sizeof(name2));
        if(sscanf(params, "is[200]", ID, R)) return SendClientMessage(playerid, 0xFF0000AA, "USAGE: /warn [playerid] [Reason]");
        {
            if(WarnC[ID] == 3) return KickPlayer(ID);
            {
                  format(string, sizeof(string), "Administrator %s (%d) Has Kicked %s (%d) For Reason : %s (Warning : %d/3)", name,playerid,name2,ID,R,WarnC);
                  SendClientMessageToAll(0xFF1493FF, string);
                  KickPlayer(ID);
            }
            if(ID != INVALID_PLAYER_ID)
            {
                {
                   format(string, sizeof(string), "Administrator %s (%d) Has Warned %s (%d) For Reason : %s (Warning : %d/3)", name,playerid,name2,ID,R,WarnC);
                   SendClientMessageToAll(0xFF1493FF, string);
                   WarnC[ID]++;
                }
            }
            else SendClientMessage(playerid, 0xFF0000AA, "ID Not Connected.");
        }
        return 1;
}
Reply
#2

Copy [NWA]Hannes code
Reply
#3

- It's impossible the reason to be 200 so reduce it to 100 or even lower.
- You shouldn't declare WarnC inside the command but it should be global instead (don't forget to set it to 0 on connect for each player).
- Get the name of the player after the sscanf has been used otherwise it will get the name of the player with ID 0.
- Check if ID is not INVALID_PLAYER_ID before using ID into WarnC or else it will cause run time error 4 if the player is invalid.
Reply
#4

First move the WarnC[id]++; variable to the top of your script.
pawn Код:
//Defines and other stuff

new WarnC[MAX_PLAYERS];

//GameModeInit
Then reset it under OnPlayerConnect and OnPlayerDisconnect(optionally)
pawn Код:
//Under OnPlayerConnect
WarnC[playerid] = 0;

//Under OnPlayerDisconnect
WarnC[playerid] = 0;
Then change a few things in your command
pawn Код:
CMD:warn(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] < 3 && !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You Must Be Level 2 To Use This Command.");
       
    new ID, R[100], string[128];
    if(sscanf(params, "is[100]", ID, R)) return SendClientMessage(playerid, 0xFF0000AA, "USAGE: /warn [playerid] [Reason]");
    {
        new name[MAX_PLAYER_NAME], name2[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        GetPlayerName(ID, name2, sizeof(name2));

        if(IsPlayerConnected(ID) && ID != INVALID_PLAYER_ID)
        {
            WarnC[ID]++;
            if(WarnC[ID] == 1 || WarnC[ID] == 2)
            {
                format(string, sizeof(string), "Administrator %s (%d) Has Warned %s (%d) For Reason : %s (Warning : %d/3)", name,playerid,name2,ID,R,WarnC[ID]);
                SendClientMessageToAll(0xFF1493FF, string);
            }
            if(WarnC[ID] == 3)
            {
                format(string, sizeof(string), "Administrator %s (%d) Has Kicked %s (%d) For Reason : %s (Warning : %d/3)", name,playerid,name2,ID,R,WarnC[ID]);
                SendClientMessageToAll(0xFF1493FF, string);
                KickPlayer(ID);
            }
        }
        else return SendClientMessage(playerid, 0xFF0000AA, "ID Not Connected.");
    }
    return 1;
}
Reply
#5

its 3nd warn
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)