Multiple Player Kicks?
#1

As most scripters know and/or server owners know, the kick command is quite useful. In the past, many servers just use a kicking command, to kick 1 player at once, instead of other players...

So I am here to ask:

Is it possible to do, such as:
/kick 19 34 23 (19 , 34, 23 = different players' ids)

And it will kick them all? If it is, mind making it for me? I am clueless
Reply
#2

You could use dcmd and sscanf. Make the first parameter required and then maybe like 5 other ones optional so you could just type them all in.
Reply
#3

It's untested, and I doubt it'll work, but it's worth a try. Make sure to change the 10 that declares the array and the number inside the sscanf line to what you'd want the max kicks to be.

The problem I'm worried about is sscanf isn't going to allow parsing those extra values, in case you don't type them all, and just give an error and abort the operation. If my thinking is correct, this will not work. However, like I said, it's worth a shot.

pawn Code:
COMMAND:kicks( playerid, params[ ] )
{
    if( !IsPlayerAdmin( playerid ) ) return 0;
    new kicks[ 10 ] = { -1, ... };
    sscanf( params, "a<i>[10]", kicks );
    for( new i = 0; i < sizeof( kicks ); i++ )
    {
        if( kicks[ i ] != -1 )
        {
            KickPlayer( kicks[ i ] );
        }
    }
    return 1;
}
Reply
#4

You can try:
pawn Code:
stock KickEx(...)
{
    for(new i = 0; i != numargs(); ++i)
    {
        if(IsPlayerConnected(getarg(i)) Kick(getarg(i));
    }
    return 1;
}

// Usage: KickEx(1, 2, 6, 7, 25, 52, 125, 252, 450);
Reply
#5

Quote:
Originally Posted by [L3th4l]
View Post
You can try:
pawn Code:
stock KickEx(...)
{
    for(new i = 0; i != numargs(); ++i)
    {
        if(IsPlayerConnected(getarg(i)) Kick(getarg(i));
    }
    return 1;
}

// Usage: KickEx(1, 2, 6, 7, 25, 52, 125, 252, 450);
That was going to be my first response, but he needs a way to implement that function into a command.

It would be nice if sscanf had an option (or maybe it does and I've overlooked it) to parse an unknown amount of values into an array.
Reply
#6

Lol, you guys are speaking another language.. lol

Thanks for the help, I was just asking if it was possible.. I see now it is, so I will test your guys' scripts, and see if they work. If not, I might see if I can do some tweaking.

Thanks for the time, you put into this guys.
Reply
#7

pawn Code:
CMD:kicks(playerid, params[])
{
    new id, bool:num;
    for(new i=0; params[i]; i++)
    {
        if('0' <= params[i] <= '9')
        {
            num = true;
            id = (id * 10) + (params[i] - '0'); // credits to Y_Less for sscanf
        }
        else
        {
            if(num && IsPlayerConnected(id))
            {
                SendClientMessage(id, -1, "You are kicked");
                Kick(id);
            }
            num = false;
            id = 0;
        }
    }
    return 1;
}
Reply
#8

Quote:
Originally Posted by Grim_
View Post
It would be nice if sscanf had an option (or maybe it does and I've overlooked it) to parse an unknown amount of values into an array.
It has that option. I actually made this code a few days ago:
pawn Code:
new
    id[10];
sscanf(params, "A<u>(0xFFFF)[10]", id);
You can enter up to 10 optional user names/ids. The default value will be INVALID_PLAYER_ID (or 0xFFFF).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)