Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- chatLog = {}
- for i = 1, 10 do
- chatLog[i] = " "
- end
- selectMode = "skin"
- emotion = 1
- function saveTab(file, tab)
- fp = fs.open(file, "w")
- fp.write(textutils.serialize(tab))
- fp.close()
- end
- function getTab(file)
- fp = fs.open(file, "r")
- return textutils.unserialize(fp.readAll())
- end
- if fs.exists("bild") == false then
- shell.run("pastebin get SawrHPLY bild")
- end
- if fs.exists("skin") == false then
- shell.run("pastebin get Qz9j4CFq skin")
- end
- if fs.exists("loadImage") == false then
- shell.run("pastebin get 3iBE8juA loadImage")
- end
- if fs.exists("turtlearmee") == false then
- shell.run("pastebin get KCW8FCWG turtlearmee")
- end
- if fs.exists("scan") == false then
- shell.run("pastebin get nJaq5St4 scan")
- end
- shell.run("scan")
- if fs.exists("update") == false then
- fp = fs.open("update", "a")
- fp.writeLine("shell.run('rm startup')")
- fp.writeLine("shell.run('pastebin get YWNLRSpK startup')")
- fp.writeLine("shell.run('reboot')")
- fp.close()
- end
- if fs.exists("face") == false then
- fp = fs.open("face", "a")
- fp.writeLine("local args = {...}")
- fp.writeLine(
- "m=peripheral.wrap(args[2]) h=tonumber(args[1]) m.setBackgroundColor(colors.yellow) m.clear() bild=paintutils.loadImage('bild')"
- )
- fp.writeLine("paintutils.drawImage(bild,1,h)")
- fp.close()
- end
- if fs.exists("playerData") == false then
- playerData = {}
- print("Bitte Lege einen Owner fest:")
- playerData["owner"] = io.read()
- print("Bittle Lege einen Namen fest:")
- playerData["myName"] = io.read()
- saveTab("playerData", playerData)
- end
- playerData = getTab("playerData")
- owner = playerData["owner"]
- myName = playerData["myName"]
- function wrapP(peripheralName)
- if os.version() ~= "CraftOS 1.5" then
- if peripheralName == nil then
- print("Fehler")
- end
- local peripherals = peripheral.getNames()
- local i = 1
- while i < #peripherals and peripheral.getType(peripherals[i]) ~= peripheralName do
- i = i + 1
- end
- if peripheral.getType(peripherals[i]) == peripheralName then
- return peripheral.wrap(peripherals[i]), peripherals[i]
- else
- return nil
- end
- else
- local sides = {"top", "bottom", "left", "right", "front", "back"}
- for i = 1, #sides do
- if peripheral.getType(sides[i]) == peripheralName then
- return peripheral.wrap(sides[i]), sides[i]
- end
- end
- end
- end
- function wrapPs(peripheralName)
- periTab = {}
- sideTab = {}
- if peripheralName == nil then
- print("Fehler")
- end
- local peripherals = peripheral.getNames()
- local i2 = 1
- for i = 1, #peripherals do
- if peripheral.getType(peripherals[i]) == peripheralName then
- periTab[i2] = peripheral.wrap(peripherals[i])
- sideTab[i2] = peripherals[i]
- i2 = i2 + 1
- end
- end
- if periTab ~= {} then
- return periTab, sideTab
- else
- return nil
- end
- function getPSide(peripheralName)
- if peripheralName == nil then
- print("Fehler")
- end
- local peripherals = peripheral.getNames()
- local i = 1
- while i < #peripherals and peripheral.getType(peripherals[i]) ~= peripheralName do
- i = i + 1
- end
- if peripheral.getType(peripherals[i]) == peripheralName then
- return peripherals[i]
- else
- return nil
- end
- end
- end
- function wrapper()
- c = wrapP("chat")
- if os.version() == "CraftOS 1.7" then
- c = wrapP("chat_box")
- end
- tb = wrapP("terminal_glasses_bridge")
- if os.version() == "CraftOS 1.7" then
- tb = wrapP("openperipheral_bridge")
- end
- sp = wrapP("speaker")
- pr = wrapP("printer")
- mon, monSide = wrapPs("monitor")
- dr, drSide = wrapP("drive")
- nb = wrapP("note")
- modem, modemSide = wrapPs("modem")
- me = wrapP("tileinterface")
- dr = wrapP("droneInterface")
- for i = 1, #modem do
- if modem[i].isWireless then
- rednetSide = modemSide[i]
- rednet.open(rednetSide)
- end
- end
- end
- wrapper()
- -- 1=normal
- -- -40=angry
- -- -81=Sad
- function loadFace()
- for i = 1, #mon do
- if mon[i].getSize() == 61 then
- m = mon[i]
- shell.run("monitor " .. monSide[i] .. " face " .. emotion .. " " .. monSide[i])
- end
- end
- end
- function loadSkin(arg)
- if mon ~= nil then
- if arg ~= nil then
- if tonumber(arg) == nil then
- monSideCurrent = arg
- else
- monSideCurrent = monSide[arg]
- end
- monCurrent = peripheral.wrap(monSideCurrent)
- if monSideCurrent ~= nil then
- monCurrent.setTextScale(1)
- if monCurrent.getSize() == 7 then
- monCurrent.setTextScale(0.5)
- end
- if monCurrent.getSize() == 18 then
- monCurrent.setTextScale(1)
- end
- if monCurrent.getSize() == 29 then
- monCurrent.setTextScale(2)
- end
- if monCurrent.getSize() == 39 then
- monCurrent.setTextScale(3)
- end
- shell.run("monitor " .. monSideCurrent .. " loadImage skin")
- end
- end
- loadFace()
- end
- end
- function loadInfo(arg)
- if tonumber(arg) == nil then
- monSideCurrent = arg
- else
- monSideCurrent = monSide[arg]
- end
- monCurrent = peripheral.wrap(monSideCurrent)
- if monSideCurrent ~= nil then
- monCurrent.setTextScale(1)
- monXScale, monYScale = monCurrent.getSize()
- if monXScale == 7 then
- monCurrent.setTextScale(0.5)
- end
- if monXScale == 18 then
- monCurrent.setTextScale(1)
- end
- if monXScale == 29 then
- monCurrent.setTextScale(2)
- end
- if monXScale == 39 then
- monCurrent.setTextScale(3)
- end
- monXScale, monYScale = monCurrent.getSize()
- monCurrent.setCursorPos((monXScale - #textutils.formatTime(os.time())) / 2, monYScale / 2)
- monCurrent.write(textutils.formatTime(os.time()))
- end
- end
- loadSkin(math.random(1, #monSide))
- function say(message)
- print(message)
- if c ~= nil then
- c.say(myName .. ": " .. message)
- sleep(0.5)
- end
- if tb ~= nil then
- glassesChat(message)
- if os.version() == "CraftOS 1.7" then
- tb.sync()
- end
- end
- if sp ~= nil then
- sp.speak(message)
- end
- end
- function eval(command)
- fp = fs.open("eval", "w")
- fp.write(command)
- fp.close()
- shell.run("eval")
- shell.run("rm eval")
- end
- function glassesChat(message)
- if message then
- if #chatLog >= 11 then
- for i = 1, #chatLog do
- chatLog[i] = chatLog[i + 1]
- end
- end
- chatLog[#chatLog + 1] = myName .. " : " .. message
- else
- if event == "chat" then
- if #chatLog >= 11 then
- for i = 1, #chatLog do
- chatLog[i] = chatLog[i + 1]
- end
- end
- chatLog[#chatLog + 1] = arg1 .. " : " .. arg2
- end
- if event == "chat_death" then
- if #chatLog >= 11 then
- for i = 1, #chatLog do
- chatLog[i] = chatLog[i + 1]
- end
- end
- chatLog[#chatLog + 1] = arg1 .. " starb"
- end
- if event == "chat_command" then
- if #chatLog >= 11 then
- for i = 1, #chatLog do
- chatLog[i] = chatLog[i + 1]
- end
- end
- chatLog[#chatLog + 1] = arg2 .. " : " .. arg1
- end
- if event == "glasses_chat_command" then
- if #chatLog >= 11 then
- for i = 1, #chatLog do
- chatLog[i] = chatLog[i + 1]
- end
- end
- chatLog[#chatLog + 1] = arg2 .. " : " .. arg4
- end
- end
- tb.clear()
- for i = 1, #chatLog do
- tb.addBox(1, 1, 400, 100, 0x000000, 0.1)
- tb.addText(1, i * 8, chatLog[i], 0xffffff)
- end
- if os.version() == "CraftOS 1.7" then
- tb.sync()
- end
- end
- function search(args1, args2, args3)
- function stringReplace(source, delString, repString)
- if string.find(source, delString) then
- local stringPos = {string.find(source, delString)}
- source = string.sub(source, 1, stringPos[1] - 1) .. repString .. string.sub(source, stringPos[2] + 1)
- end
- return (source)
- end
- function stringReplaceAll(source, delString, repString)
- while string.find(source, delString) do
- local stringPos = {string.find(source, delString)}
- source = string.sub(source, 1, stringPos[1] - 1) .. repString .. string.sub(source, stringPos[2] + 1)
- end
- return (source)
- end
- function stringDel(source, delString)
- local stringPos = {string.find(source, delString)}
- source = string.sub(source, 1, stringPos[1] - 1) .. string.sub(source, stringPos[2] + 1)
- return (source)
- end
- function stringDelAll(source, delString)
- while string.find(source, delString) do
- source = stringDel(source, delString)
- end
- return source
- end
- results = {}
- url = http.get("http://www.bing.com/search?q=" .. stringReplaceAll(args1, " ", "+"))
- html = url.readAll()
- i = 255
- while i >= 0 do
- html = stringDelAll(html, "&#" .. tostring(i) .. ";")
- i = i - 1
- end
- html = stringDelAll(html, "<strong>")
- html = stringDelAll(html, "</strong>")
- html = stringDelAll(html, """)
- html = stringDelAll(html, ";")
- html = stringDelAll(html, ":")
- i = 1
- while string.find(html, "<p>") do
- local stringPos1 = {string.find(html, "<p>")}
- local stringPos2 = {string.find(html, "</p>")}
- results[i] = string.sub(html, stringPos1[2] + 1, stringPos2[1] - 1)
- html = stringDel(html, "<p>")
- html = stringDel(html, "</p>")
- i = i + 1
- end
- amount = 4
- if args2 then
- amount = tonumber(args2)
- end
- num = nil
- if tonumber(args3) == nil then
- for i = 1, amount do
- if results[i] ~= nil then
- if tb ~= nil then
- glassesChat("Result:" .. i .. string.sub(results[i], 1, 200))
- if os.version() == "CraftOS 1.7" then
- tb.sync()
- end
- if c ~= nil then
- c.say("Result:" .. i .. string.sub(results[i], 1, 200))
- sleep(0.5)
- end
- end
- --say("Result:"..i..string.sub(results[i],1,200))
- end
- end
- else
- num = tonumber(args3)
- print(results[num])
- end
- end
- function addButton(id, data, func)
- button = {}
- button.data = data
- button.func = func
- buttons[id] = button
- end
- function giveItemFromMe(fingerprint, amount)
- fi=fingerprint
- eval("me.exportItem(fi,'up',"..amount..")")
- end
- function loadConfig()
- if fs.exists("config")==false then
- fp=fs.open("config","w")
- fp.writeLine("importDirection='north'")
- fp.writeLine("exportDirection='south'")
- fp.writeLine("windowSizeX=950")
- fp.writeLine("windowSizeY=400")
- fp.close()
- end
- shell.run("config")
- end
- loadConfig()
- function showItemSelection(items)
- buttons = {}
- t.clear()
- y = 1
- x = 1
- local xMax = windowSizeX
- local yMax = windowSizeY
- i1 = 1
- t.addBox(1, 1, xMax, math.ceil(#items / (xMax / 20)) * 20, 0x000000, 0.5)
- while i1 <= yMax do
- while x <= xMax do
- if items[i1] ~= nil then
- data = {}
- data.component = t.addIcon(x, y, items[i1].fingerprint.id, items[i1].fingerprint.dmg)
- if items[i1].size > 1 then
- data.text = t.addText(x, y + 10, tostring(items[i1].size), 0)
- end
- data.item = items[i1]
- function func(data)
- giveItemFromMe(data.item.fingerprint, 1)
- --print(data.item.name)
- if data.text ~= nil then
- eval(data.text.setText(data.text.getText() - 1))
- else
- data.component.delete()
- end
- t.sync()
- end
- addButton(data.component.getId(), data, func)
- end
- i1 = i1 + 1
- x = x + 20
- end
- x = 1
- y = y + 20
- end
- t.sync()
- end
- function scanItems()
- if me ~= nil then
- items = me.getAvailableItems()
- itemById = {}
- for i = 1, #items do
- itemById[items[i].fingerprint.id .. "/" .. items[i].fingerprint.dmg] = items[i]
- end
- end
- end
- --main
- while true do
- event, arg1, arg2, arg3, arg4 = os.pullEvent()
- --Events
- --say(event)
- if event == "peripheral" then
- pType = arg1
- wrapper()
- say("neue Peripheral " .. peripheral.getType(pType) .. " gefunden.")
- if peripheral.getType(pType) == "monitor" then
- loadSkin(arg1)
- end
- end
- if event == "monitor_resize" then
- loadSkin(arg1)
- sleep(1)
- end
- if event == "glasses_capture" then
- scanItems()
- showItemSelection(items)
- end
- if event == "glasses_component_mouse_down" then
- componentId = arg4
- --say(arg4)
- if buttons[componentId] ~= nil then
- if buttons[componentId].func ~= nil then
- buttons[componentId].func(buttons[componentId].data)
- end
- end
- end
- if event == "glasses_release" then
- t.clear()
- t.sync()
- end
- if os.version() == "CraftOS 1.7" then
- if event == "glasses_key_down" then
- if arg4 == 200 then
- rednet.broadcast("turtle do turtle.forward()")
- end
- if arg4 == 208 then
- rednet.broadcast("turtle do turtle.back()")
- end
- if arg4 == 203 then
- rednet.broadcast("turtle do turtle.turnLeft()")
- end
- if arg4 == 205 then
- rednet.broadcast("turtle do turtle.turnRight()")
- end
- if arg4 == 57 or arg4 == 78 then
- rednet.broadcast("turtle do turtle.up()")
- end
- if arg4 == 54 or arg4 == 74 then
- rednet.broadcast("turtle do turtle.down()")
- end
- if arg4 == 211 then
- rednet.broadcast("turtle do turtle.dig()")
- end
- if arg4 == 29 or arg4 == 157 then
- rednet.broadcast("turtle do turtle.place()")
- end
- if arg4 == 19 then
- rednet.broadcast("turtle do shell.run('refuel all()') turtle.select(1) ")
- end
- if arg4 == 42 then
- rednet.broadcast("turtle do p.toggle()")
- end
- if dr ~= nil then
- drPos = {dr.getDronePosition()}
- dr.clearArea()
- if arg4 == 200 then
- dr.addArea(drPos[1] + 1, drPos[2], drPos[3])
- end
- if arg4 == 208 then
- dr.addArea(drPos[1] - 1, drPos[2], drPos[3])
- end
- if arg4 == 203 then
- dr.addArea(drPos[1], drPos[2], drPos[3] + 1)
- end
- if arg4 == 205 then
- dr.addArea(drPos[1], drPos[2], drPos[3] - 1)
- end
- if arg4 == 57 then
- dr.addArea(drPos[1], drPos[2] + 1, drPos[3])
- end
- if arg4 == 42 or arg4 == 54 then
- dr.addArea(drPos[1], drPos[2] - 1, drPos[3])
- end
- dr.setAction("goTo")
- sleep(0.5)
- end
- end
- end
- if event == "monitor_touch" then
- for i = 1, #mon do
- mon[i].clear()
- end
- if selectMode == "skin" then
- loadSkin(arg1)
- end
- if selectMode == "info" then
- mInfo = arg1
- loadInfo(mInfo)
- infoTimer = os.startTimer(1)
- end
- end
- if event == "timer" then
- if arg1 == jumpTimer then
- monCurrent.clear()
- loadSkin(math.random(1, #monSide))
- if message ~= myName .. " stop" then
- jumpTimer = os.startTimer(2)
- else
- say("ok")
- end
- end
- if arg1 == infoTimer then
- if selectMode == "info" then
- loadInfo(mInfo)
- infoTimer = os.startTimer(1)
- end
- end
- end
- if event == "chat" or event == "chat_command" or event == "glasses_chat_command" or event == "chat_message" then
- if tb ~= nil then
- glassesChat()
- end
- if event == "chat" then
- player = arg1
- message = arg2
- end
- if event == "chat_message" then
- player = arg2
- message = arg3
- end
- if event == "glasses_chat_command" then
- player = arg2
- message = arg4
- end
- if event == "chat_command" then
- player = arg2
- message = arg1
- end
- if rednetSide ~= nil then
- rednet.broadcast("turtle do " .. message)
- end
- if string.sub(message, 1, #tostring(myName .. " berechne ")) == myName .. " berechne " then
- fp = fs.open("rechner", "w")
- fp.writeLine("say(tostring(" .. string.sub(message, #tostring(myName .. " berechne ")) .. "))")
- fp.close()
- shell.run("rechner")
- end
- if string.sub(message, 1, #tostring(myName .. " bing ")) == myName .. " bing " then
- fp = fs.open("rechner", "w")
- say(string.sub(message, #tostring(myName .. " bing ")))
- search(string.sub(message, #tostring(myName .. " bing ")), 10)
- fp.close()
- shell.run("rechner")
- end
- if string.sub(message, 1, #tostring(myName .. " list ")) == myName .. " list " then
- if me ~= nil and tb ~= nil then
- searchId = string.sub(message, #(myName .. " list ") + 1)
- scanItems()
- i2 = 1
- itemsAlike = {}
- for i = 1, #items do
- if string.find(string.lower(items[i].fingerprint.id .. "/" .. items[i].fingerprint.dmg), string.lower(searchId)) then
- itemsAlike[i2] = items[i].fingerprint.id .. "/" .. items[i].fingerprint.dmg, searchId
- i2 = i2 + 1
- end
- end
- for i = 1, 10 do
- if itemsAlike[i] ~= nil then
- say(itemsAlike[i] .. " Amount:" .. itemById[itemsAlike[i]].size)
- end
- end
- end
- end
- if string.sub(message, 1, #tostring(myName .. " gib mir ")) == myName .. " gib mir " then
- if me ~= nil and tb ~= nil then
- fingerprint = {}
- scanItems()
- fp = fs.open("give", "w")
- fp.writeLine(
- "fingerprint=itemById[string.sub(message,#(myName..' gib mir ')+1),string.find(message,",
- ")-1].fingerprint me.exportItem(fingerprint,'up',tonumber(string.sub(message,string.find(message,",
- ")+1)))"
- )
- fp.close()
- shell.run("give")
- end
- end
- if message == myName .. " update" then
- say("Ok bis gleich")
- shell.run("update")
- shell.run("reboot")
- end
- if message == myName .. " jump" then
- say("such mich :)")
- jumpTimer = os.startTimer(2)
- end
- if string.find(message, myName .. " notiere") ~= nil then
- say("Ich hoere")
- pr.newPage()
- pr.setPageTitle(string.sub(message, #(myName .. " notiere") + 2))
- y = 1
- while message ~= "schluss" do
- event, dump, player, dump, message = os.pullEvent("glasses_chat_command")
- if message ~= "schluss" then
- x = 1
- for i = 1, math.floor(#message / 26) + 1 do
- pr.setCursorPos(1, y)
- pr.write(string.sub(message, x, x + 26))
- say(string.sub(message, x, x + 26))
- y = y + 1
- x = x + 26
- end
- end
- end
- pr.endPage()
- end
- if string.find(message, myName .. " lua") ~= nil then
- eval(string.sub(message, #(myName .. " lua") + 2))
- end
- if string.find(message, myName .. " shoot") ~= nil and string.find(message, myName .. " shoot at") == nil then
- target = string.sub(message, #(myName .. " shoot") + 2)
- shootAt(target, 5)
- end
- if string.find(message, myName .. " shoot at") ~= nil then
- target = textutils.unserialize("{" .. string.sub(message, #(myName .. " shoot at") + 2) .. "}")
- shootAtPos(target, 5)
- end
- if string.find(message, myName .. " zeig inv") ~= nil and string.find(message, myName .. " shoot at") == nil then
- showInventory(string.sub(message, #(myName .. " zeig inv") + 2))
- end
- if string.find(message, myName .. " scan mobs") ~= nil then
- say("Mobs werden gescannt")
- scanAll("mob")
- for i = 1, #entity.mob do
- say(entity.mob[i].name)
- end
- end
- if string.find(message, myName .. " scan spieler") ~= nil or string.find(message, myName .. " scan player") ~= nil then
- say("Spieler werden gescannt")
- scanAll("player")
- for i = 1, #entity.player do
- say(entity.player[i].name)
- end
- end
- if string.find(message, myName .. " suche mobs") ~= nil then
- say(" Mobs werden gesucht")
- scanPos("mob")
- for i = 1, #eName do
- say(eName[i] .. " (" .. ePos[eName[i]].x .. "/" .. ePos[eName[i]].y .. "/" .. ePos[eName[i]].z .. ")")
- end
- end
- if string.find(message, myName .. " suche spieler") ~= nil then
- say(" Spieler werden gesucht")
- scanPos("player")
- for i = 1, #eName do
- say(eName[i] .. " (" .. ePos[eName[i]].x .. "/" .. ePos[eName[i]].y .. "/" .. ePos[eName[i]].z .. ")")
- end
- end
- if string.find(message, myName .. " suche alles") ~= nil then
- say(" Entitys werden gesucht")
- scanPos("all")
- for i = 1, #eName do
- say(eName[i] .. " (" .. ePos[eName[i]].x .. "/" .. ePos[eName[i]].y .. "/" .. ePos[eName[i]].z .. ")")
- end
- end
- if message == myName .. " sag hallo" then
- say("Hallo :D")
- end
- if message == myName .. " du bist fett" then
- say("Ich bin nur stabil gebaut")
- emotion = -40
- loadFace()
- end
- if message == myName .. " du bist toll" then
- say("Ich weiss")
- emotion = 1
- loadFace()
- end
- if message == myName .. " sei traurig" then
- say("Ok")
- emotion = -81
- loadFace()
- end
- if message == myName .. " play music" then
- if drSide ~= nil then
- if disk.hasAudio(drSide) ~= nil then
- disk.playAudio(drSide)
- say("playing: " .. disk.getAudioTitle(drSide))
- end
- end
- end
- if message == myName .. " stop music" then
- if drSide ~= nil then
- disk.stopAudio(drSide)
- end
- end
- if message == myName .. " bau eine armee" then
- if rednetSide ~= nil then
- if dr ~= nil then
- if disk.isPresent(drSide) then
- shell.run("cp turtlearmee disk/startup")
- say(
- myName ..
- " Ich habe dir ein Turtle Programm auf die Floppy gezogen :). Beachte bitte Folgende schritte zum Aufbau der Armee: 1.Wireless Mining Turtle aufstellen 2.Lege Wireless Mining Turtles in den ersten Slot und Fuel in den zweiten 3.Stell ein Diskdrive mit der Floppydisk auf die Turtle und starte die Turtle neu"
- )
- else
- say(myName .. " leg bitte eine Floppydisk in den Diskdrive")
- end
- else
- say(myName .. ": Stell bitte einen Diskdrive mit einer Floppydisk an mich dran :)")
- end
- else
- say(myName .. ": Stell bitte ein Wireless Modem an den Computer")
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement