chat.AddText Constant spam?

So i’m a developer on a server and we added a hit system that requires a reason which is what we want. However if the text length is longer than 24 characters it used to just call the local variable and subtract 3 characters and add … in it’s place so it looks something like this “This person mugged me then raided my bas…” obviously it’s a necessity to be able to view the full reason and since I couldn’t figure out how to make the text scroll horizontally I just decided to make it output the text to the chatbox. It does this. However it spams the chat box an infinite amount of times until you hit “Accept” or “Deny”.

Original code:


local rlen = string.len( Reason )
		local RSub = string.sub( Reason, 1, 21 )
		if rlen <= 24 then
			draw.SimpleText( "Reason for Requesting: "..Reason, "Question_Titel", FrameWithReason:GetWide()/2, 35, HitModule.TextColor, TEXT_ALIGN_CENTER )
		else
			draw.SimpleText( "Reason for Requesting: "..RSub.."...", "Question_Titel", FrameWithReason:GetWide()/2, 35, HitModule.TextColor, TEXT_ALIGN_CENTER )	
		end
		draw.SimpleText( math.Round( timer.TimeLeft( "ChooseWisely" ) ), "Number_Time", FrameWithReason:GetWide()/2, FrameWithReason:GetTall()-50, HitModule.TextColor, TEXT_ALIGN_CENTER )
	end

My code:


local rlen = string.len( Reason )
		if rlen <= 24 then
			draw.SimpleText( "Reason for Requesting: "..Reason, "Question_Titel", FrameWithReason:GetWide()/2, 35, HitModule.TextColor, TEXT_ALIGN_CENTER )
		else
	chat.AddText( Color( 100, 255, 100 ), "Reason for hit:", Color( 255, 255, 255 ), .Reason )
		end
		draw.SimpleText( math.Round( timer.TimeLeft( "ChooseWisely" ) ), "Number_Time", FrameWithReason:GetWide()/2, FrameWithReason:GetTall()-50, HitModule.TextColor, TEXT_ALIGN_CENTER )
	end

This is probably in a hud paint hook which is called every frame I believe.

Modified it a bit. But there paint is mentioned in code connected to the problem. Look:


function RequestReason(TName, TJob, THealth, TArmor, Reward, TModel, Hitman, Requester, Reason)
	FrameWithReason = vgui.Create( "DFrame" ) 
	FrameWithReason:SetSize( 470, 330 )
	FrameWithReason:SetPos( ScrW()/2-235, ScrH()/2-205 )
	FrameWithReason:SetTitle( " " ) 
	FrameWithReason:SetVisible( true )
	FrameWithReason:SetDraggable( false ) 
	FrameWithReason:ShowCloseButton( false ) 				
	FrameWithReason:MakePopup() 
	FrameWithReason.Paint = function()
		draw.RoundedBoxEx( 4, 0, 0, 470, 55, HitModule.BGColor2, true, true, false, false )
		draw.RoundedBoxEx( 4, 0, 55, 470, 275, HitModule.BGColor, false, false, true, true )	
		draw.SimpleText( "Hit Requested - Placed By: "..Requester, "main_titel", FrameWithReason:GetWide()/2, 0, HitModule.TextColor, TEXT_ALIGN_CENTER )
		draw.SimpleText( "Would you like to take on this hit challenge?", "Question_Titel", FrameWithReason:GetWide()/2, 232.5, HitModule.TextColor, TEXT_ALIGN_CENTER )
		surface.SetDrawColor( Color( 0, 0, 0 ) )
		surface.DrawLine( 50, 30, FrameWithReason:GetWide()-50, 30 )
		local rlen = string.len( Reason )
		local RSub = string.sub( Reason, 1, 21 )
		if rlen <= 24 then
			draw.SimpleText( "Reason for Requesting: "..Reason, "Question_Titel", FrameWithReason:GetWide()/2, 35, HitModule.TextColor, TEXT_ALIGN_CENTER )
		else
		draw.SimpleText( "Reason for Requesting: "..RSub.."...", "Question_Titel", FrameWithReason:GetWide()/2, 35, HitModule.TextColor, TEXT_ALIGN_CENTER )
	chat.AddText( Color( 100, 255, 100 ), "Reason for hit: ", Color( 255, 255, 255 ), reason )
		end
		draw.SimpleText( math.Round( timer.TimeLeft( "ChooseWisely" ) ), "Number_Time", FrameWithReason:GetWide()/2, FrameWithReason:GetTall()-50, HitModule.TextColor, TEXT_ALIGN_CENTER )
	end

[editline]7th August 2015[/editline]

So I looked through it some more and the only time I can see HUDPaint being referenced is the todo list that shows your active hit, and the other HUDPaint is for the “Press E to place a hit” bit of the HUD

put it after the end of the framewithreason.paint function.

