AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Chat Text Error/ExplodingImploding String (https://forums.alliedmods.net/showthread.php?t=298964)

Riotline 06-28-2017 00:59

Chat Text Error/ExplodingImploding String
 
I've been trying to create a rainbow effect with my text and I'm now having a problem. Everytime I try to run this code it works fine until the PrintToChat "Test2".
If I moved that print to chat above where the for loop is then it will show but after the for loop nothing else runs.
Code:

        if(strcmp(buffer, "1") == 0 && pos <= -1 || pos > 1 ){
                ExplodeString(msg, " ", arraymsg, sizeof(arraymsg), sizeof(arraymsg[]))
                for(new i = 0; i <= sizeof(arraymsg); i++)
                {
                        switch(GetRandomInt(1, 8))
                        {
                                case 1:
                                        msgcolour = " {blue}"
                                case 2:
                                        msgcolour = " {red}"
                                case 3:
                                        msgcolour = " {purple}"
                                case 4:
                                        msgcolour = " {yellow}"
                                case 5:
                                        msgcolour = " {green}"
                                case 6:
                                        msgcolour = " {pink}"
                                case 7:
                                        msgcolour = " {lime}"
                                case 8:
                                        msgcolour = " {aqua}"
                        }
                        StrCat(arraymsg[i], sizeof(arraymsg), msgcolour);
                }
                PrintToChat(client, "Test2")
                ImplodeStrings(arraymsg, sizeof(arraymsg), " ", endmsg, sizeof(endmsg))
                CPrintToChatAllEx(client, "{aqua}%s{teamcolor}%s {default}: %s", tag, name, endmsg)
                return Plugin_Handled;
        }


hmmmmm 06-28-2017 02:29

Re: Chat Text Error/ExplodingImploding String
 
PHP Code:

char gC_Colours[][][] = {

    {
"White""{white}""\x01"},
    {
"Red""{red}""\x07"},
    {
"Light Red""{lightred}""\x0F"},
    {
"Dark Red""{darkred}""\x02"},
    {
"Blue-Gray""{bluegrey}""\x0A"},
    {
"Blue""{blue}""\x0B"},
    {
"Dark Blue""{darkblue}""\x0C"},
    {
"Orchid""{orchid}""\x0E"},
    {
"Yellow""{yellow}""\x09"},
    {
"Gold""{gold}""\x10"},
    {
"Light Green""{lightgreen}""\x05"},
    {
"Green""{green}""\x04"},
    {
"Lime""{lime}""\x06"},
    {
"Gray""{grey}""\x08"},
    {
"Gray2""{grey2}""\x0D"},
    {
"Team Colour""{teamcolor}""\x03"},
    {
"Purple""{purple}""\x03"},
    {
"Default""{default}""\x01"},

}

stock void GetRandomColours(char[] message) {

    
int I_Split;
    
char C_SplitString[64][512];

    
ExplodeString(message" "C_SplitString64512);

    while (
strlen(C_SplitString[I_Split]) > 0) {

        
int I_Random GetRandomInt(0sizeof(gC_Colours) - 4);
        
Format(C_SplitString[I_Split], 512"%s%s"gC_Colours[I_Random][2], C_SplitString[I_Split]);

        
I_Split++;

    }

    
ImplodeStrings(C_SplitStringI_Split" "message512);



This is how I went about it instead of using bunch of switch statements.

Neuro Toxin 06-28-2017 02:38

Re: Chat Text Error/ExplodingImploding String
 
You probably have any error in your logs which is preventing execution after your for loop.

Riotline 06-29-2017 03:25

Re: Chat Text Error/ExplodingImploding String
 
Quote:

Originally Posted by hmmmmm (Post 2532149)
PHP Code:

char gC_Colours[][][] = {

    {
"White""{white}""\x01"},
    {
"Red""{red}""\x07"},
    {
"Light Red""{lightred}""\x0F"},
    {
"Dark Red""{darkred}""\x02"},
    {
"Blue-Gray""{bluegrey}""\x0A"},
    {
"Blue""{blue}""\x0B"},
    {
"Dark Blue""{darkblue}""\x0C"},
    {
"Orchid""{orchid}""\x0E"},
    {
"Yellow""{yellow}""\x09"},
    {
"Gold""{gold}""\x10"},
    {
"Light Green""{lightgreen}""\x05"},
    {
"Green""{green}""\x04"},
    {
"Lime""{lime}""\x06"},
    {
"Gray""{grey}""\x08"},
    {
"Gray2""{grey2}""\x0D"},
    {
"Team Colour""{teamcolor}""\x03"},
    {
"Purple""{purple}""\x03"},
    {
"Default""{default}""\x01"},

}

stock void GetRandomColours(char[] message) {

    
int I_Split;
    
char C_SplitString[64][512];

    
ExplodeString(message" "C_SplitString64512);

    while (
strlen(C_SplitString[I_Split]) > 0) {

        
int I_Random GetRandomInt(0sizeof(gC_Colours) - 4);
        
Format(C_SplitString[I_Split], 512"%s%s"gC_Colours[I_Random][2], C_SplitString[I_Split]);

        
I_Split++;

    }

    
ImplodeStrings(C_SplitStringI_Split" "message512);



This is how I went about it instead of using bunch of switch statements.

After trying to apply this, the logs show an error everytime with the C_SplitString

Neuro Toxin 06-29-2017 03:34

Re: Chat Text Error/ExplodingImploding String
 
Whats the error?

Riotline 06-29-2017 03:42

Re: Chat Text Error/ExplodingImploding String
 
Sorry the Logs from my server is showing an error from using the GetRandomColours and the C_SplitString...

Just to ask you incase I may have applied it incorrectly but I just put a string into the GetRandomColours right?

Updated Code:
Code:

//Chat
public Action OnClientSayCommand(int client, const char[] command, const char[] sArgs)
{
        new String:buffer[16], String:name[MAX_NAME_LENGTH], String:tag[128], pos = FindCharInString(sArgs, '/'), String:msg[512];
        GetClientName(client, name, sizeof(name));
        GetClientCookie(client, VIPChatTextClient, buffer, sizeof(buffer));
        CCC_GetTag(client, tag, sizeof(tag));
        strcopy(msg, sizeof(msg), sArgs);
       
        if(strcmp(buffer, "1") == 0 && pos <= -1 || pos > 1 ){
                PrintToChatAll("Test");
                GetRandomColours(sArgs);
                CPrintToChatAll("{aqua}%s\x03%s {default}: %s", tag, name, sArgs);
                return Plugin_Handled;
        }
       
        if(strcmp(buffer, "1") == 0 && pos > -1){
                return Plugin_Handled;
        }
        return Plugin_Continue;
}


hmmmmm 06-29-2017 04:08

Re: Chat Text Error/ExplodingImploding String
 
You'll have to post the error. This is the code I use exactly in my plugin and it works fine.

Riotline 06-29-2017 04:13

Re: Chat Text Error/ExplodingImploding String
 
I just needed to increase stack size.

Riotline 06-29-2017 04:19

Re: Chat Text Error/ExplodingImploding String
 
One problem now is that your random colours sometimes cause the words to go to the next line in chat and also remove the first few characters.. Etc

For example.

Input: Why do you want a quiz?
Output: o you want a quiz

hmmmmm 06-29-2017 04:43

Re: Chat Text Error/ExplodingImploding String
 
Just tested it out and it works fine for me. http://i.imgur.com/pjqgyvQ.jpg

Also suggest you use a chat processor instead of doing all this manually, will save you a lot of work and make things easier.


All times are GMT -4. The time now is 00:42.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.