02.10.2010, 08:48
Quote:
This is definitely the bad way to make this command. It's a lot easier doing it with sscanf.
pawn Code:
|
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!
}
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'.