Advertisement
chuzAUzername

SomeShit

Feb 21st, 2022 (edited)
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.38 KB | None | 0 0
  1. local component = require('component')
  2. local event = require('event')
  3. local chat = component['chat_box']
  4. local redstone = component['redstone']
  5. local sensor = component['openperipheral_sensor']
  6. local players_old, exit_gate = 0, true
  7. chat.setName("§bОбменник§7§o")
  8. chat.setDistance(10)
  9. local cords = {
  10.     pos_1 = {
  11.         x = -1,
  12.         y = 3,
  13.         z = -6
  14.     },
  15.     pos_2 = {
  16.         x = 5,
  17.         y = 6,
  18.         z = 2
  19.     },
  20.     exit = {
  21.         x = 2,
  22.         y = 3,
  23.         z = -6
  24.     }
  25. }
  26.  
  27.  
  28. local function get_players_string(player_list)
  29.     local players_string = ''
  30.     for i in pairs(player_list) do
  31.         if i == 1 then
  32.             players_string = player_list[i]
  33.         else
  34.             players_string = players_string .. ', ' .. player_list[i]
  35.         end
  36.     end
  37.     return players_string
  38. end
  39.  
  40.  
  41. local function int_cords(cords)
  42.     return {
  43.         x = math.floor(cords['x']),
  44.         y = math.floor(cords['y']),
  45.         z = math.floor(cords['z'])
  46.     }
  47. end
  48.  
  49.  
  50. local function get_players(exit)
  51.     local players, players_in = sensor.getPlayers(), {}
  52.     for player in pairs(players) do
  53.         local act, coords = pcall(function() return int_cords(sensor.getPlayerByName(players[player]['name']).basic()['position']) end)
  54.         if act then
  55.             if (cords['pos_1']['x'] <= coords['x'] and coords['x'] <= cords['pos_2']['x'] and
  56.                 cords['pos_1']['y'] <= coords['y'] and coords['y'] <= cords['pos_2']['y'] and
  57.                 cords['pos_1']['z'] <= coords['z'] and coords['z'] <= cords['pos_2']['z']) then
  58.                 if exit and not (coords['x']==cords['exit']['x'] and coords['y']==cords['exit']['y'] and coords['z']==cords['exit']['z']) then
  59.                     table.insert(players_in, players[player]['name'])
  60.                 elseif not exit then
  61.                     table.insert(players_in, players[player]['name'])
  62.                 end
  63.             end
  64.         end
  65.     end
  66.     return players_in
  67. end
  68.  
  69.  
  70. while true do
  71.     local trade_players = get_players(exit_gate)
  72.     if #trade_players > 1 and players_old ~= #trade_players then
  73.         active_button, exit_gate = true, false
  74.         chat.say('§4В кабинке несколько игроков, обменник заблокирован: §d[§b' .. get_players_string(trade_players) .. '§d]')
  75.         redstone.setOutput(4, 0)
  76.     elseif #trade_players == 1 then redstone.setOutput(4, 1)
  77.     elseif #trade_players == 0 then redstone.setOutput(4, 0) end
  78.     if players_old > 1 and #trade_players <= 1 then
  79.         active_button, exit_gate = false, true
  80.         chat.say('§2Обменник разблокирован')
  81.     end
  82.     players_old = #trade_players
  83.     os.sleep(0)
  84. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement