-
Notifications
You must be signed in to change notification settings - Fork 0
/
torretaMicro.lua
137 lines (123 loc) · 3.76 KB
/
torretaMicro.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
--Made by Gato Borrachon --24/04/2020
----LIBRERIAS----
local turret = component.proxy(component.list("os_energyturret")())
local entdetec = component.proxy(component.list("os_entdetector")())
----VARIABLES-ESTATICAS----
local objetivos = {}
local anguloVertical
local anguloHorizontal
local tanXZ
local tanY
local x
local y
local z
local nombreDeObjetivo
local comprobarX = {0}
local comprobarY = {0}
local comprobarZ = {0}
local mob1 = "Esqueleto" --here you set more variables for more mob objetives, you will need to add the respect condition more below
local mob2 = "Zombi"
local mob3 = "Creeper"
local range = 18 --this is the range of the turret
local function pullFiltered(...)
local args = table.pack(...)
local seconds, filter = math.huge
if type(args[1]) == "function" then
filter = args[1]
else
checkArg(1, args[1], "number", "nil")
checkArg(2, args[2], "function", "nil")
seconds = args[1]
filter = args[2]
end
repeat
local signal = table.pack(computer.pullSignal(seconds))
if signal.n > 0 then
if not (seconds or filter) or filter == nil or filter(table.unpack(signal, 1, signal.n)) then
return table.unpack(signal, 1, signal.n)
end
end
until signal.n == 0
end
local function createPlainFilter(name, ...)
local filter = table.pack(...)
if name == nil and filter.n == 0 then
return nil
end
return function(...)
local signal = table.pack(...)
if name and not (type(signal[1]) == "string" and signal[1]:match(name)) then
return false
end
for i = 1, filter.n do
if filter[i] ~= nil and filter[i] ~= signal[i + 1] then
return false
end
end
return true
end
end
local function pull(...)
local args = table.pack(...)
if type(args[1]) == "string" then
return pullFiltered(createPlainFilter(...))
else
checkArg(1, args[1], "number", "nil")
checkArg(2, args[2], "string", "nil")
return pullFiltered(args[1], createPlainFilter(select(2, ...)))
end
end
local function sleep(timeout)
checkArg(1, timeout, "number", "nil")
local deadline = computer.uptime() + (timeout or 0)
repeat
pull(deadline - computer.uptime())
until computer.uptime() >= deadline
end
----PROGRAMA----
for i=1, math.huge do
objetivos = entdetec.scanEntities(range)
if objetivos == true or objetivos == false then
else
for k,v in pairs(objetivos) do
nombreDeObjetivo = v.name
if nombreDeObjetivo == mob1 or nombreDeObjetivo == mob2 or nombreDeObjetivo == mob3 then --here you will add the conditions to
--make the turret attack more mobs, there are 3 examples
x = v.x
y = v.y+1
z = v.z
tanXZ = x/z
tanY = y/(math.sqrt((x*x)+(z*z)))
anguloHorizontal = math.deg(math.atan(tanXZ))
anguloVertical = math.deg(math.atan(tanY))
if x >= 0 and z >= 0 then --90-180
anguloHorizontal = -anguloHorizontal+180
elseif x < 0 and z > 0 then --180-270
anguloHorizontal = -anguloHorizontal+180
elseif x > 0 and z < 0 then --0-90
anguloHorizontal = -anguloHorizontal
elseif x < 0 and z < 0 then --270-360
anguloHorizontal = -anguloHorizontal+360
end
if anguloVertical >= 45 then
anguloVertical = 44
elseif anguloVertical <= -45 then
anguloVertical = -44
end
if x ~= comprobarX[1] or y ~= comprobarY[1] or z ~= comprobarZ[1] then
table.insert(comprobarX, 1, x)
table.insert(comprobarY, 1, y)
table.insert(comprobarZ, 1, z)
turret.powerOn()
turret.setArmed(true)
turret.moveTo(anguloHorizontal,anguloVertical)
while turret.isOnTarget() == false do
sleep(0.1)
end
turret.fire()
sleep(0.5)
end
end
end
end
end