Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require('component')
- local event = require('event')
- local chat = component['chat_box']
- local redstone = component['redstone']
- local sensor = component['openperipheral_sensor']
- local players_old, exit_gate = 0, true
- chat.setName("§bОбменник§7§o")
- chat.setDistance(10)
- local cords = {
- pos_1 = {
- x = -1,
- y = 3,
- z = -6
- },
- pos_2 = {
- x = 5,
- y = 6,
- z = 2
- },
- exit = {
- x = 2,
- y = 3,
- z = -6
- }
- }
- local function get_players_string(player_list)
- local players_string = ''
- for i in pairs(player_list) do
- if i == 1 then
- players_string = player_list[i]
- else
- players_string = players_string .. ', ' .. player_list[i]
- end
- end
- return players_string
- end
- local function int_cords(cords)
- return {
- x = math.floor(cords['x']),
- y = math.floor(cords['y']),
- z = math.floor(cords['z'])
- }
- end
- local function get_players(exit)
- local players, players_in = sensor.getPlayers(), {}
- for player in pairs(players) do
- local act, coords = pcall(function() return int_cords(sensor.getPlayerByName(players[player]['name']).basic()['position']) end)
- if act then
- if (cords['pos_1']['x'] <= coords['x'] and coords['x'] <= cords['pos_2']['x'] and
- cords['pos_1']['y'] <= coords['y'] and coords['y'] <= cords['pos_2']['y'] and
- cords['pos_1']['z'] <= coords['z'] and coords['z'] <= cords['pos_2']['z']) then
- if exit and not (coords['x']==cords['exit']['x'] and coords['y']==cords['exit']['y'] and coords['z']==cords['exit']['z']) then
- table.insert(players_in, players[player]['name'])
- elseif not exit then
- table.insert(players_in, players[player]['name'])
- end
- end
- end
- end
- return players_in
- end
- while true do
- local trade_players = get_players(exit_gate)
- if #trade_players > 1 and players_old ~= #trade_players then
- active_button, exit_gate = true, false
- chat.say('§4В кабинке несколько игроков, обменник заблокирован: §d[§b' .. get_players_string(trade_players) .. '§d]')
- redstone.setOutput(4, 0)
- elseif #trade_players == 1 then redstone.setOutput(4, 1)
- elseif #trade_players == 0 then redstone.setOutput(4, 0) end
- if players_old > 1 and #trade_players <= 1 then
- active_button, exit_gate = false, true
- chat.say('§2Обменник разблокирован')
- end
- players_old = #trade_players
- os.sleep(0)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement