Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Пример: https://yadi.sk/i/ukH4XC4n3KXuLc
- local component = require("component")
- local event = require("event")
- local shell = require("shell")
- local fs = require("filesystem")
- local serialization = require("serialization")
- local args = shell.parse(...)
- if not component.isAvailable("chat_box") then print("Установите chat box") return end
- if not component.isAvailable("debug") then print("Установите debug card") return end
- local debug = component.debug
- local chat = component.chat_box
- function invers(a,b,g)
- if g == a then return b else return a end
- end
- function scan()
- local s = {debug.getPlayer(you).getPosition()}
- return {math.ceil(s[1])-1,math.ceil(s[2]),math.ceil(s[3])-1}
- end
- function pidoroff()
- for a,b in pairs(pidori) do
- local sas = {debug.getPlayer(b).setPosition(point[3][1],point[3][2],point[3][3])}
- if sas[2] ~= "player is offline" then
- pidori[a] = nil
- end
- end
- end
- local com = {"p1","p2","r1","r2"}
- function start()
- local point = {}
- local i = 1
- local ttt = "§3Установка точек§r: "
- chat.setName("§rL§7§o")
- io.write("Ваш ник: ")
- you = io.read()
- chat.say(ttt .. "1 и 2 - точки тп на арену, 3 - точка тп победителя в лобби ***")
- chat.say(ttt .. "Встав на [1] точку напишите что-нибудь в чат")
- while true do
- local _,_,nick,_ = event.pull("chat_message")
- if you == nick then
- point[i] = scan()
- i = i + 1
- if i == 4 then break end
- chat.say(ttt .. "Встав на ["..i.."] точку напишите что-нибудь в чат")
- end
- end
- local file=io.open("/home/point.cfg","w")
- file:write(serialization.serialize(point))
- file:close()
- chat.say(ttt .. "Установка закончена")
- end
- if args[1] == "new" then
- start()
- end
- if not fs.exists("/home/point.cfg") then
- start()
- end
- local file = io.open("/home/point.cfg", "r")
- point = serialization.unserialize(file:read())
- file:close()
- print("Для изменения точек, запустите программу иначе -> [назв. программы] new")
- print("*** Программа запущена ***")
- pidori = {}
- while true do
- local inc = 1
- local name = {}
- local health = {}
- local flag
- for add, _ in component.list("pim") do
- name[inc] = component.proxy(add).getInventoryName()
- if name[inc] == "pim" then
- flag = true
- break
- end
- inc = 2
- end
- if not flag then
- io.write("Сражение: "..name[1].." и "..name[2].." --- ")
- for i = 1, 2 do
- debug.getPlayer(name[i]).setPosition(point[i][1],point[i][2],point[i][3])
- end
- while true do
- pidoroff()
- local fl
- for i = 1, 2 do
- health[i] = debug.getPlayer(name[i]).getHealth()
- end
- if (health[1] == 0) and (health[2] == 0) then print("Ничья") break end
- for i = 1, 2 do
- if health[i] == 0 then
- local win = name[invers(1,2,i)]
- local xxx
- print("Победа: "..win)
- local f = event.timer(60,
- function()
- local n = {debug.getPlayer(win).setPosition(point[3][1],point[3][2],point[3][3])}
- if n[2] == "player is offline" then
- pidori[#pidori+1] = win
- end
- xxx = true
- end
- )
- repeat
- pidoroff()
- if xxx then break end
- local _,_,nick,mes = event.pull("chat_message")
- until (nick == win) and (mes == "exit")
- if not xxx then debug.getPlayer(win).setPosition(point[3][1],point[3][2],point[3][3]) end
- event.cancel(f)
- fl = true
- break
- end
- end
- if fl then break end
- os.sleep(1)
- end
- end
- os.sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement