Problem with INVALID_PLAYER_ID
#1

INVALID_PLAYER_ID doesn't seem to be working right.

I've got this command, along with heaps others and even if I do an invalid ID the command still gets called.
This is the code(all my other commands use the same code):

pawn Code:
zcmd(kick, playerid, params[])
{
  if (AccountInfo[playerid][AdminLevel] >= 1 || IsPlayerAdmin(playerid))
  {
    new tmp[256], idx;
    tmp = strtok(params, idx);
    if (isnull(tmp))
    {
        SendClientMessage(playerid, COLOR_WHITE, "USAGE: /kick [playerid] [reason]");
        return 1;
    }
    new targetid = strval(tmp);
    new reason[128];
    reason = bigstrtok(params, idx);

    if (targetid != INVALID_PLAYER_ID)
    {
        new sendername[MAX_PLAYER_NAME];
            new targetname[MAX_PLAYER_NAME];

        GetPlayerName(targetid, targetname, sizeof(targetname));
        GetPlayerName(playerid, sendername, sizeof(sendername));
        printf("ADMIN: %s has kicked %s, Reason: %s.", sendername, targetname, reason);
        format(tmp, sizeof(tmp), "ADMIN: Administrator %s has kicked %s, Reason: %s.", sendername,targetname,reason);
        SendClientMessageToAll(COLOR_LIGHTRED, tmp);
        Kick(targetid);
        KickLog(tmp);
    }
    else return SendClientMessage(playerid, COLOR_RED, "Invalid Player ID!");
  }
  else SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use that command!");
  return 1;
}
Reply
#2

INVALID_PLAYER_ID is a number, you must set your variable to INVALID_PLAYER_ID for it to work.

pawn Code:
if ( !IsPlayerConnected( targetid ) )
{
  targetid = INVALID_PLAYER_ID ;
}
Best thing to do would be to change

pawn Code:
if (targetid != INVALID_PLAYER_ID)
to

pawn Code:
if ( !IsPlayerConnected( targetid ) )
Reply
#3

Cheers man, it works.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)