Help with 1 command
#1

pawn Код:
if(strcmp(cmd, "/write", true) == 0 && PlayerAdminLevel[playerid] >= 1){

        if(IsAdminOrRecon[playerid] == 0){
        SendClientMessage(playerid,COLOR_ERROR,"Please Login Into Your Mod/Admin Account! Use /adminlog");
        return 1;
        }
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp))    {
        SendClientMessage(playerid, COLOR_ERROR, "USAGE: /write [Colour] [Text]");
        SendClientMessage(playerid, COLOR_WHITE, "Colours: 0=black 1=white 2=red 3=orange 4=yellow 5=green 6=blue 7=purple 8=brown 9=pink");
        return 1;
        }
        new Colour;
        Colour = strval(tmp);
        if(Colour > 9 || Colour < 0)    {
        SendClientMessage(playerid, COLOR_ERROR, "USAGE: /write [Colour] [Text]");
        SendClientMessage(playerid, COLOR_WHITE, "Colours: 0=black 1=white 2=red 3=orange 4=yellow 5=green 6=blue 7=purple 8=brown 9=pink");
        return 1;
        }
        tmp = strtok(cmdtext, idx);
        if(Colour == 0) {
        format(string,256,"%s",cmdtext[9]); SendClientMessageToAll(COLOR_BLACK,string);
        return 1;
        }
        else if(Colour == 1) {
        format(string,256,"%s",cmdtext[9]); SendClientMessageToAll(COLOR_WHITE,string);
        return 1;
        }
        else if(Colour == 2) {
        format(string,256,"%s",cmdtext[9]); SendClientMessageToAll(COLOR_RED,string);
        return 1;
        }
        else if(Colour == 3) {
        format(string,256,"%s",cmdtext[9]); SendClientMessageToAll(COLOR_ORANGE,string);
        return 1;
        }
        else if(Colour == 4) {
        format(string,256,"%s",cmdtext[9]); SendClientMessageToAll(COLOR_YELLOW,string);
        return 1;
        }
        else if(Colour == 5) {
        format(string,256,"%s",cmdtext[9]); SendClientMessageToAll(COLOR_GREEN,string);
        return 1;
        }
        else if(Colour == 6) {
        format(string,256,"%s",cmdtext[9]); SendClientMessageToAll(COLOR_BLUE,string);
        return 1;
        }
        else if(Colour == 7) {
        format(string,256,"%s",cmdtext[9]); SendClientMessageToAll(COLOR_PURPLE,string);
        return 1;
        }
        else if(Colour == 8) {
        format(string,256,"%s",cmdtext[9]); SendClientMessageToAll(COLOR_BROWN,string);
        return 1;
        }
        else if(Colour == 9) {
        format(string,256,"%s",cmdtext[9]); SendClientMessageToAll(COLOR_PINK,string);
        return 1;
        }
    return 1;
    }

how i can make in that command like in 1 sentence i can write more than 1 color like /ann command when i use ~r~ or ~w~ or ~g~
Reply
#2

