Advertisement
serafim7

турель [OpenComputers]

Jul 26th, 2016
513
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.10 KB | None | 0 0
  1. --http://computercraft.ru/topic/1429-okhrannaia-sistema-turelei-opensecurity/
  2.  
  3. local function func()
  4.     local com                   = require("component")
  5.     local event                 = require("event")
  6.     local gpu                   = com.gpu
  7.     local turret                = com.os_energyturret
  8.     local radar                 = com.openperipheral_sensor
  9.     local autors                = {"qwertyMAN"}
  10.     local version               = "0.9.1"
  11.  
  12.     -- Настройки
  13.     local firePleayers          = true
  14.     local fireMobs              = true
  15.     local Black_Player_List     = {}
  16.     local White_Player_List     = {}
  17.     -- относительные координаты пушки от сканера
  18.     local correct = {
  19.         x = 0,
  20.         y = 3,
  21.         z = 0
  22.     }
  23.  
  24.     local function pointer(x,y,z)
  25.         local distXY = math.sqrt(x^2+z^2)
  26.         local distDY = math.sqrt(y^2+distXY^2)
  27.         local outX = math.deg(math.acos(x/distXY))+90
  28.         local outY = 90-math.deg(math.acos(y/distDY))
  29.         if z<0 then
  30.             outX = (180-outX)%360
  31.         end
  32.         return outX,outY
  33.     end    
  34.                    
  35.     while true do
  36.         os.sleep(0)
  37.         local target = false
  38.         local fire = true
  39.         local scan=radar.getPlayers()
  40.         if firePleayers and #scan>0 then
  41.             if #White_Player_List>0 then
  42.                 for i=1, #autors do
  43.                     White_Player_List[#White_Player_List+1] = autors[i]
  44.                 end
  45.                 for i=1, #scan do
  46.                     local swich = true
  47.                     for j=1, #White_Player_List do
  48.                         if scan[i].name==White_Player_List[j] or not scan[i].name then
  49.                             swich = false
  50.                         end
  51.                     end
  52.                     if swich then
  53.                         target = scan[i].name
  54.                         break
  55.                     end
  56.                 end
  57.             elseif #Black_Player_List>0 then
  58.                 for i=#Black_Player_List, 1, -1 do
  59.                     for j=1, #autors do
  60.                         if Black_Player_List[i] == autors[j] then
  61.                             table.remove(Black_Player_List,i)
  62.                         end
  63.                     end
  64.                 end
  65.                 for i=1, #scan do
  66.                     local swich = false
  67.                     for j=1, #Black_Player_List do
  68.                         if scan[i].name==Black_Player_List[j] then
  69.                             swich = true
  70.                         end
  71.                     end
  72.                     if swich then
  73.                         target = scan[i].name
  74.                         break
  75.                     end
  76.                 end
  77.             else
  78.                 if #autors>0 then
  79.                     for i=1, #autors do
  80.                         White_Player_List[#White_Player_List+1] = autors[i]
  81.                     end
  82.                 else
  83.                     target = scan[1].name
  84.                 end
  85.             end
  86.             if target and radar.getPlayerByName(target) then
  87.                 target=radar.getPlayerByName(target).all()
  88.                 local x,y,z = target.position.x-0.5-correct.x, target.position.y+0.3-correct.y, target.position.z-0.5-correct.z
  89.                 local vx,vy = pointer(x,y,z)
  90.                 turret.moveTo(vx,vy)
  91.                 if turret.isOnTarget() then
  92.                     turret.fire()
  93.                 end
  94.                 fire = false
  95.             end
  96.         end
  97.         target = false
  98.         if fireMobs and fire then
  99.             local scan=radar.getMobIds()
  100.             if #scan>0 then
  101.                 for i=1, #scan do
  102.                     local mob
  103.                     if radar.getMobData(scan[i]).basic() then
  104.                         mob = radar.getMobData(scan[i]).basic()
  105.                         target = mob
  106.                     end
  107.                 end
  108.                 if target then
  109.                     local x,y,z = target.position.x-0.5-correct.x, target.position.y-0.5-correct.y, target.position.z-0.5-correct.z
  110.                     local vx,vy = pointer(x,y,z)
  111.                     turret.moveTo(vx,vy)
  112.                     if turret.isOnTarget() then
  113.                         turret.fire()
  114.                     end
  115.                 end
  116.             end
  117.         end
  118.     end
  119. end
  120. -- мегакостыль
  121. while true do
  122.     local oop = pcall(func)
  123.     print(oop)
  124. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement