Raised This Month: $12 Target: $400
 3% 

Chat Text Error/ExplodingImploding String


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Riotline
AlliedModders Donor
Join Date: Oct 2015
Location: Half Life 3
Old 06-28-2017 , 00:59   Chat Text Error/ExplodingImploding String
Reply With Quote #1

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;
	}
__________________
Riotline is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 06-28-2017 , 02:29   Re: Chat Text Error/ExplodingImploding String
Reply With Quote #2

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.
hmmmmm is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 06-28-2017 , 02:38   Re: Chat Text Error/ExplodingImploding String
Reply With Quote #3

You probably have any error in your logs which is preventing execution after your for loop.
__________________
Neuro Toxin is offline
Riotline
AlliedModders Donor
Join Date: Oct 2015
Location: Half Life 3
Old 06-29-2017 , 03:25   Re: Chat Text Error/ExplodingImploding String
Reply With Quote #4

Quote:
Originally Posted by hmmmmm View Post
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
__________________
Riotline is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 06-29-2017 , 03:34   Re: Chat Text Error/ExplodingImploding String
Reply With Quote #5

Whats the error?
__________________
Neuro Toxin is offline
Riotline
AlliedModders Donor
Join Date: Oct 2015
Location: Half Life 3
Old 06-29-2017 , 03:42   Re: Chat Text Error/ExplodingImploding String
Reply With Quote #6

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;
}
__________________
Riotline is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 06-29-2017 , 04:08   Re: Chat Text Error/ExplodingImploding String
Reply With Quote #7

You'll have to post the error. This is the code I use exactly in my plugin and it works fine.
hmmmmm is offline
Riotline
AlliedModders Donor
Join Date: Oct 2015
Location: Half Life 3
Old 06-29-2017 , 04:13   Re: Chat Text Error/ExplodingImploding String
Reply With Quote #8

I just needed to increase stack size.
__________________
Riotline is offline
Riotline
AlliedModders Donor
Join Date: Oct 2015
Location: Half Life 3
Old 06-29-2017 , 04:19   Re: Chat Text Error/ExplodingImploding String
Reply With Quote #9

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
__________________
Riotline is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 06-29-2017 , 04:43   Re: Chat Text Error/ExplodingImploding String
Reply With Quote #10

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.

Last edited by hmmmmm; 06-29-2017 at 04:43.
hmmmmm is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:05.


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