Nike622000

Testversuch

Jun 12th, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.49 KB | None | 0 0
  1. os.loadAPI("ocs/apis/sensor")
  2. local PCol      = colors.lightGray
  3. local SCol      = colors.black
  4. local DCol      = colors.gray
  5. local senSide   = "top"
  6. local monSide   = "front"
  7. local filename  = "databank"
  8. local delaytime = 5
  9. local MaxRadius = 28
  10. local maxPlayer = 5
  11.  
  12. local PosX      = 2284
  13. local PosY      =   68
  14. local PosZ      = -767
  15.  
  16. local z = 7
  17. local C = 0
  18.  
  19. local Button = {}
  20. Button[1] = {81,37,95,42,"Change Color",colors.cyan,false}
  21. Button[2] = {81,44,95,49,"Reset List"  ,colors.red ,false}
  22.  
  23. mon = peripheral.wrap(monSide)
  24. sen = sensor.wrap(senSide)
  25. mon.setTextScale(.5)
  26. xMax,yMax = mon.getSize()
  27.  
  28. function ocFile()
  29.   if fs.exists(filename) then
  30.     data = fs.open(filename,"a")
  31.     --Open File
  32.   else
  33.     data = fs.open(filename,"w")
  34.     --Create new File
  35.   end
  36. end
  37.  
  38. function JoJa(xP,yP)
  39.   mon.setCursorPos(xP,yP)
  40.   mon.setBackgroundColor(colors.gray)
  41.   mon.setTextColor(colors.cyan)
  42.   mon.write("Jo")
  43.   mon.setTextColor(colors.orange)
  44.   mon.write("Ja ")  
  45.   mon.setTextColor(colors.lightGray)
  46.   mon.write("Productions")
  47. end
  48.  
  49. function Background(col)
  50.   mon.setBackgroundColor(col)
  51.   for yPos = 1,yMax do
  52.     for xPos = 1,xMax do
  53.       mon.setCursorPos(xPos,yPos)
  54.       mon.write(" ")
  55.     end
  56.   end
  57. end
  58.  
  59. function Square(xP1,yP1,xP2,yP2,col)
  60.   mon.setBackgroundColor(col)
  61.   for yPos = yP1,yP2 do
  62.     for xPos = xP1,xP2 do
  63.       mon.setCursorPos(xPos,yPos)
  64.       mon.write(" ")
  65.     end
  66.   end
  67. end
  68.  
  69. function printButton()
  70.   for i = 1,#Button do
  71.     Square(Button[i][1],Button[i][2],Button[i][3],Button[i][4],Button[i][6])
  72.     mon.setCursorPos((Button[i][1]+Button[i][3])/2-#Button[i][5]/2,(Button[i][2]+Button[i][4])/2)
  73.     mon.write(Button[i][5])
  74.   end  
  75. end
  76.  
  77. function checkButton(xP,yP)
  78.   for i = 1,#Button do
  79.     if xP >= Button[i][1] and xP <= Button[i][3] and
  80.        yP >= Button[i][2] and yP <= Button[i][4] then
  81.        Button[i][7] = true
  82.     end
  83.   end    
  84. end
  85.  
  86.  
  87. function graph(Wert1,Wert2,xPos,yPos,xMax,col1,col2)
  88.   mon.setBackgroundColor(colors.lightGray)
  89.   for xP = xPos,xMax do
  90.     mon.setCursorPos(xP,yPos)
  91.     mon.write(" ")
  92.   end
  93.   i = Wert1/Wert2
  94.   s = xMax-xPos
  95.   mon.setBackgroundColor(colors.cyan)
  96.   for xP = xPos,xPos+math.floor(s*i) do
  97.     mon.setCursorPos(xP,yPos)
  98.     mon.write(" ")
  99.   end
  100. end
  101.  
  102. while true do
  103.   Background(PCol)
  104.   JoJa(xMax/2-7,1)
  105.   Square(2,3,xMax-1,yMax-1,DCol)
  106.   Square(3,4,xMax-2,yMax-2,SCol)
  107.   mon.setCursorPos(4,5)
  108.   mon.setTextColor(colors.white)
  109.   mon.write("Spieler in Reichweite:")
  110.   printButton()
  111.   mon.setBackgroundColor(SCol)
  112.   Pos = 0
  113.   ziele = sen.getTargets()
  114.   for k,v in pairs(ziele) do
  115.     if v.Name == "Player" then
  116.       if Pos <= z*maxPlayer-1  then
  117.         mon.setCursorPos(4,7+Pos)
  118.         mon.write("Name: "..k)
  119.         mon.setCursorPos(5,8+Pos)
  120.         mon.write("X: "..PosX + v.Position.X)
  121.         mon.setCursorPos(5,9+Pos)
  122.         mon.write("Y: "..PosY + v.Position.Y)
  123.         mon.setCursorPos(5,10+Pos)
  124.         mon.write("Z: "..PosZ + v.Position.Z)
  125.         mon.setCursorPos(5,11+Pos)
  126.         Entfernung = math.sqrt(v.Position.X^2+v.Position.Y^2+v.Position.Z^2)
  127.         mon.write("Entfernung: "..Entfernung)
  128.         graph(Entfernung,MaxRadius,5,12+Pos,15)
  129.         mon.setBackgroundColor(SCol)
  130.       end
  131.       Pos = Pos+z
  132.     end
  133.   end
  134.   --sleep(delaytime)
  135.   event,_,xP,yP = os.pullEvent("monitor_touch")
  136.   checkButton(xP,yP)
  137.   if Button[1][7] then
  138.     C = C+1
  139.     if C > 15 then
  140.       C = 0
  141.     end
  142.     PCol = 2^C  
  143.     Button[1][7] = false
  144.   end
  145. end
Advertisement
Add Comment
Please, Sign In to add comment