[Tutorial] setskin
#7

There are problems again.

- As newbie scripter said, only players who are NOT RCON admins can use the command.
- You don't check if the skin is negative or 74 (invalid).
- You send the message to the player who typed the command instead of the player whose skin is set.
- You don't need 128 as size for the string, the message is shorter.
- In case the parameters are wrong, the usage will be displayed. If so, why to declare the name and get the name of the player (who typed the command) when it will be never used?

It can be improved:
pawn Код:
CMD:setskin(playerid, params[])
{
    if (!IsPlayerAdmin(playerid)) return 0;
   
    new
        pID,
        sID;
   
    if (sscanf(params, "ri", pID, sID)) return SendClientMessage(playerid, COLOR_RED, "INFO: /setskin [PlayerID/Name] [SkinID]");
    if (pID == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "Player not found.");
    if (!(0 <= sID <= 299) || sID == 74) return SendClientMessage(playerid, COLOR_RED, "Skin not found.");
   
    SetPlayerSkin(pID, sID);
   
    new
        name[MAX_PLAYER_NAME],
        str[57];
   
    GetPlayerName(playerid, name, MAX_PLAYER_NAME);
    format(str, sizeof (str), "Admin %s has set your skin to %i.", name, sID);
    SendClientMessage(pID, COLOR_RED, str);
    return 1;
}
Quote:
Originally Posted by EnzoMetlc
Посмотреть сообщение
pawn Код:
if(sID > 299)return SendClientMessage(playerid, COLOR_RED, "Skin not found.");
Would not it be:

pawn Код:
if(strlen(sID) > 299) return SendClientMessage(playerid, COLOR_RED, "Skin not found.");
No, sID is integer not a string to get its lenght.
Reply


Messages In This Thread
setskin - by MatriXgaMer - 09.01.2014, 12:29
Re: setskin - by Konstantinos - 09.01.2014, 12:49
Re: setskin - by MatriXgaMer - 09.01.2014, 12:52
Re: setskin - by Vince - 09.01.2014, 13:10
Re: setskin - by newbie scripter - 09.01.2014, 15:16
Respuesta: setskin - by Swedky - 09.01.2014, 15:21
Re: Respuesta: setskin - by Konstantinos - 09.01.2014, 15:31

Forum Jump:


Users browsing this thread: 1 Guest(s)