kovakovi2000

CC: P++ CubeDefender

Apr 3rd, 2020
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. os.loadAPI("ldb")
  2. sensor = peripheral.wrap("top")
  3. chat = peripheral.wrap("bottom")
  4. speaker = peripheral.wrap("left")
  5. ant = peripheral.wrap("back")
  6. tmr = peripheral.wrap("right")
  7.  
  8. gd = 200
  9. me = "kovakovi2000"
  10. prefix = "[CUBE] "
  11.  
  12. players = sensor.getNearbyPlayers(gd)
  13. w_near = {}
  14. w_close = {}
  15. w_inside = {}
  16.  
  17. helmet = ant.getPlayers()
  18. con = false
  19. xme = 0
  20. for i = 1, table.getn(helmet) do
  21. if helmet[i] == me then
  22. xme = i
  23. con = true
  24. end
  25. end
  26. function dtf(str)
  27. return string.format("%.2d",str)
  28. end
  29. function formatTime(v_time)
  30. return v_time.year .. "." ..
  31. dtf(v_time.month) .. "." ..
  32. dtf(v_time.day) .. " " ..
  33. dtf(v_time.hour) .. ":" ..
  34. dtf(v_time.minute) .. ":" ..
  35. dtf(v_time.second)
  36. end
  37.  
  38. if con then
  39. ame = ant.getHUD(helmet[xme])
  40. white = ame.getColorFromRGB(255,255,255,255)
  41. red = ame.getColorFromRGB(255,0,0,255)
  42. yellow = ame.getColorFromRGB(255,255,0,255)
  43. green = ame.getColorFromRGB(0,255,0,255)
  44.  
  45. function dws(str,ly,color)
  46. ame.drawString(str,100,ly,color)
  47. end
  48.  
  49. function createHUD()
  50. ame.drawString(prefix,100,12,white)
  51. ame.drawHorizontalLine(100,24,200,white)
  52. end
  53.  
  54. if ldb.is("washere") == true then
  55. ldb.del("washere")
  56. ame.clear()
  57. ame.drawString(prefix,300,12,red)
  58. ame.drawHorizontalLine(300,24,400,red)
  59. local y = 26
  60. ls = ldb.list()
  61. for i = 1, table.getn(ls) do
  62. if string.find(ls[i], "was_") ~= nil then
  63. tmp = ldb.get(ls[i])
  64. ame.drawString(tmp.l_player .. " " .. tmp.l_sdis .. " " .. formatTime(tmp.l_tmr),300,y,red)
  65. y = y + 12
  66. ldb.del(ls[i])
  67. end
  68. end
  69. ame.sync()
  70. sleep(120)
  71. end
  72. ame.clear()
  73. createHUD()
  74. ame.sync()
  75.  
  76. local y = 0
  77. local tm = 0
  78. while true do
  79. createHUD()
  80. ame.sync()
  81. sleep(0.1)
  82. y = 26
  83. tm = tm + 1
  84. players = sensor.getNearbyPlayers(gd)
  85. me_online = false
  86. for i = 1, table.getn(players) do
  87. if players[i].player ~= me then
  88. local dis = players[i].distance
  89. local sdis = string.format("%2.2f",dis)
  90. if dis < 10.0 then
  91. dws(players[i].player .. " " .. sdis, y, red)
  92. y = y + 12
  93. if(tm > 20) then
  94. chat.tell(players[i].player , prefix .. "YOU HAVE NO PERMISSON TO BE HERE, MY MASTER WILL KNOW IT!")
  95. speaker.speak("YOU HAVE NO PERMISSON TO BE HERE, MY MASTER WILL KNOW IT!", 10)
  96. tm = 0
  97. end
  98. elseif 10.0 < dis and dis < 20.0 then
  99. dws(players[i].player .. " " .. sdis, y, yellow)
  100. y = y + 12
  101. elseif 20.0 < dis and dis < 30.0 then
  102. dws(players[i].player .. " " .. sdis, y, green)
  103. y = y + 12
  104. elseif 30.0 < dis then
  105. dws(players[i].player .. " " .. sdis, y, white)
  106. y = y +12
  107. end
  108. else
  109. me_online = true
  110. end
  111. end
  112.  
  113. if me_online ~= true then
  114. os.reboot()
  115. end
  116. end
  117. else
  118. while true do
  119. sleep(0.1)
  120. players = sensor.getNearbyPlayers(gd)
  121. for i = 1, table.getn(players) do
  122. local dis = players[i].distance
  123. local sdis = string.format("%2.2f",dis)
  124. if dis < 10.0 then
  125. ldb.set("washere", 1)
  126. ldb.set("was_" .. tmr.getTime(), {l_player = players[i].player, l_sdis = sdis, l_tmr = tmr.getDate()})
  127. chat.tell(players[i].player , prefix .. "YOU HAVE NO PERMISSON TO BE HERE, MY MASTER WILL KNOW IT!")
  128. speaker.speak("YOU HAVE NO PERMISSON TO BE HERE, MY MASTER WILL KNOW IT!", 10)
  129. sleep(2)
  130. end
  131.  
  132. if(players[i].player == me) then
  133. os.reboot()
  134. end
  135. end
  136. end
  137. end
Add Comment
Please, Sign In to add comment