zcmd kick command
#1

Hey. I am creating a kick command with zcmds. The kick itself seems to be working fine. Just the message it's supposed to send is quite messy and I really don't know how to continue.
pawn Код:
COMMAND:kick(playerid, params[]) //using ZCMD this is how your command will start off looking like.
{
    if(PlayerInfo[playerid][pAdminlevel] >= 1) // player level more (>) 0
    {
        new otherplayerid, reason[128];
        if(sscanf(params, "uz", otherplayerid, reason)) // split input string and check level value 0 to 5
            SendClientMessage(playerid, 0xFFFFFFFF, "/kick [playerid/name] [reason]");
        else if(otherplayerid == INVALID_PLAYER_ID) // Check player connected
            SendClientMessage(playerid, 0xFFFFFFFF, "This player is not connected");
        else
        {
            new string[32];
            format(string, sizeof(string), "Admin %s kicked %s | Reason: %s", GetPlayerNameEx(playerid), GetPlayerNameEx(otherplayerid), reason);
            SendClientMessageToAll(0xFFFFFFFF,string);
            Kick(otherplayerid);
        }
    }
    else
    {
        SendClientMessage(playerid, 0xAAAAAAAA, "You are not admin or the required level.");
    }
    return 1;
}
An other question.. at first I used "s" in the code below instead of "z", can someone explain why I have put "z" there? I just copied it somewhere and didn't really understand why I put it there.
pawn Код:
if(sscanf(params, "uz", otherplayerid, reason))
I am aware what u means.
Reply
#2

Solution here
Reply
#3

Don't take me for an idiot. I have obviously been looking there, I always do search and whatnot. But when it comes to the point where I can't find the solution myself. I ask here. After all we are in the Script Discussion section.
Reply
#4

First, if you are using plugin:

Quote:

What happened to "z", the optional string? z has been removed (you can still use it but will get a server warning) to make way for the new optional parameter system described later on.

so, you need change z to s, like..

new id, string[ 128 ];
sscanf( params, "us[128]", id, string ) ) ...

[128] - lenght of ur string.

and your command can be MUCH longer:

pawn Код:
COMMAND:kick( playerid, params[ ] )
{
    if( PlayerInfo[ playerid ][ pAdminLevel ] == 0 ) return SendClientMessage( playerid, 0xAAAAAAAA, "You are not admin or the required level." );
    new
        ID,
        Reason[ 101 ]
    ;
    if( sscanf( params, "us[101]", ID, Reason ) ) return SendClientMessage( playerid, 0xFFFFFFFF, "/kick [playerid/name] [reason]" );
    if( ID == INVALID_PLAYER_ID || ID == playerid ) return SendClientMessage( playerid, 0xFFFFFFFF, "This player is not connected" );
    if( strlen( Reason ) > 100 ) return SendClientMessage( playerid, 0xFFFFFFFF, "Reason is too long.. [Max chars - 100]" );
    new
        String[ 188 ]
    ;
    format( String, 188, "Admin %s kicked kicked %s. | Reason: %s", GetPlayerNameEx( playerid ), GetPlayerNameEx( ID ), Reason );
    SendClientMessageToAll( 0xFFFFFFFF, String );
    Kick( ID );
    return true;
}
Reply
#5

Thanks for your answer. I tried it but when I try kicking myself it returns the following;
Код:
[12:38:23] Admin Otto Kling kicked Otto Kl
[12:38:23] Server closed the connection.
As you can see the message is not complete.

EDIT: Testing your code.

EDIT 2: Your code doesn't work, it only returns "This player is not connected", doesn't matter what I type. Probably something simple needed to be adjusted. I will try if I can find it myself if not I'd appreciate some help.

EDIT 3: Didn't found a solution to his code but I find it to my code. I just changed the string[32] to string[100]. Too easy.
Reply
#6

Then from this line:

pawn Код:
if( ID == INVALID_PLAYER_ID || ID == playerid )
Remove the "ID == playerid", if you want to test by kicking yourself.
Reply
#7

Ah yeah, obviously, thank you.
Reply
#8

pawn Код:
COMMAND:kick(playerid, params[])
{
    new pid;
    if(PlayerInfo[playerid][pAdminlevel] >= 1)
    {
        if(sscanf(params, "us[128]", pid, params[2])) return SendClientMessage(playerid,  0xFFFFFFFF, "/kick [playerid/name] [reason]");
        if(!IsPlayerConnected(pid)) return SendClientMessage(playerid, 0xFFFFFFFF, "This player is not connected");
        new adminname[MAX_PLAYER_NAME], paramname[MAX_PLAYER_NAME], string[180];
        GetPlayerName(pid, paramname, sizeof(paramname));
        GetPlayerName(playerid, adminname, sizeof(adminname));
        format(string, sizeof(string), "%s has been kicked by %s for: %s", paramname, adminname, params[2]);
        SendClientMessageToAll(AdminColor, string);
        Kick(pid);
    } else if(PlayerInfo[playerid][pAdminLevel] == 0) return SendClientMessage(playerid, 0xAAAAAAAA, "You are not admin or the required level.");
    return 1;
}
Try this

EDIT: nvm
Reply
#9

pawn Код:
COMMAND:kick(playerid, params[])
{
    new pid, reason[105];
    if(PlayerInfo[playerid][pAdminlevel] >= 1) return SendClientMessage(playerid, 0xAAAAAAAA, "You are not admin or the required level.");
    if(sscanf(params, "uS(No Reason Given)[128]", pid, reason)) return SendClientMessage(playerid,  0xFFFFFFFF, "/kick [playerid/name] [reason]");
    if(IsPlayerConnected(pid) && pid != INVALID_PLAYER_ID && pid != playerid)
    {
        new adminname[MAX_PLAYER_NAME], paramname[MAX_PLAYER_NAME], string[180];
        GetPlayerName(pid, paramname, sizeof(paramname));
        GetPlayerName(playerid, adminname, sizeof(adminname));
        format(string, sizeof(string), "%s has been kicked by %s for: %s", paramname, adminname, reason);
        SendClientMessageToAll(AdminColor, string);
        Kick(pid);
    }
    else return SendClientMessage(playerid, 0xFFFFFFFF, "This player is not connected Or Is Yourself.");
    return 1;
}
Edit: i've added optnl reason.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)