Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local speaker=peripheral.wrap("right")
- local chatBox=peripheral.wrap("left")
- local commands={
- ["Hey"]=
- function(player,message)
- speaker.speak("Hey "..string.gsub(player,"_",""),10)
- end,
- ["Whatsup"]=
- function(player,message)
- speaker.speak("I am AI, I do not have feelings.",10)
- end,
- ["go"]=
- function(player,message)
- local message=string.lower(message)
- local message=string.gsub(message,"nanoturtle","")
- local direction=splitString(message," ",2)
- local blocks=tonumber(spltString(message," ",3))
- if direction=="left" then
- turtle.turnLeft()
- for i=1,blocks do
- turtle.forward()
- end
- elseif direction=="right" then
- turtle.turnRight()
- for i=1,blocks do
- turtle.forward()
- end
- elseif direction=="forwards" then
- for i=1,blocks do
- turtle.forward()
- end
- elseif direction="back" then
- for i=1,blocks do
- turtle.back()
- end
- elseif direction=="up" then
- for i=1,blocks do
- turtle.up()
- end
- elseif direction=="down" then
- for i=1,blocks do
- turtle.down()
- end
- end
- end,
- }
- function main()
- event,player,message=os.pullEvent()
- if event=="chat" then
- if string.find(string.lower(message),"nanoturtle")==nil then return end
- for messageString,messageFunction in pairs(commands) do
- if string.find(string.lower(message),string.lower(messageString))~=nil then
- messageFunction(player,message)
- end
- end
- end
- end
- function splitString(sourceString,splittingChar,index)
- results={}
- currentWord=""
- for i=1,string.len(sourceString) do
- letter=string.sub(sourceString,i,i)
- if letter==splittingChar then
- results[#results+1]=currentWord
- currentWord=""
- else
- currentWord=currentWord..letter
- end
- end
- results[#results+1]=currentWord
- return results[index]
- end
- while true do
- main()
- end
Add Comment
Please, Sign In to add comment