How to make /skin cmd?
#1

Hi, i have this script:
Код:
    if(!strcmp("/skin", cmdtext, true))
    {
        new string[128], skinid;
        SendClientMessage(playerid, 0xDEEE20FF, "/Skin [Skin ID 0-299]");
        skinid = strval(cmdtext[12]);
        switch(skinid)
        {
            default:
            {
                SetPlayerSkin(playerid, skinid);
                format(string, sizeof(string), "Pakeitėte savo skin į %d", skinid);
                SendClientMessage(playerid, 0xDEEE20FF, string);
            }
        }
        return 1;
}
But when i type /skin server crash, can someone remake this cmd? Thanks.
Reply
#2

pawn Код:
if(!strcmp("/skin", cmdtext, true))
{
    new string[128],skinid;
    SendClientMessage(playerid, 0xDEEE20FF, "/Skin [Skin ID 0-299]");
    skinid = strval(cmdtext[5]);
    if(skinid > 299 || skinid < 0) return SendClientMessage(playerid,-1,"ERROR: Invalid Skin.");
    SetPlayerSkin(playerid, skinid);
    format(string, sizeof(string), "Pakeitete savo skin i %d", skinid);
    SendClientMessage(playerid, 0xDEEE20FF, string);
    return 1;
}
Reply
#3

Now when i write /skin, it changes to CJ skin, when i write /skin [ID] nothing happens.
Reply
#4

UPPP
Reply
#5

PHP код:
if(strcmp("/skin"cmdtexttrue) == 0/*change cmdtext with cmd.Learn more at this link:
https://sampwiki.blast.hk/wiki/Strtok*/n...9.82770523
{
new 
tmp[128];
tmp strtok(cmdtextidx);
new 
id strval(tmp);
if(!
strlen(tmp))
{
SendClientMessage(playerid, -1"Usage: /skin [skin id]");
return 
1;
}
SetPlayerSkin(playeridid);
SendClientMessage(playerid,-1,"Skin changed!");
return 
1;

Reply
#6

You also have to check if it's valid id or not. By the way, it's 2012 guys! Stop using strcmp/strtok for commands while ZCMD or y_commands with Sscanf is a faster and easier way.
Anyway..
pawn Код:
// --
    if( !strcmp( cmdtext, "/skin", true ) )
    {
        new
            string[ 128 ],
            skin
        ;
        if( !cmdtext[ 5 ] ) return SendClientMessage( playerid, -1, "Usage: /skin <id>" );
        skin = strval( cmdtext[ 6 ] );
        switch( skin )
        {
            case 74: return SendClientMessage( playerid, -1, "Invalid skin ID!" );
            default:
            {
                SetPlayerSkin( playerid, skin );
                format( string, sizeof( string ), "You have successfully changed your skin to %i", skin );
                SendClientMessage( playerid, -1, string );
            }
        }
        return 1;
    }
Reply
#7

strcmp/strtok is old school,but it's slow
Reply
#8

Quote:
Originally Posted by Dwane
Посмотреть сообщение
You also have to check if it's valid id or not. By the way, it's 2012 guys! Stop using strcmp/strtok for commands while ZCMD or y_commands with Sscanf is a faster and easier way.
Anyway..
pawn Код:
// --
    if( !strcmp( cmdtext, "/skin", true ) )
    {
        new
            string[ 128 ],
            skin
        ;
        if( !cmdtext[ 5 ] ) return SendClientMessage( playerid, -1, "Usage: /skin <id>" );
        skin = strval( cmdtext[ 6 ] );
        switch( skin )
        {
            case 74: return SendClientMessage( playerid, -1, "Invalid skin ID!" );
            default:
            {
                SetPlayerSkin( playerid, skin );
                format( string, sizeof( string ), "You have successfully changed your skin to %i", skin );
                SendClientMessage( playerid, -1, string );
            }
        }
        return 1;
    }
When i write /skin [ID] nothing happens..
Reply
#9

pawn Код:
CMD:skin(playerid, params[])
{
    new skin, string[128];
    if(sscanf(params, "d", skin)) return SendClientMessage(playerid, COLOR_RED, "[SERVER] /skin skinid");

    if(skin > 0 && skin < 300)
    {
        SetPlayerSkin(playerid, skin);
        format(string, sizeof(string), "Your skin has been set by Staff Member "COL_BLUE"%s.", pName(playerid));
        SendClientMessage(playerid, -1, string);

        format(string, sizeof(string), "You have set your skin to %d", skin);
        SendClientMessage(playerid, -1, string);
    }
    else
    {
       SendClientMessage(playerid, -1, "Please use a valid skin ID");
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)