Implement spam function into vgui

Hey, I am trying to implement my spam script


concommand.Add("spamchat", function(ply, argStr)
      local spam = argStr
	  MsgC(Color( 46, 204, 113 ), ( prefix ) )
	  MsgC(Color(236, 240, 241), ("spamming chat with: " .. spam ) )
	  timer.Create( "cool_ticktocker", 0.5, 0, function()
      LocalPlayer():ConCommand("say " .. spam)
	end )  
end ) 

into this:


	DermaText:SetParent( Frame )
	DermaText:SetPos(25, 75)
	DermaText:SetTall( 20 )
	DermaText:SetWide( 350 )
	DermaText:SetEnterAllowed( true )
	DermaText.OnEnter = function()
	
end

I tried entering


spam

in the function but that didn’t work, tried making it local and it still didn’t work.

Anything is appreciated, thanks!

You would want to use:

EDIT: I thought u already had one?



If you're referring to /*
Spam Script
Coded by VenomCruster

*/,
I didn't post the whole script. There's a VGUI and that stuff that I coded and implemented.


I already have my derma/vgui set up?

What I am trying to do is something like:

[lua]
DermaText:SetParent( Frame )
DermaText:SetPos(25, 75)
DermaText:SetTall( 20 )
DermaText:SetWide( 350 )
DermaText:SetEnterAllowed( true )
DermaText.OnEnter = function()
spam
end[/lua]

(Also, that isnt the whole vgui.)

Read this again: http://wiki.garrysmod.com/page/Category:DTextEntry

Read it all.

Unless you have a function named ‘spam’, calling it wont do anything especially if you dont even use the right syntax. You have a console command, so you need a function to run a console command. Look it up: http://wiki.garrysmod.com/page/Main_Page

-snip-

[lua]function DermaText.OnEnter( self )
RunConsoleCommand(“spamchat”, self:GetValue() )
end[/lua]

A lot of people learn by doing / trying; if you learn best by reading then that’s great but not everyone learns alike. I find it admirable that people still “try” now-a-days.

Also, if you create a custom-chat box I’d suggest calling all usual hooks so if you want to prevent spam you can stop it server-side on PlayerSay. Also, the only thing that would need to be done clientside is log the time of the last message ( or see if the same message is being repeated; you could store the last few messages to compare ).

Time calculations: https://dl.dropboxusercontent.com/u/26074909/tutoring/time/understanding_time%20and_basic_time_calculations.lua.html

And, a simple cooldown script: https://dl.dropboxusercontent.com/u/26074909/tutoring/logic/simple_cooldown.lua.html - remove .html for .lua

Then:


local _p = LocalPlayer( );
if ( _p:HasCooldown( "SpammingChat" ) ) then
	print( "stop sending messages so quickly" );
else
	_p:SetCooldown( "SpammingChat", 3 );

	-- ...
end

will only allow submitting once every 3 seconds ( you’ll want to add this check server-side in addition to client-side; if you only add it on client then it’d be easy to bypass ). If you only set on server, clients may lose what they’re typing; a good option is to simply prevent the message being sent until the time is up instead of erasing the message… I’d suggeest creating a ply:CanSubmitChatMessage function to return true if able, false if not in shared-realm, although it’d be essentially the same thing as the cooldown code, so its easy enough to use that and add the check in both places.

“please learn lua before trying to make an script”

Nice.

And how are you supposed to learn without making “an” script?

Fuck, you’re right. Also notice I’m spanish

[editline]1st March 2015[/editline]

Also you are

He’s clearly trying to spam, not prevent it, and he is asking about derma controls

Ah, well the default chat-box itself has an anti spam built into it and I’m sure most custom chat-boxes do too. You’ll either need to override it, or set up a custom system to call chat.AddText manually in a networking receiver, and be sure it gets networked to the server and back.

If this is for your game-mode, easy. If this is for spamming others in other servers; good luck. You’ll either need to use a back-door or modify the server files. I won’t even begin to list the possible legal implications this may have if this is for malicious purposes.

Thanks to everyone who helped, I’ll just begin to finish a few bugs off myself.
:smile: