Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if fs.exists("event")==false then shell.run("pastebin get L7KYC10V event") end
- os.loadAPI("event")
- if fs.exists("database")==false then shell.run("pastebin get PdhBaBdZ database") end
- os.loadAPI("database")
- local pos={}
- local peripherals={}
- local owner="NanoBob_"
- function init()
- if fs.exists("cdata/pos")==false then
- fs.open("cdata/pos","w").close()
- end
- local file=fs.open("cdata/pos","r")
- local line=file.readLine()
- file.close()
- if line=="" or line==nil then line="0,0,0" end
- pos.x=splitString(line,",",1)
- pos.y=splitString(line,",",2)
- pos.z=splitString(line,",",3)
- savePosition()
- 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
- function equipPeripheral(itemName)
- for i=1,16 do
- if turtle.getItemCount(i)>0 and turtle.getItemDetail(i).name==itemName then
- if peripherals[peripheral.getType("left")]~=nil then
- peripherals[peripheral.getType("left")]=nil
- end
- print(turtle.getItemDetail(i).name.." found")
- turtle.select(i)
- turtle.equipLeft()
- sleep(0.05)
- print(tostring(peripheral.getType("left")))
- peripherals[peripheral.getType("left")]=peripheral.wrap("left")
- end
- end
- end
- function output(message)
- if peripherals.chatBox==nil then
- equipPeripheral("PeripheralsPlusPlus:chatBox")
- end
- peripheral.wrap("left").say("<Cortana> "..message)
- end
- function savePosition()
- fs.delete("cdata/pos")
- file=fs.open("cdata/pos","w")
- file.write(pos.x..","..pos.y..","..pos.z)
- file.close()
- end
- function setPos(x,y,z)
- pos.x=tonumber(x)
- pos.y=tonumber(y)
- pos.z=tonumber(z)
- savePosition()
- end
- function posCommand(message)
- local x=splitString(message," ",1)
- local y=splitString(message," ",2)
- local z=splitString(message," ",3)
- if y==nil or y==" " then
- output("Please seperate coordinates with spaces.")
- return
- end
- setPos(x,y,z)
- output("Successfully modified coordinates")
- end
- function goCommand(message)
- local direction=splitString(message," ",1)
- local distance=tonumber(splitString(message," ",2))
- if direction==nil then direction="forward" end
- if distance==nil then distance=1 end
- print(direction..":"..distance)
- if direction=="left" then
- turtle.turnLeft()
- for i=1,distance do
- turtle.forward()
- end
- elseif direction=="right" then
- turtle.turnRight()
- for i=1,distance do
- turtle.forward()
- end
- elseif turtle[direction]~=nil then
- for i=1,distance do
- turtle[direction]()
- end
- end
- end
- function digCommand(message)
- local direction=splitString(message," ",1)
- local distance=tonumber(splitString(message," ",2))
- if direction==nil then direction="forward" end
- if distance==nil then distance=1 end
- print(direction..":"..distance)
- if direction=="left" then
- turtle.turnLeft()
- for i=1,distance do
- turtle.forward()
- turtle.dig()
- end
- elseif direction=="right" then
- turtle.turnRight()
- for i=1,distance do
- turtle.forward()
- turtle.dig()
- end
- elseif turtle[direction]~=nil then
- for i=1,distance do
- turtle[direction]()
- if direction=="up" then
- turtle.digUp()
- elseif direction=="forward" then
- turtle.dig()
- elseif direction=="down" then
- turtle.digDown()
- end
- end
- end
- end
- function runCommand(message)
- output(tostring(shell.run(message)))
- end
- local insults={"hhh","Fuck you too","Go fuck yourself","I dare you to do that again motherfucker!"}
- function insulted(message,player)
- local returnable=insults[math.random(#insults)]
- if returnable=="hhh" then
- returnable=message
- end
- output(player.." "..returnable)
- end
- local keyStrings={
- ["setpos"]=posCommand,
- ["go"]=goCommand,
- ["fuck you"]=insulted,
- ["run"]=runCommand,
- ["dig"]=digCommand,
- }
- local restricted={
- ["setpos"]=true,
- ["go"]=true,
- ["run"]=true,
- ["dig"]=true,
- }
- function handleInput(player,message)
- if string.lower(message):match("cortana")==nil then return end
- local message=string.gsub(message,"cortana " ,"")
- for str,func in pairs(keyStrings) do
- local message=string.lower(message)
- if message:match(str)~=nil then
- print("Command detected: "..str..". In: "..message)
- local message=string.gsub(message,str.." " ,"")
- if restricted[str]==true and player~=owner then
- output("I'm sorry but I can not do this for you.")
- break
- end
- keyStrings[str](message,player)
- break
- end
- end
- end
- event.addHandler("chat",handleInput)
- init()
- equipPeripheral("PeripheralsPlusPlus:chatBox")
- while true do
- event.handleCCEvents()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement