Setting skins
#1

Alright, so I am making a script to where administrators over the level of 2 may set other player's skin for my RP server. I have a code that sets a skin, but can only seem to set the skin to 0, I am not sure why, here's the code...
pawn Код:
if (strcmp("/setskin", cmdtext, true, 10) == 0)
    {
        if(PlayerInfo[playerid][pAdmin] >= 2)
        {
            if(isnull(cmdtext))
            {
                SendClientMessage(playerid, 0xFFFFFFFF, "SYNTAX: /setskin [Playerid] [ID]");
            }
            else
            {
                new id, Value, string[128];
                if(IsInvalidSkin(Value))
                {
                        SendClientMessage(playerid, 0xFFFFFFFF, "Invalid skin!");
                }
                else
                {
                format(string, sizeof(string), "You have set %s's skin to %d.", GetName(id), Value);
                SendClientMessage(playerid, 0xFFFFFFFF, string);
                SetPlayerSkin(Value, id);
                }
            }
        }
        else
        {
            SendClientMessage(playerid, 0x4F4F4FFF, "ERROR: You are unauthorized to use this command!");
        }
        return 1;
    }
Reply
#2

You need to switch between the Value and the ID.
pawn Код:
SetPlayerSkin(Value, id); --> SetPlayerSkin(id, value);
Reply
#3

Already tried, I get the same result.
Reply
#4

Try this.
pawn Код:
if (strcmp("/setskin", cmdtext, true, 10) == 0)
{
    if(PlayerInfo[playerid][pAdmin] >= 2)
    {
        if(isnull(cmdtext)) {
            SendClientMessage(playerid, 0xFFFFFFFF, "SYNTAX: /setskin [Playerid] [ID]");
        }
        else {
            new value, string[128];
            if(IsInvalidSkin(value)) {
                SendClientMessage(playerid, 0xFFFFFFFF, "Invalid skin!");
            }
            else {
                format(string, sizeof(string), "You have set %s's skin to %d.", GetName(playeridid), Value);
                SendClientMessage(playerid, 0xFFFFFFFF, string);
                SetPlayerSkin(playerid, value);
            }
        }
    }
    else {
        SendClientMessage(playerid, 0x4F4F4FFF, "ERROR: You are unauthorized to use this command!");
    }
    return 1;
}
Reply
#5

Wrong post >.>.
Reply
#6

I get the same issue.
Reply
#7

What do you mean, same issue ? you can set the skin only 0, or the playerid, only 0 ?
Reply
#8

Well, the skin will only set to 0, when I type /setskin with nothing following it says no error message afterwards, and sets my skin to skin ID 0.
Reply
#9

Try using this maybe :
pawn Код:
if (strcmp("/setskin", cmdtext, true, 10) == 0)
{
    if(PlayerInfo[playerid][pAdmin] >= 2)
    {
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp)) {
            SendClientMessage(playerid, 0xFFFFFFFF, "SYNTAX: /setskin [Playerid] [ID]");
            return 1;
        }
        else
        {
            new value, string[128];
            if(IsInvalidSkin(value))
            {
                SendClientMessage(playerid, 0xFFFFFFFF, "Invalid skin!");
            }
            else
            {
                format(string, sizeof(string), "You have set %s's skin to %d.", GetName(playeridid), Value);
                SendClientMessage(playerid, 0xFFFFFFFF, string);
                SetPlayerSkin(playerid, value);
            }
        }
    }
    else
    {
        SendClientMessage(playerid, 0x4F4F4FFF, "ERROR: You are unauthorized to use this command!");
    }
    return 1;
}
If the problem still occurs, what does it tell ?
Reply
#10

You're not getting any parameters at all, that's why. You simply declared value(default is 0) and there's no parameter for the player's ID or name.
pawn Код:
strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }
 
    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}
You should do this
pawn Код:
new param[64], cmd[64], idx;
cmd = strtok(cmdtext, idx);
The cmd variable would be the one to detect the command used, so
pawn Код:
if(!strcmp(cmd, "/setskin", true))
    {
        if(PlayerInfo[playerid][pAdmin] >= 2)
        {
            // declare the variables
            new targetid, skin, string[128];

            // get the first parameter, which is the playerid
            param = strtok(cmdtext, idx);
            if(!strlen(param)) return SendClientMessage(playerid, -1, "Usage: /setskin [PlayerID] [SkinID]");
            targetid = param;

            // second parameter, which is the skin id
            param = strtok(cmdtext, idx);
            if(!strlen(param)) return SendClientMessage(playerid, -1, "Usage: /setskin [PlayerID] [SkinID]");
            skin = strval(param);

            // check if the input is a valid skin id
            if(IsInvalidSkin(skin)) return SendClientMessage(playerid, -1, "Invalid skin ID!");

            // set the player's skin and send the message
            format(string, sizeof(string), "You have set %s's skin to %d", GetName(targetid), skin);
            SendClientMessage(playerid, -1, string);
            SetPlayerSkin(targetid, skin);
        }
        else SendClientMessage(playerid, -1, "ERROR: You are unauthorized to use this command.");
        return 1;
    }
Use this one(ReturnUser) to return the player's ID or name:
http://pastebin.com/A5CZ46C2

I highly recommend using sscanf and ZCMD though, rather than this.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)