#Heshan||eUNLOCK|| Posted November 24, 2017 Share Posted November 24, 2017 How to creaye a chat bot for output some words loop in main chat pls help me ? Link to comment
msyyn Posted November 24, 2017 Share Posted November 24, 2017 (edited) local messages = { "Visit our website at www.google.com!", "Did you know? These messages are automated!", "Add another message here!" } local prefix = "[INFO] #FFFFFF" -- message prefix local interval = 5 -- time between messages (minutes) function outputRandomMessage() local msg = messages[math.random(#messages)] outputChatBox(prefix .. msg, root, 3, 169, 244, true) end setTimer(outputRandomMessage, interval * 60 * 1000, 0) Output looks like: [INFO] Did you know? These messages are automated! Are you looking for something like this? Or what do you mean by words loop. Edited November 24, 2017 by msyyn 1 Link to comment
Moony Posted February 19, 2020 Share Posted February 19, 2020 (edited) On 24/11/2017 at 08:57, msyyn said: local messages = { "Visit our website at www.google.com!", "Did you know? These messages are automated!", "Add another message here!" } local prefix = "[INFO] #FFFFFF" -- message prefix local interval = 5 -- time between messages (minutes) function outputRandomMessage() local msg = messages[math.random(#messages)] outputChatBox(prefix .. msg, root, 3, 169, 244, true) end setTimer(outputRandomMessage, interval * 60 * 1000, 0) I apologize for the necroing, but I have a quick question. If I wanted the interval to be less than a minute, so I can output a few messages that need to go connected, how would I change the interval? What about having an order, instead of outputting the messages randomly? Edited February 19, 2020 by Moony Link to comment
ReZurrecti0n Posted February 19, 2020 Share Posted February 19, 2020 (edited) Just set the interval for the desired seconds and then just rip out the 60 * setTimer(outputRandomMessage, interval * 1000, 0) -- Now interval is mearsured in seconds instead of minutes As for the order, replace the random bit with a new variable and after each message, add to the variable, also reset it when it reaches the last possible message number = 0 -- Declare the variable outside the function function outputRandomMessage() number = number + 1 -- Add +1 so it changes each time the function is called local msg = messages[number] -- Display the Message if number = 3 then -- If it just Displayed the last Message... number = 0 -- Reset it to start all over again end Edited February 19, 2020 by ReZurrecti0n Link to comment
Moony Posted February 19, 2020 Share Posted February 19, 2020 (edited) 8 hours ago, ReZurrecti0n said: As for the order, replace the random bit with a new variable and after each message, add to the variable, also reset it when it reaches the last possible message number = 0 -- Declare the variable outside the function function outputRandomMessage() number = number + 1 -- Add +1 so it changes each time the function is called local msg = messages[number] -- Display the Message if number = 3 then -- If it just Displayed the last Message... number = 0 -- Reset it to start all over again end Thanks for the quick answer. I'm getting an error: SCRIPT ERROR: chatbot\script.Lua:14: 'then' expected near '=' ERROR: Loading script failed: chatbot\script.Lua:14: 'then' expected near '=' Edited February 19, 2020 by Moony Optimization. Link to comment
ReZurrecti0n Posted February 19, 2020 Share Posted February 19, 2020 Sorry, forgot to add the "end" for the function itself... number = 0 -- Declare the variable outside the function function outputRandomMessage() number = number + 1 -- Add +1 so it changes each time the function is called local msg = messages[number] -- Display the Message if number = 3 then -- If it just Displayed the last Message... number = 0 -- Reset it to start all over again end end -- Forgotten End :( Link to comment
Moony Posted February 20, 2020 Share Posted February 20, 2020 (edited) On 19/02/2020 at 17:53, ReZurrecti0n said: Sorry, forgot to add the "end" for the function itself... number = 0 -- Declare the variable outside the function function outputRandomMessage() number = number + 1 -- Add +1 so it changes each time the function is called local msg = messages[number] -- Display the Message if number = 3 then -- If it just Displayed the last Message... number = 0 -- Reset it to start all over again end end -- Forgotten End :( It is still giving me an error in debugscript. I've also noticed that there is no outputChatBox in your script. I've tried the following, but it gives me an error (line 14, 'then' expect near '=') in every option: Spoiler local messages = { "Presioná 'F9' para saber acerca de las funciones del servidor.", "Poné el asado pa' lo' pibe' con /asado.", "Festejá un gol con /petardos." } local prefix = "#FA0000[#BBBBBBINFO#FA0000]: #BBBBBB" -- message prefix local interval = 45 -- time between messages (s) number = number + 1 function outputRandomMessage() local msg = messages(number) if number = 3 then number = 0 outputChatBox(prefix .. msg, root, 3, 169, 244, true) end end setTimer(outputRandomMessage, interval * 1000, 0) I did some minor changes to the timer, text, and color codes. Spoiler local messages = { "Presioná 'F9' para saber acerca de las funciones del servidor.", "Poné el asado pa' lo' pibe' con /asado.", "Festejá un gol con /petardos." } local prefix = "#FA0000[#BBBBBBINFO#FA0000]: #BBBBBB" -- message prefix local interval = 45 -- time between messages (s) number = number + 1 function outputRandomMessage() local msg = messages(number) if number = 3 then number = 0 end outputChatBox(prefix .. msg, root, 3, 169, 244, true) end setTimer(outputRandomMessage, interval * 1000, 0) I did some minor changes to the timer, text, and color codes. The only difference is the 'end' over and under 'outputChatBox'. Edited February 20, 2020 by Moony Link to comment
ReZurrecti0n Posted February 21, 2020 Share Posted February 21, 2020 There are no messages or not even the timer itself either, you will need to work with the base script and then throw in the changes so that you have the entire working script. You won't learn much if you just copy and paste, it's better you construct your own. But here would be the final result anyway: local messages = { "Visit our website at www.google.com!", "Did you know? These messages are automated!", "Add another message here!" } local prefix = "[INFO] #FFFFFF" -- message prefix local interval = 5 -- time between messages (minutes) number = 0 -- Declare the variable outside the function function outputRandomMessage() number = number + 1 -- Add +1 so it changes each time the function is called local msg = messages[number] -- Display the Message outputChatBox(prefix .. msg, root, 3, 169, 244, true) -- Actual Message being sent out to everyone! if number = 3 then -- If it just Displayed the last Message... number = 0 -- Reset it to start all over again end end -- Forgotten End :( setTimer(outputRandomMessage, interval * 60 * 1000, 0) -- Message Timer Link to comment
#\_oskar_/# Posted February 21, 2020 Share Posted February 21, 2020 @ReZurrecti0n line 16 : you forgot to add = if number == 3 then 1 Link to comment
ReZurrecti0n Posted February 21, 2020 Share Posted February 21, 2020 3 hours ago, #\_oskar_/# said: @ReZurrecti0n line 16 : you forgot to add = if number == 3 then Thank you, you're right, thank you for pointing that out 1 Link to comment
#\_oskar_/# Posted February 21, 2020 Share Posted February 21, 2020 2 hours ago, ReZurrecti0n said: Thank you, you're right, thank you for pointing that out np 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now