Hello,
Is it possible to get the chat message, the player sent, as string?
Yes. It is possible.
1 Like
@xander1998 and how?
What you trying to make? Like a PM script?
Also is it done through commands.
@FAXES no, no commands. I’m working on a auto reply system.
Ok so how’s the message put into chat?
Could could use an event handler and do what you want with the chat messages. I’ll find a similar thing and link it.
This is not exactly what you want but could help…
You could use the chatMessage event handler and read and log certain words from the string they sent and make the code send a response if the message has certain words.
@FAXES Can you help me?
questions = {
"write all in small letters",
"don't use question mark (?)",
"seperated by commas",
}
answers = {
"This is the answer to question NR. 1 set above.",
"Use small and big letters.",
"Set a point (.) at the end.",
}
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
TriggerClientEvent("chatMessage", -1, "System", { 255, 255, 255 }, answer[line])
TriggerClientEvent("chatMessage", -1, "System", { 255, 255, 255 }, "Maybe this is not 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)
Why is this not working?