Advertisement
rollton

Считывание сообщений игрока в выделенной комате

Jun 28th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.86 KB | None | 0 0
  1. local command = {
  2.     "на арену",
  3.     "На арену",
  4.     "го пвп",
  5. }
  6.  
  7. local component = require("component")
  8. local event = require("event")
  9. local shell = require("shell")
  10. local fs = require("filesystem")
  11. local serialization = require("serialization")
  12.  
  13. local args = shell.parse(...)
  14.  
  15. if not component.isAvailable("chat_box") then print("Установите обычный chat box") return end
  16. if not component.isAvailable("debug") then print("Установите debug card") return end
  17. if not component.isAvailable("opencb") then print("Установите командный блок") return end
  18.  
  19. local debug = component.debug
  20. local chat = component.chat_box
  21. local com_block = component.opencb.execute
  22.  
  23. function round(hhh)
  24.     local mul = math.pow( 10, roundDig )
  25.     return ( math.floor( ( hhh * mul ) + 0.5 )/mul )
  26. end
  27.  
  28. function scan(nick)
  29.     local s = {debug.getPlayer(nick).getPosition()}
  30.     return {math.ceil(s[1])-1,math.ceil(s[2]),math.ceil(s[3])-1}
  31. end
  32.  
  33. function start()
  34.     local point = {}
  35.     local i = 1
  36.     local ttt = "§3Установка точек§r: "
  37.     chat.setName("§rL§7§o")
  38.  
  39.     io.write("Ваш ник: ")
  40.     you = io.read()
  41.  
  42.     chat.say(ttt .. "*** 1 и 2 - точки комнаты, 3 - точка тп (на pim) ***")
  43.     chat.say(ttt .. "Встав на [1] точку напишите что-нибудь в чат")
  44.     while true do
  45.         local _,_,nick,_ = event.pull("chat_message")
  46.         if you == nick then
  47.             point[i] = scan(you)
  48.             i = i + 1
  49.             if i == 4 then break end
  50.             chat.say(ttt .. "Встав на ["..i.."] точку напишите что-нибудь в чат")
  51.         end
  52.     end
  53.     local file=io.open("/home/point.cfg","w")
  54.         file:write(serialization.serialize(point))
  55.     file:close()
  56.     chat.say(ttt .. "Установка закончена")
  57. end
  58.  
  59. if args[1] == "new" then
  60.     start()
  61. end
  62. if not fs.exists("/home/point.cfg") then
  63.     start()
  64. end
  65. local file = io.open("/home/point.cfg", "r")
  66. point = serialization.unserialize(file:read())
  67. file:close()
  68.  
  69. print("Для изменения точек, запустите программу иначе -> [назв. программы] new")
  70. print("*** Программа запущена ***")
  71.  
  72. while true do
  73.     local _,_,nick,mes = event.pull("chat_message")
  74.     for _,com in pairs(command) do
  75.         if mes == com then
  76.             local xyz = scan(nick)
  77.             local flag
  78.             for i = 1,3 do
  79.                 if point[1][i] > point[2][i] then
  80.                     point[1][i],point[2][i] = point[2][i],point[1][i]
  81.                 end
  82.                 if (xyz[i] >= point[1][i]) and (xyz[i] <= point[2][i]) then
  83.                 else
  84.                     flag = true
  85.                     break
  86.                 end
  87.             end
  88.             -- Этот раздел можно дополнять, например обнулять режим бога, отчищать инвентарь и т.д.
  89.             if not flag then
  90.                 com_block("tppos "..nick.." "..point[3][1].." "..point[3][2].." "..point[3][3])
  91.             end
  92.         end
  93.     end
  94. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement