Params
#1

Hey i know that i can use sscanf for like params for ID's,texts and similar...but how would i do /color (red,green,yellow...) (text).... Please, i want to learn
Reply
#2

I don't know what is /color (red,green,yellow...), however maybe you mean this.. as example, using strcmp to compare the params.
pawn Код:
CMD:color( playerid, params[] )
{
    new s_Color[32];
    if ( sscanf( params, "s[32]", s_Color ) ) return SendClientMessage( playerid, -1, "Usage: /color (green, red, yellow, blue)" );
    if ( strcmp ( s_Color, "green", true ) == 0 )
    {
        SendClientMessage( playerid, -1, "you choosed GREEN");
    }
    if ( strcmp ( s_Color, "red", true ) == 0 )
    {
        SendClientMessage( playerid, -1, "you choosed RED");
    }
    if ( strcmp ( s_Color, "yellow", true ) == 0 )
    {
        SendClientMessage( playerid, -1, "you choosed YELLOW");
    }
    if ( strcmp ( s_Color, "blue", true ) == 0 )
    {
        SendClientMessage( playerid, -1, "you choosed BLUE");
    }
    else // if it's none of above
    {
        SendClientMessage( playerid, -1, "you didn't choose a correct color.");
    }
    return 1;
}
if this is not your intent, specify yourself
Reply
#3

pawn Код:
CMD:text(playerid, params[])
{
    new text[100], color;
    if(!sscanf(params,"hs", color, text))
    SendClientMessageToAll(color, text);
    return 1;
}
This is the basic script. You'll have to make a better choice of colors with names yourself.
Reply
#4

@admantis: You haven't put the text in though.
@Unte99: He wants color names not hex codes.

pawn Код:
CMD:color( playerid, params[] )
{
    new s_Color[32], s_Text[128];
    if (sscanf(params, "s[32]s[128]", s_Color, s_Text)) return SendClientMessage(playerid, COLOR_RED, "Usage: /color [green/red/yellow/blue] [message]" );

    // the 's_Color' string contains the color they entered
    // the 's_Text' string contains what they entered after it
 
    // example usage:
    if(!strcmp(s_Color, "red", true)) // If they chose red
    {
        SendClientMessageToAll(COLOR_RED, s_Text);
    }
    else if(!strcmp(s_Color, "green", true))
    {
        SendClientMessageToAll(COLOR_GREEN, s_Text);
    }
    else SendClientMessage(playerid, COLOR_RED, "Invalid color. Valid colors are green/red/yellow/blue.");
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)