Hello,
I’m working on a automatic reply system. Could someone help me fixing the lua code? Maybe i messed it up with client- and server-side.
Code:
questions = {
"write all in small letters",
"don't use question mark (?)",
"seperated by commas",
"this is question NR. 4"
}
answers = {
"This is the answer to question NR. 1 set above.",
"Use small and big letters.",
"Set a point (.) at the end.",
"This is the answer to question NR. 4 set above."
}
AddEventHandler("chatMessage", function(Source, Name, Msg)
local line = 0
local nope = 0
for quest in questions do
local line = line + 1
if(string.find(string.lower(quest), string.lower(Msg))) then
Notify(answer[line])
Notify("This may not be the answer you're looking for.")
CancelEvent()
else
local nope = nope + 1
end
end
if(nope == table.getn(questions)) then
TriggerClientEvent("chatMessage", -1, Name, { 255, 255, 255 }, Msg)
end
end)
function Notify(text)
SetNotificationTextEntry('STRING')
AddTextComponentString(text)
DrawNotification(false, true)
end
questions = {
"write all in small letters",
"don't use question mark (?)",
"seperated by commas",
"this is question NR. 4"
}
answers = {
"This is the answer to question NR. 1 set above.",
"Use small and big letters.",
"Set a point (.) at the end.",
"This is the answer to question NR. 4 set above."
}
AddEventHandler("chatMessage", function(Name, Msg)
print("Message detected.") --just for testing
local line = 0
local nope = 0
for quest in questions do
local line = line + 1
if string.find(string.lower(quest), string.lower(message)) then
Notify(answer[line])
Notify("This may not be the answer you're looking for.")
CancelEvent()
else
local nope = nope + 1
end
end
if nope == table.getn(questions) then
TriggerEvent("chat:addMessage", -1, pname, { 255, 255, 255 }, message)
end
end)
function Notify(text)
SetNotificationTextEntry('STRING')
AddTextComponentString(text)
DrawNotification(false, true)
end
Any other mistake? I’m learning LUA, came from C#. But i don’t like coding FiveM Scripts in C#.
questions = {
"write all in small letters",
"don't use question mark (?)",
"seperated by commas",
"this is question NR. 4"
}
answers = {
"This is the answer to question NR. 1 set above.",
"Use small and big letters.",
"Set a point (.) at the end.",
"This is the answer to question NR. 4 set above."
}
AddEventHandler("chatMessage", function(Source, Name, Msg)
print("Message detected.") --just for testing
local line = 0
local nope = 0
for quest in questions do
local line = line + 1
if string.find(string.lower(quest), string.lower(Msg))) then
Notify(answer[line])
Notify("This may not be the answer you're looking for.")
CancelEvent()
else
local nope = nope + 1
end
end
if nope == table.getn(questions) then
TriggerEvent("chat:addMessage", Name, { 255, 255, 255 }, Msg)
end
end)
function Notify(text)
SetNotificationTextEntry('STRING')
AddTextComponentString(text)
DrawNotification(false, true)
end