I didn't understand very well. Can you explaine better please?
Take a look at this.
pawn Код:
public OnPlayerText(playerid, text[])
{
    return SendPlayerMessageToAll(playerid, ColouredText(text)), 0;
}
//---
stock ColouredText(text[])
{
    enum
        colorEnum
        {
            colorName[16],
            colorID[7]
        }
    ;
    new
        colorInfo[][colorEnum] =
        {
            { "1",           "1B1BE0" }, //Blue
            { "2",           "E81CC9" }, //Pink
            { "3",         "DBED15" }, //Yellow
            { "4",     "8CED15" }, //Lightgreen
            { "5",      "15D4ED" }, //Lightblue
            { "6",            "FF0000" }, //Red
            { "7",           "BABABA" }, //Grey
            { "8",          "FFFFFF" }, //White
            { "9",         "DB881A" }, //Orange
            { "10",          "37DB45" }, //Green
            { "11",         "7340DB" } //Purple
        },
        string[(128 + 32)],
        tempString[16],
        pos = -1,
        x
    ;
    strmid(string, text, 0, 128, sizeof(string));

    for( ; x != sizeof(colorInfo); ++x)
    {
        format(tempString, sizeof(tempString), "#%s", colorInfo[x][colorName]);

        while((pos = strfind(string, tempString, true, (pos + 1))) != -1)
        {
            new
                tempLen = strlen(tempString),
                tempVar,
                i = pos
            ;
            format(tempString, sizeof(tempString), "{%s}", colorInfo[x][colorID]);

            if(tempLen < 8)
            {
                for(new j; j != (8 - tempLen); ++j)
                {
                    strins(string, " ", pos);
                }
            }
            for( ; ((string[i] != 0) && (tempVar != 8)) ; ++i, ++tempVar)
            {
                string[i] = tempString[tempVar];
            }
            if(tempLen > 8)
            {
                strdel(string, i, (i + (tempLen - 8)));
            }
            x = -1;
        }
    }
    return string;
}
All credits to RyDeR`.
_________________
Best regardas!
Reply
#3

what i mean when i type

/write 0 Hello! 5 how are you

the sentence cant be colored 2 colors its stay black only! i want when i type like this /write 0 Hello 5How are you 4 Fine??


like sentence be colors more than 1 color!
Reply
#4

What...you can't do that with your code at all, that lets you colour the ENTIRE message, what your trying to do is colour embedding ( {FF00FF} ) and you should look for a tutorial on that first, a nice tip would be inputtext doesn't strip colour hexs.
Reply
#5

Quote:
Originally Posted by ColdRain
Посмотреть сообщение
what i mean when i type

/write 0 Hello! 5 how are you

the sentence cant be colored 2 colors its stay black only! i want when i type like this /write 0 Hello 5How are you 4 Fine??

like sentence be colors more than 1 color!
Aaa, you want that in a command, let me make it please.
______________________
EDIT: This should work:
pawn Код:
if(strcmp(cmd, "/write", true) == 0 && PlayerAdminLevel[playerid] >= 1)
{
    if(IsAdminOrRecon[playerid] == 0)
    {
        SendClientMessage(playerid,COLOR_ERROR,"Please Login Into Your Mod/Admin Account! Use /adminlog");
        return 1;
    }
    new length = strlen(cmdtext);
    while ((idx < length) && (cmdtext[idx] <= ' ')) { idx++; }
    new offset = idx, result[128], string[128];
    while ((idx < length) && ((idx - offset) < (sizeof(result) - 1))) { result[idx - offset] = cmdtext[idx], idx++; }
    result[idx - offset] = EOS;
    if(!strlen(result))
    {
        SendClientMessage(playerid, COLOR_ERROR, "USAGE: /write [Colour] [Text]");
        SendClientMessage(playerid, COLOR_WHITE, "Colours: #1 = Blue | #2 = Pink | etc.");
        //#1Just #2an #3example#4!
        return 1;
    }
    format(string,256,"%s", result), SendClientMessageToAll(COLOR_BLACK, ColouredText(string));
    return 1;
}
   
stock ColouredText(text[]) //Thanks to RyDeR`
{
    enum colorEnum { colorName[16], colorID[7] } ;
    new
        colorInfo[][colorEnum] =
        {
            { "1",           "1B1BE0" }, //Blue
            { "2",           "E81CC9" }, //Pink
            { "3",         "DBED15" }, //Yellow
            { "4",     "8CED15" }, //Lightgreen
            { "5",      "15D4ED" }, //Lightblue
            { "6",            "FF0000" }, //Red
            { "7",           "BABABA" }, //Grey
            { "8",          "FFFFFF" }, //White
            { "9",         "DB881A" }, //Orange
            { "10",          "37DB45" }, //Green
            { "11",         "7340DB" } //Purple
        },
        string[(128 + 32)], tempString[16], pos = -1, x;
    strmid(string, text, 0, 128, sizeof(string));

    for( ; x != sizeof(colorInfo); ++x)
    {
        format(tempString, sizeof(tempString), "#%s", colorInfo[x][colorName]);

        while((pos = strfind(string, tempString, true, (pos + 1))) != -1)
        {
            new tempLen = strlen(tempString), tempVar, i = pos;
            format(tempString, sizeof(tempString), "{%s}", colorInfo[x][colorID]);

            if(tempLen < 8)
            {
                for(new j; j != (8 - tempLen); ++j)
                {
                    strins(string, " ", pos);
                }
            }
            for( ; ((string[i] != 0) && (tempVar != 8)) ; ++i, ++tempVar)
            {
                string[i] = tempString[tempVar];
            }
            if(tempLen > 8)
            {
                strdel(string, i, (i + (tempLen - 8)));
            }
            x = -1;
        }
    }
    return string;
}
Tell me if you get any error.
Reply
#6

sorry for annoy guys but thank you all i owe one ! + rep for all !!!!
Reply
#7

Haha, you're welcome.
Reputation for all. Why? lol xD!
Reply
#8

just gift man :P its chrimates time!
Reply
#9

Quote:
Originally Posted by ColdRain
Посмотреть сообщение
just gift man :P its chrimates time!
Hahaha, you're right.
Waiting for my reputation vote. Hihihi... Thank you.
Reply
#10

Hey i need other help how i can in the command if dont find this "#" tell him Error Text!


pawn Код:
if(strcmp(cmd, "/write", true) == 0 && PlayerAdminLevel[playerid] >= 1){

        if(IsAdminOrRecon[playerid] == 0){
        SendClientMessage(playerid,COLOR_ERROR,"Please Login Into Your Mod/Admin Account! Use /adminlog");
        return 1;
        }
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp))    {
        SendClientMessage(playerid, COLOR_ERROR, "USAGE: /write [Text]");
        SendClientMessage(playerid, COLOR_ERROR, "You can Do Colored Text! Ex. /write #1Hi #2How are you!");
        SendClientMessage(playerid, COLOR_ERROR, "#1, #2, #3, #4, #5, #6, #7, #8, #9, #10");
        return 1;
        }
        new output[125];
        strmid(output,cmdtext,7,strlen(cmdtext));
        format(string,256,"%s",cmdtext[9]);
        SendClientMessageToAll(playerid,ColouredText(output));
    return 1;
    }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)