[Tutorial] How to script /skin command
#10

Quote:
Originally Posted by RealCop228
View Post
This is definitely the bad way to make this command. It's a lot easier doing it with sscanf.

pawn Code:
command(skin, playerid, params[])
{
        new string[128], skinid;
    if(IsPlayerAdmin(playerid))
    {
        if(sscanf(params, "d", skinid)
        {
            SendClientMessage(playerid, COLOR_WHITE, "SYNTAX: /skin [skinID]");
        }
        else
        {
            SetPlayerSkin(playerid, skinid);
            format(string, sizeof(string), "You have set your skin ID to %d", skinid);
            SendClientMessage(playerid, COLOR_WHITE, string);
        }
    }
    return 1;
}
This checks if a player is an admin (RCON), if the sscanf params are correct, if not it sends a message with the correct usage (SYNTAX) if the params are correct, it continues the command. It will set your skin to the ID you chose and then send you a message telling you what skin you chose. I used ZCMD and SSCANF2 to do this. Took me 10 seconds.
You don't really need to create another integer, as you can strval params:

pawn Code:
command(skin, playerid, params[]) // Declaring that this is a ZCMD command.
{
    if(IsPlayerAdmin(playerid)) { // Checking whether the player is an admin or not, if so the code continues!
        if(!isnull(params)) { // Here we check if the string contains no content.
            SendClientMessage(playerid, COLOR_WHITE, "SYNTAX: /skin [skinID]"); // It contains no content, let's send them a message showing them the syntax
        }
        else { // This else statement does the opposite to the check above, basically the params appear to be existant so the code continues like so
            new
                string[32]; // Create a string to send them a message with

            SetPlayerSkin(playerid, strval(params)); // Set the player skin. Here, we're using 'strval' which evaluates 'params' (a string) in to an integer
            format(string, sizeof(string), "Your new skin ID is: %d", strval(params)); // And again, however formatting a message.
            SendClientMessage(playerid, COLOR_WHITE, string); // Sending them the message
        }
    }
    return 1; // Command has finished processing. Returning 1!
}
Added comments to explain what's being done, too. A bit of a further explanation for how strval works (for those that didn't understand it):

By default, params is a string, which means it isn't expected to just contain the value of an integer (digit/number), therefore using strval, it evaluates the string and checks for numbers within the string, then throws them out as an integer. Hence 'strval'.
Reply


Messages In This Thread
How to script /skin command - by Injector - 24.09.2010, 13:18
Re: How to script /skin command - by Kyosaur - 24.09.2010, 13:25
Re: How to script /skin command - by Scenario - 24.09.2010, 13:29
Re: How to script /skin command - by Injector - 24.09.2010, 13:30
Re: How to script /skin command - by Injector - 24.09.2010, 13:34
Re: How to script /skin command - by Cameltoe - 24.09.2010, 13:37
Re: How to script /skin command - by Injector - 24.09.2010, 13:41
Re: How to script /skin command - by Scenario - 24.09.2010, 13:46
Re: How to script /skin command - by LarzI - 29.09.2010, 18:27
Re: How to script /skin command - by Calgon - 02.10.2010, 08:48

Forum Jump:


Users browsing this thread: 1 Guest(s)