Jump to content

How to create chat bot


Recommended Posts

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 by msyyn
  • Thanks 1
Link to comment
  • 2 years later...
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 by Moony
Link to comment

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 by ReZurrecti0n
Link to comment
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 by Moony
Optimization.
Link to comment

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
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 by Moony
Link to comment

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...