Quick Help - Invalid Skin
#1

Hi,

i've got this as a command:
pawn Код:
if(strcmp(cmd, "/setskin", true) == 0)
    {
    if(PlayerInfo[playerid][pAdmin] < 7) return DenyMessage(playerid, 7);
    new tmp2[256];
    tmp = strtok(cmdtext, idx);
    new otherplayer = strval(tmp);
    tmp2 = strtok(cmdtext, idx);
    new skin = strval(tmp2);
    if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setskin [playerid] [skinid]");
        if(!strlen(tmp2)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setskin [playerid] [skinid]");
        if(!IsPlayerConnected(otherplayer)) SendClientMessage(playerid, COLOR_WHITE, "Invalid Player ID.");
        else if (IsInvalidSkin(skin)) SendClientMessage(playerid, COLOR_GREY, "* Invalid Skin ID");
        SetPlayerSkin(otherplayer, skin);
        SendClientMessage(otherplayer, COLOR_WHITE, "An Admin has changed your skin.");
        return 1;
    }
pawn Код:
stock IsInvalidSkin(skin)
{
  #define   MAX_BAD_SKINS  14
  new badSkins[MAX_BAD_SKINS] =
  {
    3, 4, 5, 6, 8, 42, 65, 74, 86,
    119, 149, 208, 273, 289
  };

  for (new i = 0; i < MAX_BAD_SKINS; i++)
  {
    if (skin == badSkins[i] || skin < 0 || skin >= 300) return true;
  }

  return false;
}
Now, what's supposed to happen is that if the player has entered an incorrect skin id, it returns them the "* Invalid Skin ID" message.
But, I think it ignores the IsInvalidSkin stock, and this makes me crash, i.e. it's not working.

i've used this in my gamemode in another way for setting team skins, and that works, but the admin script uses a different way (as above).

I'm probably making a simple stupid mistake. Help is much appreciated
Reply
#2

Well you should indent better, it makes reading errors easier. But you should also look into dcmd and sscanf. They are faster and a lot easier.

pawn Код:
dcmd_setskin(playerid,params[])
{
    new player, skin;
    if(sscanf(params,"dd",player,skin))
    {
        SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setskin [playerid] [skinid]");
        return 1;
    }
    if(!IsPlayerConnected(player))
    {
        SendClientMessage(playerid, COLOR_WHITE, "Invalid Player ID.");
        return 1;
    }
    if(IsInvalidSkin(skin))
    {
        SendClientMessage(playerid, COLOR_GREY, "* Invalid Skin ID");
        return 1;
    }
    SetPlayerSkin(player, skin);
    SendClientMessage(player, COLOR_WHITE, "An Admin has changed your skin.");
    return 1;
}
Or even less. Although, I hate when people code like this.

pawn Код:
dcmd_setskin(playerid,params[])
{
    new player, skin;
    if(sscanf(params,"dd",player,skin)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setskin [playerid] [skinid]");
    if(!IsPlayerConnected(player)) return SendClientMessage(playerid, COLOR_WHITE, "Invalid Player ID.");
    if(IsInvalidSkin(skin)) return SendClientMessage(playerid, COLOR_GREY, "* Invalid Skin ID");
    SetPlayerSkin(player, skin);
    SendClientMessage(player, COLOR_WHITE, "An Admin has changed your skin.");
    return 1;
}
Reply
#3

Thanks backwardsman97,

I already found the fix lol, just put a return, just like you did. Sorry to waste ur time. I was just about to say, but my mum told me to do help her get the bins out.

Yeh i know i should use dcmd and sscanf as they are faster and have much more benefits, but i han't got the time. I will convert all commands and stuff soon though.

Thanks once again.

p.s. indentations are fine on the pawn file. I get stressed seeing things improperly indented lol
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)