Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local fs = require("filesystem")
- local shell = require("shell")
- local term = require("term")
- local serialization = require("serialization")
- if not component.isAvailable("openperipheral_sensor") then print("Установите сенсор (через адаптер)") return end
- if not component.isAvailable("os_entdetector") then print("Установите entity detector") return end
- local sensor = component.openperipheral_sensor
- local function xyz(g)
- local x,y = term.getCursor()
- term.setCursor(otstup,y-2)
- otstup = otstup + #tostring(g) + 1
- term.write(g)
- term.setCursor(x,y)
- end
- local function clear(g)
- local x,y = term.getCursor()
- for i = 0, g do
- term.setCursor(x,y-i)
- term.clearLine()
- end
- end
- local function read(g,t)
- while true do
- local x,y = term.getCursor()
- term.write(g)
- local a = tonumber(term.read())
- if a ~= nil then
- clear(t)
- return a
- end
- clear(2)
- print("*** Повторите попытку ***")
- end
- end
- local args = shell.parse(...)
- if args[1] == nil then
- print([[
- --- Программа для записи/обнаружения предметов с uuid и их записи/сравнения с базой данных ---
- Доступные команды:
- [программа] new [Ваш ник] - добавить новоый предмет из вашего инвентаря в базу данных
- [программа] del - удалить предмета из базы данных
- [программа] point - изменить точку проверки ключей (дверь)
- [программа] run - запуск программы]])
- return
- end
- if args[1] == "new" then
- if not fs.exists("/home/bditem") then
- fs.makeDirectory("/home/bditem")
- end
- if args[2] == nil then print(" После 'new' Вы забыли ввести Ваш ник, повторите попытку.") return end
- local players = sensor.getPlayers()
- local flag = true
- for _,v in pairs(players) do
- if v.name == args[2] then
- flag = false
- end
- end
- if flag then print(" Игрок не найден") return end
- local buf = {}
- local name = {}
- local size = 0
- for i = 1, 36 do
- local inv = sensor.getPlayerByName(args[2]).all().player.inventory[i]
- if inv ~= nil then
- inv = inv.all()
- if inv.nbt_hash ~= nil then
- size = size + 1
- buf[size] = inv.nbt_hash
- name[size] = inv.display_name
- print(size..") "..name[size])
- end
- end
- end
- if size == 0 then
- print(" Предметы, имеющие uuid, в вашем инвентаре не найдено, повторите попытку.")
- return
- end
- print("-==========================-")
- local item = {["addname"] = args[2]}
- local file
- while true do
- print(" Выберите номер предмета:")
- t = read(">> ",2)
- if t>=1 and t<=size then
- file = "/home/bditem/"..name[t]
- if fs.exists(file) then
- print(" Данный предмет уже записан, хотите удалить? [Y/N]")
- term.write(">> ")
- local st = io.read()
- clear(2)
- if (st == "y") or (st == "Y") then
- fs.remove(file)
- end
- else
- break
- end
- end
- end
- clear(size+1)
- item["uuid"] = buf[t]
- otstup = 13
- print("Координаты:")
- print(" Введите:")
- item["x"] = read("X >> ",1)
- xyz(item["x"])
- item["y"] = read("Y >> ",1)
- xyz(item["y"])
- item["z"] = read("Z >> ",1)
- xyz(item["z"])
- clear(1)
- file=io.open(file,"w")
- file:write(serialization.serialize(item))
- file:close()
- print("*** Предмет успешно занесен в базу данных ***")
- return
- end
- if args[1] == "del" then
- local inc = 0
- local name = {}
- for file in fs.list("/home/bditem") do
- inc = inc + 1
- print(inc..") "..file)
- name[inc] = file
- end
- if inc == 0 then print(" Предметов не найдено.") return end
- print(" Выберите номер предмета:")
- fs.remove("/home/bditem/"..name[read(">> ",2)])
- clear(inc)
- print("*** Предмет успешно удален ***")
- end
- if args[1] == "point" then
- local item = {}
- otstup = 13
- print("Координаты:")
- print(" Введите:")
- item["x"] = read("X >> ",1)
- xyz(item["x"])
- item["y"] = read("Y >> ",1)
- xyz(item["y"])
- item["z"] = read("Z >> ",1)
- xyz(item["z"])
- clear(1)
- local file = io.open("point.txt", "w")
- file:write(serialization.serialize(item))
- file:close()
- print("*** Точка проверки ключей обновлена ***")
- end
- if args[1] == "run" then
- if not fs.exists("/home/point.txt") then print(" Точка еще не создана, воспользуйтесь gg piont для ее создания") return end
- local file = io.open("point.txt", "r")
- local point = serialization.unserialize(file:read())
- file:close()
- while true do
- os.sleep(1)
- local scan = component.os_entdetector.scanPlayers(16)
- for _,k in pairs(scan) do
- local flag = true
- for n,_ in pairs(point) do
- if not (math.floor(k[n]) == point[n]) then
- flag = false
- break
- end
- end
- if flag then
- local ff = {}
- local inc = 0
- for file in fs.list("/home/bditem") do
- inc = inc + 1
- local file = io.open("/home/bditem/"..file, "r")
- ff[inc] = serialization.unserialize(file:read())
- file:close()
- end
- if inc == 0 then print(" Файлы не найдены") return end
- for i = 1, 36 do
- local inv = sensor.getPlayerByName(k.name).all().player.inventory[i]
- if inv ~= nil then
- inv = inv.all()
- if inv.nbt_hash ~= nil then
- for _,v in pairs(ff) do
- if v.uuid == inv.nbt_hash then
- if component.isAvailable("opencb") then
- component.opencb.execute("tppos "..k.name.." "..v.x.." "..v.y.." "..v.z)
- else
- if component.isAvailable("debug") then
- component.debug.getPlayer(k.name).setPosition(v.x,v.y,v.z)
- else
- print("Отсутствует дебаг карта или командный блок")
- return
- end
- end
- os.sleep(1)
- break
- end
- end
- end
- end
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement