Advertisement
rollton

Пвп 1 на 1, пример использования по ссылке в 1 строчке кода

Jun 27th, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.63 KB | None | 0 0
  1. -- Пример: https://yadi.sk/i/ukH4XC4n3KXuLc
  2.  
  3. local component = require("component")
  4. local event = require("event")
  5. local shell = require("shell")
  6. local fs = require("filesystem")
  7. local serialization = require("serialization")
  8.  
  9. local args = shell.parse(...)
  10.  
  11. if not component.isAvailable("chat_box") then print("Установите chat box") return end
  12. if not component.isAvailable("debug") then print("Установите debug card") return end
  13.  
  14. local debug = component.debug
  15. local chat = component.chat_box
  16.  
  17. function invers(a,b,g)
  18.     if g == a then return b else return a end
  19. end
  20.  
  21. function scan()
  22.     local s = {debug.getPlayer(you).getPosition()}
  23.     return {math.ceil(s[1])-1,math.ceil(s[2]),math.ceil(s[3])-1}
  24. end
  25.  
  26. function pidoroff()
  27.     for a,b in pairs(pidori) do
  28.         local sas = {debug.getPlayer(b).setPosition(point[3][1],point[3][2],point[3][3])}
  29.         if sas[2] ~= "player is offline" then
  30.             pidori[a] = nil
  31.         end
  32.     end
  33. end
  34.  
  35. local com = {"p1","p2","r1","r2"}
  36.  
  37. function start()
  38.     local point = {}
  39.     local i = 1
  40.     local ttt = "§3Установка точек§r: "
  41.     chat.setName("§rL§7§o")
  42.  
  43.     io.write("Ваш ник: ")
  44.     you = io.read()
  45.  
  46.     chat.say(ttt .. "1 и 2 - точки тп на арену, 3 - точка тп победителя в лобби ***")
  47.     chat.say(ttt .. "Встав на [1] точку напишите что-нибудь в чат")
  48.     while true do
  49.         local _,_,nick,_ = event.pull("chat_message")
  50.         if you == nick then
  51.             point[i] = scan()
  52.             i = i + 1
  53.             if i == 4 then break end
  54.             chat.say(ttt .. "Встав на ["..i.."] точку напишите что-нибудь в чат")
  55.         end
  56.     end
  57.     local file=io.open("/home/point.cfg","w")
  58.         file:write(serialization.serialize(point))
  59.     file:close()
  60.     chat.say(ttt .. "Установка закончена")
  61. end
  62. if args[1] == "new" then
  63.     start()
  64. end
  65. if not fs.exists("/home/point.cfg") then
  66.     start()
  67. end
  68. local file = io.open("/home/point.cfg", "r")
  69. point = serialization.unserialize(file:read())
  70. file:close()
  71.  
  72. print("Для изменения точек, запустите программу иначе -> [назв. программы] new")
  73. print("*** Программа запущена ***")
  74.  
  75. pidori = {}
  76.  
  77. while true do
  78.     local inc = 1
  79.     local name = {}
  80.     local health = {}
  81.     local flag
  82.     for add, _ in component.list("pim") do
  83.         name[inc] = component.proxy(add).getInventoryName()
  84.         if name[inc] == "pim" then
  85.             flag = true
  86.             break
  87.         end
  88.         inc = 2
  89.     end
  90.     if not flag then
  91.         io.write("Сражение: "..name[1].." и "..name[2].." --- ")
  92.         for i = 1, 2 do
  93.             debug.getPlayer(name[i]).setPosition(point[i][1],point[i][2],point[i][3])
  94.         end
  95.         while true do
  96.             pidoroff()
  97.             local fl
  98.             for i = 1, 2 do
  99.                 health[i] = debug.getPlayer(name[i]).getHealth()
  100.             end
  101.             if (health[1] == 0) and (health[2] == 0) then print("Ничья") break end
  102.             for i = 1, 2 do
  103.                 if health[i] == 0 then
  104.                     local win = name[invers(1,2,i)]
  105.                     local xxx
  106.                     print("Победа: "..win)
  107.                     local f = event.timer(60,
  108.                         function()
  109.                             local n = {debug.getPlayer(win).setPosition(point[3][1],point[3][2],point[3][3])}
  110.                             if n[2] == "player is offline" then
  111.                                 pidori[#pidori+1] = win
  112.                             end
  113.                             xxx = true
  114.                         end
  115.                     )
  116.                     repeat
  117.                         pidoroff()
  118.                         if xxx then break end
  119.                         local _,_,nick,mes = event.pull("chat_message")
  120.                     until (nick == win) and (mes == "exit")
  121.                     if not xxx then debug.getPlayer(win).setPosition(point[3][1],point[3][2],point[3][3]) end
  122.                     event.cancel(f)
  123.                     fl = true
  124.                     break
  125.                 end
  126.             end
  127.             if fl then break end
  128.             os.sleep(1)
  129.         end
  130.     end
  131.     os.sleep(1)
  132. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement