30.11.2011, 17:15
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
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;
}
CMD:text(playerid, params[])
{
new text[100], color;
if(!sscanf(params,"hs", color, text))
SendClientMessageToAll(color, text);
return 1;
}
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;
}