I just did and tested it. It still spams the chat. I tried chat.close() but that didn’t work either. I also tried making it so if you type more than 24 characters it would give you a warning message saying it’s too long. I’ll give you that code too.


 function AskForReason(Target, Job, Health, Armor, Reward, Model, Hitman, Reason)
	local FrameMany = vgui.Create( "DFrame" ) 
	FrameMany:SetSize( 250, 100 )
	FrameMany:SetPos( ScrW()/2-150, ScrH()/2-75 )
	FrameMany:SetTitle( " " ) 
	FrameMany:SetVisible( true )
	FrameMany:SetDraggable( false ) 
	FrameMany:ShowCloseButton( false ) 				
	FrameMany:MakePopup() 
	FrameMany.Paint = function()
		draw.RoundedBoxEx( 4, 0, 0, 250, 25, HitModule.BGColor2, true, true, false, false )
		draw.RoundedBoxEx( 4, 0, 25, 250, 75, HitModule.BGColor, false, false, true, true )	
		draw.SimpleText( "Type a Reason", "Warning_Titel", FrameMany:GetWide()/2, 0, HitModule.TextColor, TEXT_ALIGN_CENTER )
	end
	
	local CannotPanel = vgui.Create( "DPanel", FrameMany )
	CannotPanel:SetPos( 5, 30 )
	CannotPanel:SetSize( 240, 65 )
	CannotPanel.Paint = function()
		draw.RoundedBox( 4, 0, 0, 240, 65, HitModule.BGColor2 )
		draw.SimpleText( "Reason for Placing Hit: ", "Possible_Targs", CannotPanel:GetWide()/2, 5, HitModule.TextColor, TEXT_ALIGN_CENTER )
	end
	
	local TextEntry = vgui.Create( "DTextEntry", CannotPanel )	-- create the form as a child of frame
	TextEntry:SetPos( 10, 25 )
	TextEntry:SetSize( 220, 15 )
	TextEntry:SetText( "Type a reason." )
	TextEntry.OnEnter = function( self )
	end
	

I’m not going to include the bit of code I added as it broke the hit system lol.

You must call chat.AddText once…Not when you are doing hud process

Well how do I do that then? I was looking for a way for it to be called separately from the hud but I couldn’t find it. Mind giving an example? Would definitely be a great thing to learn.

You would call it anywhere on the client.

Like I said before, put it inside the AskForReason function but not inside any of the paint functions.

[lua]function RequestReason(TName, TJob, THealth, TArmor, Reward, TModel, Hitman, Requester, Reason)
FrameWithReason = vgui.Create( “DFrame” )
FrameWithReason:SetSize( 470, 330 )
FrameWithReason:SetPos( ScrW()/2-235, ScrH()/2-205 )
FrameWithReason:SetTitle( " " )
FrameWithReason:SetVisible( true )
FrameWithReason:SetDraggable( false )
FrameWithReason:ShowCloseButton( false )
FrameWithReason:MakePopup()
FrameWithReason.Paint = function()
draw.RoundedBoxEx( 4, 0, 0, 470, 55, HitModule.BGColor2, true, true, false, false )
draw.RoundedBoxEx( 4, 0, 55, 470, 275, HitModule.BGColor, false, false, true, true )
draw.SimpleText( "Hit Requested - Placed By: "…Requester, “main_titel”, FrameWithReason:GetWide()/2, 0, HitModule.TextColor, TEXT_ALIGN_CENTER )
draw.SimpleText( “Would you like to take on this hit challenge?”, “Question_Titel”, FrameWithReason:GetWide()/2, 232.5, HitModule.TextColor, TEXT_ALIGN_CENTER )
surface.SetDrawColor( Color( 0, 0, 0 ) )
surface.DrawLine( 50, 30, FrameWithReason:GetWide()-50, 30 )
local rlen = string.len( Reason )
local RSub = string.sub( Reason, 1, 21 )
if rlen <= 24 then
draw.SimpleText( "Reason for Requesting: "…Reason, “Question_Titel”, FrameWithReason:GetWide()/2, 35, HitModule.TextColor, TEXT_ALIGN_CENTER )
else
draw.SimpleText( “Reason for Requesting: “…RSub…”…”, “Question_Titel”, FrameWithReason:GetWide()/2, 35, HitModule.TextColor, TEXT_ALIGN_CENTER )
end
draw.SimpleText( math.Round( timer.TimeLeft( “ChooseWisely” ) ), “Number_Time”, FrameWithReason:GetWide()/2, FrameWithReason:GetTall()-50, HitModule.TextColor, TEXT_ALIGN_CENTER )
end
chat.AddText( Color( 100, 255, 100 ), "Reason for hit: ", Color( 255, 255, 255 ), reason )
end[/lua]

Also, anything with the word ‘titel’ should be replaced with ‘title’, right? (Just for the sake of spelling)

high, I tried your method and the request GUI wouldn’t even show up after I did that.

Is there any errors?

None. It works, kinda. Once the requester places the hit the GUI for the hitman doesn’t show up.

It’s the exact same code you posted but I added the chat printing at the end

I know, I don’t know why it’s breaking like it is.

Check to see if your old code works