Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- id=os.getComputerID()
- --Peripheralien
- rednet.open("bottom")
- mon=peripheral.wrap("right")
- if mon==nil then
- mainComputer=os.getComputerID()
- end
- --Funktionen
- 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
- function getOwners()
- areas=getTab("areas")
- end
- function getMainComputer()
- rednet.broadcast("getMainComputer")
- end
- function reserveArea(name,x1,y1,x2,y2)
- area={name=name,pos={x1,y1,x2,y2}}
- rednet.broadcast(area)
- end
- function inArea(x1,y1,x2,y2,x3,y3)
- local inArea=false
- if x1>=x2 and x1<=x3 and y1>=y2 and y1<=y3 then inArea=true end
- return inArea
- end
- function recieve()
- event, arg1, arg2, arg3, arg4, arg5 = os.pullEvent()
- end
- function drawBox(x1,y1,x2,y2,color)
- string=""
- for i2=1,x2-x1 do
- string=string.." "
- end
- for i2=1,y2-y1 do
- mon.setCursorPos(x1,y1+i2-1)
- mon.setBackgroundColor(color)
- mon.write(string)
- end
- end
- function drawMap()
- mon.clear()
- shell.run("monitor right show map")
- for i=1,#areas do
- pos=areas[i].pos
- if areas[i].name=="Leer" then color=colors.red else color=colors.green end
- drawBox(pos[1],pos[2],pos[3],pos[4],color)
- mon.setCursorPos((pos[1]+pos[3])/2-#areas[i].name/2,(pos[2]+pos[4])/2)
- mon.setTextColor(colors.white)
- mon.write(areas[i].name)
- end
- end
- --Dateien
- --if fs.exists("update")==false then
- shell.run("rm update")
- fp=fs.open("update","a")
- fp.writeLine("rednet.broadcast('update')")
- fp.writeLine("shell.run('rm startup')")
- fp.writeLine("shell.run('pastebin get EuqksnZn startup')")
- fp.writeLine("shell.run('rm map')")
- fp.writeLine("shell.run('pastebin get rAV7B2eL map')")
- fp.writeLine("shell.run('startup')")
- fp.close()
- shell.run("rm show")
- fp=fs.open("show","a")
- fp.writeLine("m=peripheral.wrap('right') m.setTextScale(0.5) m.setBackgroundColor(colors.lightGray) m.clear() map=paintutils.loadImage('map')")
- fp.writeLine("paintutils.drawImage(map,1,1)")
- fp.close()
- --end
- --MapComputer
- if fs.exists("areas")==false then
- areas={
- {name="Leer",pos={29,8,50,16}},
- {name="Leer",pos={70,8,85,16}},
- {name="Leer",pos={71,20,84,26}},
- {name="Leer",pos={5,28,16,34}},
- {name="Leer",pos={71,28,84,34}},
- {name="Leer",pos={8,37,19,42}},
- {name="Leer",pos={50,35,63,41}},
- {name="Leer",pos={72,36,85,42}},
- {name="Leer",pos={13,45,24,51}},
- {name="Leer",pos={33,45,44,51}},
- {name="Leer",pos={58,45,69,50}}
- }
- saveTab("areas",areas)
- end
- getOwners()
- drawMap()
- --getMainComputer()
- while true do
- recieve()
- if event=="monitor_touch" then
- xPos=arg2
- yPos=arg3
- for i=1,#areas do
- pos=areas[i].pos
- if inArea(xPos,yPos,pos[1],pos[2],pos[3],pos[4]) then
- if areas[i].name=="Leer" then
- size={mon.getSize()}
- mon.setCursorPos(1,size[2])
- m.setBackgroundColor(colors.lightGray)
- mon.write("[Reservieren][Abbrechen]")
- recieve()
- if event=="monitor_touch" then
- xPos=arg2
- yPos=arg3
- if inArea(xPos,yPos,1,size[2],12,size[2]) then
- mon.setCursorPos(1,size[2])
- mon.write("Bitte Usernamen in den Computer eingeben")
- term.clear()
- term.setCursorPos(1,1)
- print("Bitte Usernamen eingeben")
- userName=io.read()
- areas[i].name=userName
- saveTab("areas",areas)
- drawMap()
- else
- drawMap()
- end
- end
- end
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment