82 posts
Posted 19 August 2013 - 02:32 PM
I'm making an over-complicated door program, and I'm trying to make it so I can use a chat box to give access to other players. I want to be able to take a string out of a message that already has other things, like *trigger message*: playername. But I have no idea how to do this.
1610 posts
Posted 19 August 2013 - 04:50 PM
Wrong section, this belongs in "Ask a Pro"
Answer: the only way to grab chat would be with the Misc Peripherals chatbox, or the OpenPeripherals thin that grabs chat starting with $$. Not quite sure what you're looking for, but check those out a bit.
If the problem is the other parts of the message, string.gsub() and string.sub() will be your best friends.
26 posts
Location
Australia
Posted 19 August 2013 - 04:56 PM
So if you have the chat box with a loop that gets the string of the public chat message, you could make it something like
local chat = peripheral.wrap(side)
while true do
event,player,message = os.pullEvent("chat")
local words = {}
for word in message:gmatch("%w+") do
table.insert(words,word)
end
if words[1] == "trigger" and words[2] == "message" and <put stuff to test here> then
<Do Stuff>
end
end
This will allow someone to say in public chat
trigger message bla
or whatever you want it to be, so you can make it check for a specific order
Say in a different example, "Unlock Base Now" you could make it check for words[1], words[2],words[3]
Hope That helps even if this in the wrong section
82 posts
Posted 19 August 2013 - 05:27 PM
I swear I clicked ask a pro. Well then.
8543 posts
Posted 19 August 2013 - 06:45 PM
Moved to Ask a Pro.
331 posts
Posted 20 August 2013 - 06:57 AM
you can use
if string.find(message, "trigger:") then -- if the message conatains 'trigger:'
a,b string.find("trigger:") -- return start pos and end pos of trigger
-- then split the string after the :
command = string.split(message, b+1, #message) -- split from spot after colon to the end of string
print(command)
end
-- now this should print 'kill' if message was 'trigger: kill'