Using Case's. (Using Name Instead Of Number) -
Shockey HD - 13.09.2011
I need some help with cases.
So here is my command.
pawn Код:
CMD:color(playerid,params[])
{
new id,color,string[128];
if(sscanf(params,"ud",id,color))return SendClientMessage(playerid,COLOR_RED,"Usage:/SetColor [ID][Color]"),SendClientMessage(playerid,COLOR_ORANGE,"Type /Colors For Available Name Colors");
if (id == INVALID_PLAYER_ID) SendClientMessage(playerid, COLOR_RED, "System: Invalid ID");
else
{
switch(color)
{
case 1:
{
SetPlayerColor(id,COLOR_ORANGE);
new name[MAX_PLAYER_NAME];
GetPlayerName(id, name, sizeof(name));
format(string, sizeof(string), "Admin %s Has Set Your Color To Orange",name);
SendClientMessage(id,COLOR_ORANGE,string);
}
case 2:
{
SetPlayerColor(id,COLOR_YELLOW);
new name[MAX_PLAYER_NAME];
GetPlayerName(id, name, sizeof(name));
format(string, sizeof(string), "Admin %s Has Set Your Color To Yellow",name);
SendClientMessage(id,COLOR_YELLOW,string);
}
case 3:
{
SetPlayerColor(id,COLOR_BLUE);
new name[MAX_PLAYER_NAME];
GetPlayerName(id, name, sizeof(name));
format(string, sizeof(string), "Admin %s Has Set Your Color To Blue",name);
SendClientMessage(id,COLOR_YELLOW,string);
}
case 4:
{
SetPlayerColor(id,COLOR_BLUE);
new name[MAX_PLAYER_NAME];
GetPlayerName(id, name, sizeof(name));
format(string, sizeof(string), "Admin %s Has Set Your Color To Red",name);
SendClientMessage(id,COLOR_RED,string);
}
case 5:
{
SetPlayerColor(id,COLOR_BLUE);
new name[MAX_PLAYER_NAME];
GetPlayerName(id, name, sizeof(name));
format(string, sizeof(string), "Admin %s Has Set Your Color To Light Blue",name);
SendClientMessage(id,COLOR_LIGHTBLUE,string);
}
}
}
return 1;
}
I want it so that you have to type
/color orange or /use blue
Not /use 1 or /use 2
Re: Using Case's. (Using Name Instead Of Number) -
admantis - 13.09.2011
You can't use case statement with a strcmp function afaik but this will definitively work.
pawn Код:
CMD:color(playerid,params[])
{
new id,color[32],string[128];
if(sscanf(params,"us[32]",id,color))return SendClientMessage(playerid,COLOR_RED,"Usage:/SetColor [ID][Color]"),SendClientMessage(playerid,COLOR_ORANGE,"Type /Colors For Available Name Colors");
if (id == INVALID_PLAYER_ID) SendClientMessage(playerid, COLOR_RED, "System: Invalid ID");
else
{
if (strcmp(color, "orange", true) == 0)
{
SetPlayerColor(id,COLOR_ORANGE);
new name[MAX_PLAYER_NAME];
GetPlayerName(id, name, sizeof(name));
format(string, sizeof(string), "Admin %s Has Set Your Color To Orange",name);
SendClientMessage(id,COLOR_ORANGE,string);
}
else if (strcmp(color, "yellow", true) == 0)
{
SetPlayerColor(id,COLOR_YELLOW);
new name[MAX_PLAYER_NAME];
GetPlayerName(id, name, sizeof(name));
format(string, sizeof(string), "Admin %s Has Set Your Color To Yellow",name);
SendClientMessage(id,COLOR_YELLOW,string);
}
else if (strcmp(color, "blue", true) == 0)
{
SetPlayerColor(id,COLOR_BLUE);
new name[MAX_PLAYER_NAME];
GetPlayerName(id, name, sizeof(name));
format(string, sizeof(string), "Admin %s Has Set Your Color To Blue",name);
SendClientMessage(id,COLOR_YELLOW,string);
}
else if (strcmp(color, "red", true) == 0)
{
SetPlayerColor(id,COLOR_BLUE);
new name[MAX_PLAYER_NAME];
GetPlayerName(id, name, sizeof(name));
format(string, sizeof(string), "Admin %s Has Set Your Color To Red",name);
SendClientMessage(id,COLOR_RED,string);
}
else if (strcmp(color, "lightblue", true) == 0)
{
SetPlayerColor(id,COLOR_BLUE);
new name[MAX_PLAYER_NAME];
GetPlayerName(id, name, sizeof(name));
format(string, sizeof(string), "Admin %s Has Set Your Color To Light Blue",name);
SendClientMessage(id,COLOR_LIGHTBLUE,string);
}
else
{
return SendClientMessage(playerid,COLOR_WHITE, "invalid color (choose orange, yellow, blue, red, lightblue)");
}
}
return 1;
}