why this happens :(
#1

guys can you explain why this happens please?
i have the current code:
pawn Код:
if(strcmp(cmd, "/kick", true) ==0)
{
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "Only admins can use this command!");
    new
        id,
        reason[120];
        new pName[MAX_PLAYER_NAME];
        GetPlayerName(playerid,pName,sizeof(pName));
   new gname[MAX_PLAYER_NAME];
   GetPlayerName(id, gname, sizeof(gname));
    if (sscanf(cmd, "uz", id, reason)) return SendClientMessage(playerid, 0xFF0000AA, "Usage:/kick [id] [reason]");
    else if (id == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFF0000AA, "ERROR:This player isn't connected!");
    else
    {
       
           format(reason, sizeof(reason), "ADMIN KICK : %s has been kicked From The Server ( Reason : %d)",gname,reason);
           SendClientMessageToAll(COLOR_PINK, reason);
           Kick(id);
    }
    return 1;
}
but when i login and type /kick it is kicking me and for reason it has the id of the player was kicked :P
Reply
#2

new gname[MAX_PLAYER_NAME];
GetPlayerName(id, gname, sizeof(gname));
that has to be behind the sscanf.. otherwise you are getting the ID of "0" not sure if it fixes all your problems though
Reply
#3

I've changed your code a bit / optimized it ... Try this:

pawn Код:
if(strcmp(cmd, "/kick", true, 5) == 0)
{
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "Only admins can use this command!");
   
    new id, reason[120];
    new pName[24], gname[24];
   
    GetPlayerName(playerid,pName,sizeof(pName));
    GetPlayerName(id, gname, sizeof(gname));

    if(sscanf(cmd, "us[120]", id, reason)) return SendClientMessage(playerid, 0xFF0000AA, "Usage:/kick [id] [reason]");
    if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFF0000AA, "ERROR:This player isn't connected!");

    format(reason, sizeof(reason), "ADMIN KICK : %s has been kicked From The Server ( Reason : %d )",gname,reason);
    SendClientMessageToAll(COLOR_PINK, reason);
    Kick(id);

    return 1;
}
Reply
#4

ITS Not working otto ( it sends now : "/kick [id] [reason] ((( please help me
Reply
#5

Quote:
Originally Posted by grand.Theft.Otto
Посмотреть сообщение
pawn Код:
new id, reason[120];
    new pName[24], gname[24];
   
    GetPlayerName(playerid,pName,sizeof(pName));
    GetPlayerName(id, gname, sizeof(gname));

    if(sscanf(cmd, "us[120]", id, reason)) return SendClientMessage(playerid, 0xFF0000AA, "Usage:/kick [id] [reason]");
Can you explain how that would work? You cannot get the other player's name before actually parsing the input with sscanf. And most likely there's no need to get the player's name before parsing it, it might turn out useless.

The major issue this is caused by is what sscanf is trying to parse!
What your code is attempting to do is: sscanf("/kick 0 REASON", "us[120]", ...)
However you should aim to do: sscanf("0 REASON", "us[120]", ...)

You need to exclude the "/kick " part first. It is best for you to switch to using ZCMD rather than for me to explain how and why exactly it needs to be done. The params[] in ZCMD commands doesn't have the command prefix anymore.
Reply
#6

can you post it here in [pawn][ /pawn] please?
Reply
#7

pawn Код:
if(strcmp(cmd, "/kick", true, 5) == 0)
{
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "Only admins can use this command!");
   
    new id, reason[120];
    new pName[24], gname[24];
   
    GetPlayerName(playerid,pName,sizeof(pName));

    if(sscanf(cmd, "{s[5]}us[120]", id, reason)) return SendClientMessage(playerid, 0xFF0000AA, "Usage:/kick [id] [reason]");
    if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFF0000AA, "ERROR:This player isn't connected!");
    GetPlayerName(id, gname, sizeof(gname));
    format(reason, sizeof(reason), "ADMIN KICK : %s has been kicked From The Server ( Reason : %d )",gname,reason);
    SendClientMessageToAll(COLOR_PINK, reason);
    Kick(id);

    return 1;
}
like that maybe
Reply
#8

Well, I am not sure, maybe this I will tell it's stupid, but I dont think that sscanf can work with strcmp.
Also,
pawn Код:
if(sscanf(cmd, "{s[5]}us[120]", id, reason)) return SendClientMessage(playerid, 0xFF0000AA, "Usage:/kick [id] [reason]");
    if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFF0000AA, "ERROR:This player isn't connected!");
Should be:
pawn Код:
if(sscanf(cmd, "{s[5]}us[120]", id, reason)) return SendClientMessage(playerid, 0xFF0000AA, "Usage:/kick [id] [reason]");
    else if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFF0000AA, "ERROR:This player isn't connected!");
Reply
#9

Omng people look into last format:
format(reason, sizeof(reason), "ADMIN KICK : %s has been kicked From The Server ( Reason : %d)",gname,reason);

Reason is string so replace %d with %s
Reply
#10

Maybe try:

pawn Код:
if (sscanf(cmd, "is", id, reason))
iso:

pawn Код:
if (sscanf(cmd, "uz", id, reason))
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)