CMD:announce(playerid,params[])
{
if(IsPlayerAdminLevel(playerid, 1))
{
new input[256];
new string[256];
if (sscanf(params, "s["#256"]",input))
{
return SendClientMessage(playerid, RED, "SYNTAX /announce [text]");
}
new name[MAX_PLAYER_NAME+1];
GetPlayerName(playerid,name,sizeof(name));
new inputformat[256];
new colorcount;
new color[7];
for(new c;c < sizeof(input);c++)
{
format(color,sizeof(color),"%s",GetColor(colorcount));
if(input[c] == ' ')
{
new addstr[256];
format(addstr,sizeof(addstr),"%s%c",inputformat,input[c]);
}
else
{
new addstr[256];
format(addstr,sizeof(addstr),"%s{%s}%c",inputformat,color,input[c]);
format(inputformat,sizeof(inputformat),"%s",addstr);
colorcount ++;
if((colorcount) > 9)
{
colorcount = 0;
}
}
}
format(string,256,"[ADMIN:%s] %s",name,inputformat);
SendClientMessageToAll(PINK, string);
SendClientMessage(playerid, LIGHTBLUE, "MessageSent");
}
else
{
SendClientMessage(playerid, RED, "You Have To Be Admin To Use This Command");
}
return 1;
}
stock GetColor(colorcount)
{
new color[7];
switch(colorcount)
{
case 0:
{
format(color,sizeof(color),"0071BD");
}
case 1:
{
format(color,sizeof(color),"FF00FE");
}
case 2:
{
format(color,sizeof(color),"78227D");
}
case 3:
{
format(color,sizeof(color),"009309");
}
case 4:
{
format(color,sizeof(color),"00FF01");
}
case 5:
{
format(color,sizeof(color),"FFFF04");
}
case 6:
{
format(color,sizeof(color),"FACB01");
}
case 7:
{
format(color,sizeof(color),"FF7C00");
}
case 8:
{
format(color,sizeof(color),"FE0000");
}
case 9:
{
format(color,sizeof(color),"D50304");
}
}
return color;
}
GetColor(colorcount)
{
static const Colors[] = {
0x0071BD00,
0xFF00FE00,
0x78227D00,
0x00930900,
0x00FF0100,
0xFFFF0400,
0xFACB0100,
0xFF7C0000,
0xFE000000,
0xD5030400
};
if(colorcount >= sizeof(Colors)) return -1;
return (Colors[colorcount] >>> 8);
}
CMD:announce(playerid,params[])
{
if(!IsPlayerAdminLevel(playerid, 1)) SendClientMessage(playerid, RED, "You Have To Be Admin To Use This Command");
else if(isnull(params)) SendClientMessage(playerid, RED, "SYNTAX /announce [text]");
else{
new str[144],name[MAX_PLAYER_NAME + 1],pos,colorcount,color[9];
strcat(str,params);
GetPlayerName(playerid,name,MAX_PLAYER_NAME);
while((pos = strfind(str," ",true,pos+1))
{
colorcount %= 10;
format(color,sizeof color,"{%06x}",GetColor(colorcount++));
strins(str,color,pos+1);
}
format(string,sizeof str,"[ADMIN:%s] %s",name,str);
SendClientMessageToAll(PINK, str);
SendClientMessage(playerid, LIGHTBLUE, "MessageSent");
}
return 1;
}
Why aren't you using switch? it's a lot better than a lot of if's.
|
CMD:announce(playerid,params[])
{
if(!IsPlayerAdmin(playerid)) SendClientMessage(playerid, -1, "You Have To Be Admin To Use This Command");
else if(isnull(params)) SendClientMessage(playerid, -1, "SYNTAX /announce [text]");
else
{
new str[144],name[MAX_PLAYER_NAME + 1],pos,colorcount,color[9];
strcat(str,params);
GetPlayerName(playerid,name,MAX_PLAYER_NAME);
while((pos = strfind(str," ",true,pos+1)))
{
colorcount %= 10;
format(color,sizeof color,"{%06x}",GetColor(colorcount++));
strins(str,color,pos+1);
}
format(str,sizeof str,"[ADMIN:%s] %s",name,str);
SendClientMessageToAll(-1, str);
SendClientMessage(playerid, -1, "MessageSent");
}
return 1;
}
Replace
while((pos = strfind(str," ",true,pos+1)) to while((pos = strfind(str," ",true,pos+1)) != -1) |
GetColor(colorcount)
{
static const Colors[] = {
0x0071BD00,
0xFF00FE00,
0x78227D00,
0x00930900,
0x00FF0100,
0xFFFF0400,
0xFACB0100,
0xFF7C0000,
0xFE000000,
0xD5030400
};
if(colorcount >= sizeof(Colors)) return -1;
return (Colors[colorcount] >>> 8);
}
CMD:announce(playerid,params[])
{
if(!IsPlayerAdminLevel(playerid, 1)) SendClientMessage(playerid, RED, "You Have To Be Admin To Use This Command");
else if(isnull(params)) SendClientMessage(playerid, RED, "SYNTAX /announce [text]");
else{
new str[144],name[MAX_PLAYER_NAME + 1],pos,colorcount,color[9];
strcat(str,params);
/*format(color,sizeof color,"{%06x}",GetColor(colorcount++));
strins(str,color,0);*/
GetPlayerName(playerid,name,MAX_PLAYER_NAME);
while((pos = strfind(str," ",true,pos+1)) != -1)
{
colorcount %= 10;
format(color,sizeof color,"{%06x}",GetColor(colorcount++));
strins(str,color,pos+1);
}
format(str,sizeof str,"[ADMIN:%s] %s",name,str);
SendClientMessageToAll(PINK, str);
SendClientMessage(playerid, LIGHTBLUE, "MessageSent");
}
return 1;
}
/announce Example Text
H{COLOR}e{COLOR}l{COLOR}l{COLOR}o {COLOR}W{COLOR}o{COLOR}r{COLOR}l{COLOR}d