What I did wrong? :S
#1

I was trying to make /kick [id] [Reason] command with zcmd but i failed,I wish someone will help me...

pawn Код:
COMMAND:kick(playerid,params[] )
{
    new name[MAX_PLAYER_NAME];
    new giveplayerid;
    GetPlayerName(playerid, name, sizeof(name)); // pretty self-explanatory
    if (PlayerInfo[playerid][pAdminLevel] >=2 || IsPlayerAdmin(playerid))
            {
            if(giveplayerid != INVALID_PLAYER_ID)  // if the player is online
                {
                new string[128];
                GetPlayerName(playerid, name, sizeof(name));
                format(string,sizeof(string),"%s has been kicked by %s, Reason: %s ");
                SendClientMessageToAll(0xFFFFFFF,string);
                return Kick(playerid); // returns the command to kick the player
                }
            }
            else
                SendClientMessage(playerid, COLOR_RED, "[ERROR:] Invalid ID.");
    else
        SendClientMessage(playerid, COLOR_RED, "[ERROR:] You are not an admin!");
    return 1;
}
Reply
#2

What errors are you getting?
Reply
#3

Nvm....I deleted it. I found out i need sscanf for it but sscanf dont like my computer
So now i will try on rCmd
Reply
#4

You don't really need sscanf for it.. This is how it should be:
pawn Код:
CMD:kick(playerid,params[])
{
    new name[MAX_PLAYER_NAME], name2[MAX_PLAYER_NAME], string[110], idx;
    GetPlayerName(playerid, name, sizeof(name));
    if(PlayerInfo[playerid][pAdminLevel] >=2 || IsPlayerAdmin(playerid))
        {
        string = strtok(params, idx);
        if(!strlen(string))
            {
            SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /kick [id] [reason]");
            return 1;
            }
        new giveplayerid = string;
        string = strtok(params, idx);
        if(!strlen(string))
            {
            SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /kick [id] [reason]");
            return 1;
            }
        if(IsPlayerConnected(giveplayerid))
            {
            new Text[110] = string
            GetPlayerName(giveplayerid, name2, sizeof(name2));
            format(string,sizeof(string),"%s has been kicked by %s, reason: %s", name2, name, text);
            SendClientMessageToAll(0xFFFFFFF,string);
            Kick(giveplayerid);
            }
        else return SendClientMessage(playerid, COLOR_RED, "[ERROR:] That ID is not connected!");
        }
    else return SendClientMessage(playerid, COLOR_RED, "[ERROR:] You are not an Admin!");
    return 1;
}
I hope it helped.

Best regards,
Jesse
Reply
#5

Thanks Jesse
Reply
#6

LOL I can also see that you did this: Kick(playerid); While playerid is the player who executes the command, it should have been giveplayerid .
Also, you have not done format well as well as the GetPlayerName.
I know you got it fixed but just pointing the things out.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)