Rainbow text
#1

Hello I am trying to make a command the shows rainbow text but the text is not showing here is my code

pawn Код:
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;
}
pawn Код:
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;
}
Reply
#2

Why aren't you using switch? it's a lot better than a lot of if's.
Reply
#3

pawn Код:
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;
}
Chat supports only 144 characters.
Reply
#4

Quote:
Originally Posted by Luis-
Посмотреть сообщение
Why aren't you using switch? it's a lot better than a lot of if's.
Added switches
Quote:
Originally Posted by Jefff
Посмотреть сообщение
Chat supports only 144 characters.
Your code does not seem to compile
Reply
#5

Replace
while((pos = strfind(str," ",true,pos+1))
to
while((pos = strfind(str," ",true,pos+1)) != -1)
Reply
#6

Change to:
pawn Код:
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;
}
It was str, not string and he forgot to add an extra ) in the while loop.
Reply
#7

Quote:
Originally Posted by Jefff
Посмотреть сообщение
Replace
while((pos = strfind(str," ",true,pos+1))
to
while((pos = strfind(str," ",true,pos+1)) != -1)
the text does not change color it remains pink
Reply
#8

All works

pawn Код:
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
Reply
#9

It does work but I want ever character a different color
Reply
#10

Dont do that !

Quote:
Originally Posted by Jefff
Посмотреть сообщение
Chat supports only 144 characters.
if u type /announce Hello World

output is

Код:
H{COLOR}e{COLOR}l{COLOR}l{COLOR}o {COLOR}W{COLOR}o{COLOR}r{COLOR}l{COLOR}d
83 characters ! + strlen("[ADMIN:%s] ")
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)