ecco7777

market info plane

Aug 23rd, 2017
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.22 KB | None | 0 0
  1. id=os.getComputerID()
  2. --Peripheralien
  3. rednet.open("bottom")
  4. mon=peripheral.wrap("right")
  5. if mon==nil then
  6. mainComputer=os.getComputerID()
  7. end
  8.  
  9. --Funktionen
  10. function saveTab(file,tab)
  11. fp=fs.open(file,"w")
  12. fp.write(textutils.serialize(tab))
  13. fp.close()
  14. end
  15.  
  16. function getTab(file)
  17. fp=fs.open(file,"r")
  18. return textutils.unserialize(fp.readAll())
  19. end
  20.  
  21. function getOwners()
  22. areas=getTab("areas")
  23. end
  24.  
  25. function getMainComputer()
  26. rednet.broadcast("getMainComputer")
  27. end
  28.  
  29. function reserveArea(name,x1,y1,x2,y2)
  30. area={name=name,pos={x1,y1,x2,y2}}
  31. rednet.broadcast(area)
  32. end
  33.  
  34. function inArea(x1,y1,x2,y2,x3,y3)
  35. local inArea=false
  36. if x1>=x2 and x1<=x3 and y1>=y2 and y1<=y3 then inArea=true end
  37. return inArea
  38. end
  39.  
  40. function recieve()
  41. event, arg1, arg2, arg3, arg4, arg5 = os.pullEvent()
  42. end
  43.  
  44. function drawBox(x1,y1,x2,y2,color)
  45. string=""
  46. for i2=1,x2-x1 do
  47. string=string.." "
  48. end
  49. for i2=1,y2-y1 do
  50. mon.setCursorPos(x1,y1+i2-1)
  51. mon.setBackgroundColor(color)
  52. mon.write(string)
  53. end
  54. end
  55.  
  56. function drawMap()
  57. mon.clear()
  58. shell.run("monitor right show map")
  59. for i=1,#areas do
  60. pos=areas[i].pos
  61. if areas[i].name=="Leer" then color=colors.red else color=colors.green end
  62. drawBox(pos[1],pos[2],pos[3],pos[4],color)
  63. mon.setCursorPos((pos[1]+pos[3])/2-#areas[i].name/2,(pos[2]+pos[4])/2)
  64. mon.setTextColor(colors.white)
  65. mon.write(areas[i].name)
  66. end
  67. end
  68.  
  69. --Dateien
  70. --if fs.exists("update")==false then
  71. shell.run("rm update")
  72. fp=fs.open("update","a")
  73. fp.writeLine("rednet.broadcast('update')")
  74. fp.writeLine("shell.run('rm startup')")
  75. fp.writeLine("shell.run('pastebin get EuqksnZn startup')")
  76. fp.writeLine("shell.run('rm map')")
  77. fp.writeLine("shell.run('pastebin get rAV7B2eL map')")
  78. fp.writeLine("shell.run('startup')")
  79. fp.close()
  80. shell.run("rm show")
  81. fp=fs.open("show","a")
  82. fp.writeLine("m=peripheral.wrap('right') m.setTextScale(0.5) m.setBackgroundColor(colors.lightGray) m.clear() map=paintutils.loadImage('map')")
  83. fp.writeLine("paintutils.drawImage(map,1,1)")
  84. fp.close()
  85. --end
  86.  
  87.  
  88.  
  89. --MapComputer
  90.  
  91. if fs.exists("areas")==false then
  92. areas={
  93. {name="Leer",pos={29,8,50,16}},
  94. {name="Leer",pos={70,8,85,16}},
  95. {name="Leer",pos={71,20,84,26}},
  96. {name="Leer",pos={5,28,16,34}},
  97. {name="Leer",pos={71,28,84,34}},
  98. {name="Leer",pos={8,37,19,42}},
  99. {name="Leer",pos={50,35,63,41}},
  100. {name="Leer",pos={72,36,85,42}},
  101. {name="Leer",pos={13,45,24,51}},
  102. {name="Leer",pos={33,45,44,51}},
  103. {name="Leer",pos={58,45,69,50}}
  104. }
  105. saveTab("areas",areas)
  106. end
  107. getOwners()
  108. drawMap()
  109. --getMainComputer()
  110. while true do
  111. recieve()
  112.  
  113. if event=="monitor_touch" then
  114. xPos=arg2
  115. yPos=arg3
  116.  
  117. for i=1,#areas do
  118. pos=areas[i].pos
  119. if inArea(xPos,yPos,pos[1],pos[2],pos[3],pos[4]) then
  120.  
  121.  
  122. if areas[i].name=="Leer" then
  123. size={mon.getSize()}
  124. mon.setCursorPos(1,size[2])
  125. m.setBackgroundColor(colors.lightGray)
  126. mon.write("[Reservieren][Abbrechen]")
  127. recieve()
  128. if event=="monitor_touch" then
  129. xPos=arg2
  130. yPos=arg3
  131. if inArea(xPos,yPos,1,size[2],12,size[2]) then
  132. mon.setCursorPos(1,size[2])
  133. mon.write("Bitte Usernamen in den Computer eingeben")
  134. term.clear()
  135. term.setCursorPos(1,1)
  136. print("Bitte Usernamen eingeben")
  137. userName=io.read()
  138. areas[i].name=userName
  139. saveTab("areas",areas)
  140. drawMap()
  141. else
  142. drawMap()
  143. end
  144.  
  145. end
  146.  
  147. end
  148.  
  149. end
  150. end
  151.  
  152. end
  153.  
  154. end
Add Comment
Please, Sign In to add comment