/kick problem
#1

Well, I am making a /kick command using zcmd and I can't basically find out the problem myself. I've been trying to figure it out, but no results.

Here's the pawn code...

pawn Код:
CMD:kick(playerid, params[])
{
  if (GetPVarInt(playerid, "Level") < 2 )
  new PlayerID[MAX_PLAYER_NAME], reason[64], str[128];
  new PlayerName[MAX_PLAYER_NAME], AdminName[MAX_PLAYER_NAME];
  GetPlayerName(playerid, AdminName, sizeof(AdminName));
  GetPlayerName(PlayerID, PlayerName, sizeof(PlayerName));
  if(sscanf(params, "us[64]", PID,reason)) return SendClientMessage(playerid, COLOR_IRAQ, "USAGE: {FFFFFF}/kick [PlayerID] [Reason]");
  if(!IsPlayerConnected(PID)) return SendClientMessage(playerid, COLOR_RED, "ERROR: {ffffff}Invalid player ID.");
  format(str, sizeof(str), "%s has been kicked by %s for %s", PlayerName, AdminName, reason);
  SendClientMessageToAll(COLOR_RED, str);

  Kick(playerid);
  return 1;
}

...- and here's the error message:

Код:
.pwn(1471) : error 003: declaration of a local variable must appear in a compound block
.pwn(1471) : error 029: invalid expression, assumed zero
.pwn(1471) : error 017: undefined symbol "reason"
.pwn(1471) : fatal error 107: too many error messages on one line
Reply
#2

Here's your actual issue, my friend:
pawn Код:
error 003: declaration of a local variable must appear in a compound block
To declare a local variable, the previous if statement has to form a compound block: that means, the following code should be put between brackets: { and }.

Change your code so that it looks like this:
pawn Код:
CMD:kick(playerid, params[])
{
    if (GetPVarInt(playerid, "Level") < 2 )
    {
        new PlayerID[MAX_PLAYER_NAME], reason[64], str[128];
        new PlayerName[MAX_PLAYER_NAME], AdminName[MAX_PLAYER_NAME];
        GetPlayerName(playerid, AdminName, sizeof(AdminName));
        GetPlayerName(PlayerID, PlayerName, sizeof(PlayerName));
        if(sscanf(params, "us[64]", PID,reason)) return SendClientMessage(playerid, COLOR_IRAQ, "USAGE: {FFFFFF}/kick [PlayerID] [Reason]");
        if(!IsPlayerConnected(PID)) return SendClientMessage(playerid, COLOR_RED, "ERROR: {ffffff}Invalid player ID.");
        format(str, sizeof(str), "%s has been kicked by %s for %s", PlayerName, AdminName, reason);
        SendClientMessageToAll(COLOR_RED, str);
        Kick(playerid);
    }
    return 1;
}
Reply
#3

Quote:

CMD:kick(playerid,params[])
{
new id,name1[MAX_PLAYER_NAME], reason[35],name2[MAX_PLAYER_NAME], string[128];
if(PlayerInfo[playerid][pAdmin] < 1) return SCM(playerid, COLOR_WHITE,"You are not authorized to use this command");
if(sscanf(params,"uz",id,reason)) return SCM(playerid, COLOR_WHITE,"USAGE: /kick [playerid/partofname] [reason]");
if(!IsPlayerConnected(id)) return SCM(playerid, COLOR_WHITE,"Invalid player id");
else
{
GetPlayerName(playerid,name1,sizeof(name1));
GetPlayerName(id,name2,sizeof(name2));
format(string, sizeof(string),"AdmCmd: %s was kicked by %s, reason: %s",name2,name1,reason);
SendClientMessageToAll(COLOR_LIGHTRED,string);
Kick(id);
}
return 1;
}

MY CMD, just edit the admin level or w/e, works fine for me
Reply
#4

figured out the problem thanks folks
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)