• Why does this not work?
    19 replies, posted
Could someone please tell my why this won't work? [CODE] MsgC(Color( 255, 255, 255 ,255 ), " What would you like to spam?\n" ) user_input = io.read() MsgC(Color( 255, 255, 255, 255 ), "You will now spam: " .. user_input ) RunConsoleCommand("say" .. user_input[/CODE] I am trying to give the user an option of what they would like to spam in chat. Thanks!
io.read() is [B]NOT[/B] a garry's mod function, neither are any of the io functions.. Use the wiki, wiki.garrysmod.com Regarding what I think your trying to do, have a look at the PlayerSay hook. (You can find information regarding it on the wiki)
You also Missed a ) on line 4.
[QUOTE=Exploderguy;47142990]You also Missed a ) on line 4.[/QUOTE] Thats just me failing to copy and paste correctly XD [editline]15th February 2015[/editline] [QUOTE=Author.;47142976]io.read() is [B]NOT[/B] a garry's mod function, neither are any of the io functions.. Use the wiki, wiki.garrysmod.com Regarding what I think your trying to do, have a look at the PlayerSay hook. (You can find information regarding it on the wiki)[/QUOTE] Ok thanks. [editline]15th February 2015[/editline] Argh I just made a big blob when trying to fix it, could someone actually type it out for me? Thanks. [editline]15th February 2015[/editline] bump
Type out what for you?
[QUOTE=Author.;47143300]Type out what for you?[/QUOTE] The code for the script, sorry, I just can't find the fix on the wiki, maybe my brain is just too small.:words:
There is no "fix". You can't read user input the same way that Lua's default io library would allow you. Two methods you [b]could[/b] use are console commands ( [url]http://wiki.garrysmod.com/page/Console_commands[/url] ) or the PlayerSay hook ( [url]http://wiki.garrysmod.com/page/GM/PlayerSay[/url] ).
[QUOTE=Willox;47143330]There is no "fix". You can't read user input the same way that Lua's default io library would allow you. Two methods you [b]could[/b] use are console commands ( [url]http://wiki.garrysmod.com/page/Console_commands[/url] ) or the PlayerSay hook ( [url]http://wiki.garrysmod.com/page/GM/PlayerSay[/url] ).[/QUOTE] Forget it, I'm too stupid :( This is what I ended up with [CODE]GM:OnPlayerChat --MsgC(Color( 255, 0, 255 ), ( prefix ) ) MsgC(Color( 255, 255, 255 ,255 ), " What would you like to spam?\n" ) user_input = GM:OnPlayerChat MsgC(Color( 255, 255, 255, 255 ), "You will now spam: " .. user_input ) GM:OnPlayerChat( Player ply, string text, false teamChat, false or true isDead )[/CODE]
Just make a console command where you can go spam "whatever." Otherwise, you'll have to hook player chat or create a derma textbox, etc. [editline]14th February 2015[/editline] [QUOTE=VenomCruster;47143355]Forget it, I'm too stupid :( This is what I ended up with [CODE]GM:OnPlayerChat --MsgC(Color( 255, 0, 255 ), ( prefix ) ) MsgC(Color( 255, 255, 255 ,255 ), " What would you like to spam?\n" ) user_input = GM:OnPlayerChat MsgC(Color( 255, 255, 255, 255 ), "You will now spam: " .. user_input ) GM:OnPlayerChat( Player ply, string text, false teamChat, false or true isDead )[/CODE][/QUOTE] This may help [code]hook.Add( "OnPlayerChat", "SpamStuff", function( ply, text ) if ( text:sub( 1, 5 ) == "!spam" or text:sub( 1, 5 ) == "/spam" ) then -- Do spam stuff here. Get the argument with text:sub( 7 ) end end )[/code]
Guys just remember that this is a Client Side script. [editline]15th February 2015[/editline] [QUOTE=code_gs;47143359]Just make a console command where you can go spam "whatever." Otherwise, you'll have to hook player chat or create a derma textbox, etc. [editline]14th February 2015[/editline] This may help [code]hook.Add( "OnPlayerChat", "SpamStuff", function( ply, text ) if ( text:sub( 1, 5 ) == "!spam" or text:sub( 1, 5 ) == "/spam" ) then -- Do spam stuff here. Get the argument with text:sub( 7 ) end end )[/QUOTE] Thanks, I will try it out. I sent a friend request too, add me.
[QUOTE=VenomCruster;47143383]Guys just remember that this is a Client Side script. [editline]15th February 2015[/editline] Thanks, I will try it out. I sent a friend request too, add me.[/QUOTE] I don't help over Steam.
[CODE]/************************************************************* Basic spam script Coded by VenomCruster *************************************************************/ prefix = "[ChatSpammer]" MsgC(Color( 255, 0, 255 ), ( prefix ) ) MsgC(Color( 255, 255, 255 ,255 ), " Welcome to a basic spam script create by VenomCruster.\n" ) hook.Add( "OnPlayerChat", "SpamStuff", function( ply, text ) if ( text:sub( 1, 5 ) == "!spam" or text:sub( 1, 5 ) == "/spam" ) then -- Do spam stuff here. Get the argument with text:sub( 7 ) end end ) function GAMEMODE:KeyPressed( ply, key ) if ( key == KEY_INSERT ) then -- I was gonna use this for a key toggle for the spam scripts, which I still wanna use. end end hook.Add ( "KeyPress", "KeyPressedHook", KeyPressed ) [/CODE] ended up with this mess. [editline]15th February 2015[/editline] Hey code_gs thanks for replying to my PM, I repealed hook.Add ( "KeyPress", "KeyPressedHook", KeyPressed ) with [CODE]hook.Add( "KeyPress", "KeyPressedHook", KeyPressSpam )[/CODE] and GAMEMODE:KeyPressed with [CODE]KeyPressSpam[/CODE] What do I need to do now? --EDIT-- Ok so I mashed it together [CODE]function KeyPressSpam( ply, key ) hook.Add( "OnPlayerChat", "SpamStuff", function( ply, text ) if ( key == KEY_INSERT ) then if ( text:sub( 1, 5 ) == "!spam" or text:sub( 1, 5 ) == "/spam" ) then text:sub( 7 ) end end ) end end hook.Add( "KeyPress", "KeyPressedHook", KeyPressSpam )[/CODE] I haven't tested it yet, could someone tell me if I am doing something wrong? --TREIILIONTH EDIT-- I ripped that out and recoded it without the option to choose what is spammed because I got sick and tired looking everywhere, but it still won't work!?!?!?!? (Note: I still would very appreciate code for giving the player a choice on what to spam.) [CODE] local enabled = true concommand.Add("spamchat",function() disabled = not disabled print("Chatspam set to "..tostring(disabled)) end) timer.Create( "my_timer", 0.5, 0, function() if not disabled then return end RunConsoleCommand("say", "Jimmy the Skid") end ) function KeyPressSpam( ply, key ) if ( key == KEY_INSERT ) then ( 'spamchat' ) end end hook.Add ( "KeyPress", "KeyPessedHook", KeyPressSpam )[/CODE] Console error: [CODE] [ERROR] lua/experiments.lua:24: syntax error near 'end' 1. unknown - lua/experiments.lua:0 [/CODE]
[QUOTE=VenomCruster;47143604] --TREIILIONTH EDIT-- I ripped that out and recoded it without the option to choose what is spammed because I got sick and tired looking everywhere, but it still won't work!?!?!?!? (Note: I still would very appreciate code for giving the player a choice on what to spam.) [CODE] local enabled = true concommand.Add("spamchat",function() disabled = not disabled print("Chatspam set to "..tostring(disabled)) end) timer.Create( "my_timer", 0.5, 0, function() if not disabled then return end RunConsoleCommand("say", "Jimmy the Skid") end ) function KeyPressSpam( ply, key ) if ( key == KEY_INSERT ) then ( 'spamchat' ) end end hook.Add ( "KeyPress", "KeyPessedHook", KeyPressSpam )[/CODE] Console error: [CODE] [ERROR] lua/experiments.lua:24: syntax error near 'end' 1. unknown - lua/experiments.lua:0 [/CODE][/QUOTE] That code looks like its came from every tutorial ever. If you want the user to input what they want to spam, use the concommand library with the Args value. (It returns a table with the arguments i believe?) you would use something like this: [code] concommand.Add("spamchat", function(ply, args) local spam = Args[1] --You would put your timer in here, make sure its a unique name , not like you had before. print("spamming chat or someshit with " .. spam) LocalPlayer():ConCommand("say " .. spam) end) --This command withh destory the above timer concommand.Add("spamchat_stop", function(ply, args) timer.Destroy("whatever you named your timer") end) [/code] not tested and very, very basic.
[QUOTE=Exploderguy;47144462]That code looks like its came from every tutorial ever. If you want the user to input what they want to spam, use the concommand library with the Args value. (It returns a table with the arguments i believe?) you would use something like this: [code] concommand.Add("spamchat", function(ply, args) local spam = Args[1] --You would put your timer in here, make sure its a unique name , not like you had before. print("spamming chat or someshit with " .. spam) LocalPlayer():ConCommand("say " .. spam) end) --This command withh destory the above timer concommand.Add("spamchat_stop", function(ply, args) timer.Destroy("whatever you named your timer") end) [/code] not tested and very, very basic.[/QUOTE] I actually got it from two threads I posted. And I will try it out and post the results, thanks. [editline]15th February 2015[/editline] It did not work, you didnt include a ( and an 'end' but I fixed that BUT then this came along when i entered the command [CODE] spamchat [/CODE]... [CODE] [ERROR] lua/spam.lua:27: attempt to index global 'Args' (a nil value) 1. unknown - lua/spam.lua:27 2. unknown - lua/includes/modules/concommand.lua:69 [/CODE] Code of script too: [CODE]concommand.Add("spamchat", function(ply, args) local spam = Args[1] timer.Create( "cool_ticktocker", 0.5, 0, function() if not disabled then return end print("spamming chat or someshit with " .. spam) LocalPlayer():ConCommand("say " .. spam) end) end) --This command withh destory the above timer concommand.Add("spamchat_stop", function(ply, args) timer.Destroy("cool_ticktocker") end)[/CODE]
Is it genuinely that difficult for people to read errors? Not trying to sound condescending, I'm just surprised. "Args" is nil on line 27 because the variable is named "args" with a lowercase "a".
NOOB QUESTION Sorry but how is it exactly suppose to work? I tried [CODE]spamchat[/CODE], [CODE]Spamchat spam [/CODE] etc.
[code] spamchat "ebola" [/code]
He could also substitute the io library with the input library + CreateMove hook could he not?
If you want to get the spam text, do the explode shit, and then, from the table get the 2nd arg
Right so I have finally came back, I tried it out but when I enter spamchat into console it spams whatever key I pressed when I ran the script. I change the number of args to 2 and it spams the second key I pressed when I ran the script. How do I fix this? Code: [CODE]/* Spam Script Coded by VenomCruster */ local prefix = "[ChatSpammer]" concommand.Add("spamchat", function(ply, args) local spam = args[1] MsgC(Color(102, 255, 102), (prefix .. "spamming chat with: " .. spam ) ) timer.Create( "cool_ticktocker", 0.5, 0, function() LocalPlayer():ConCommand("say " .. spam) end) end ) --This command will destroy the above timer concommand.Add("spamchat_stop", function(ply, args) timer.Destroy("cool_ticktocker") end) MsgC(Color( 255, 0, 255 ), ( prefix ) ) MsgC(Color( 255, 255, 255 ,255 ), "Spamscript loaded. \n" )[/CODE] [editline]28th February 2015[/editline] bump
Sorry, you need to Log In to post a reply to this thread.