Skip to content

Instantly share code, notes, and snippets.

@tuefekci
Created June 25, 2023 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuefekci/5d3948eb93703e0dd58b0a3e74c59e9d to your computer and use it in GitHub Desktop.
Save tuefekci/5d3948eb93703e0dd58b0a3e74c59e9d to your computer and use it in GitHub Desktop.
out = {}
--var = {}
delay = 1
-- =====================================================
-- Functions
-- =====================================================
function math.average(t)
local sum = 0
for _,v in pairs(t) do -- Get the sum of all numbers in t
sum = sum + v
end
return sum / #t
end
function min(t)
local min = math.huge
for i = 1, #t do
min = min < t[i] and min or t[i]
end
return min
end
function max(a)
local values = {}
for k,v in pairs(a) do
values[#values+1] = v
end
table.sort(values) -- automatically sorts lowest to highest
return values[#values]
end
function count(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end
-- =====================================================
-- Const
-- =====================================================
-- // Only if valid unit
if red['gunship-aircraft-machine-gun-_-signal'] > 0 then
unitId = red['gunship-aircraft-machine-gun-_-signal']
var['units'] = red['signal-count']
-- =====================================================
-- Checks
-- =====================================================
-- =====================================================
-- Distance
if var['distance'] == nil or count(var['distance']) > var['units'] then
var['distance'] = {}
end
distance = 0
distance = distance + red['signal-range']
var['max-distance'] = max(var['distance'])
-- =====================================================
-- Health Check
if var['health'] == nil or count(var['health']) > var['units'] then
var['health'] = {}
end
health = 0
health = health + red['signal-health']
var['health'][unitId] = health
-- =====================================================
-- Ammo Check
if var['ammo'] == nil or count(var['ammo']) > var['units'] then
var['ammo'] = {}
end
ammo = 0
ammo = ammo + red['firearm-magazine']
ammo = ammo + red['piercing-rounds-magazine']
var['ammo'][unitId] = ammo
-- =====================================================
-- Fuel Check
if var['fuel'] == nil or count(var['fuel']) > var['units'] then
var['fuel'] = {}
end
fuel = 0
fuel = fuel + red['processed-fuel']
var['fuel'][unitId] = fuel
--game.print(min(var['health']))
-- =====================================================
-- Logic
-- =====================================================
if var['depot-timer'] == nil or var['depot-timer'] > 2000 then
var['depot-timer'] = 0
end
if var['angle'] == nil or var['angle'] > 35000 then
var['angle'] = 1
end
var['angle'] = var['angle'] + 1
if red['zone-x-red'] == nil then
red['zone-x-red'] = 0
end
out['gunship-aircraft-machine-gun-_-signal'] = unitId
if red['gunship-aircraft-machine-gun-_-signal'] == 1 then
var['commander-id'] = red['signal-id']
end
if red['zone-x-red'] == 1 and var['units'] > 4 and min(var['health']) > 250 and min(var['ammo']) > 25 and min(var['fuel']) > 20 then
var['action'] = "attack"
else
var['action'] = "depot"
end
if var['action'] == "attack" and var['depot-timer'] == 0 then
var['action'] = "attack"
else
var['action'] = "depot"
end
if var['action'] == "attack" then
if red['signal-id'] == var['commander-id'] then
if var['distance'] == not nil and max(var['distance']) > 50 then
var['commander-pause'] = 1
out['signal-speed'] = 1
else
var['commander-pause'] = 0
out['signal-x-tile'] = red['signal-x-tile'] + math.cos(var['angle']/100)*35
out['signal-y-tile'] = red['signal-y-tile'] + math.sin(var['angle']/100)*35
end
else
out['signal-follow-id'] = var['commander-id']
var['distance'][unitId] = distance
end
out['signal-red'] = 1
attack = 1
var['action'] = "attack"
end
if var['action'] == "depot" then
var['depot-timer'] = var['depot-timer'] + 1
if red['signal-time-move'] > 10000 and distance > 10 then
--out['signal-x-tile'] = green['signal-x-tile'] + 10
--out['signal-y-tile'] = green['signal-y-tile'] + 10
else
--out['signal-follow-player'] = 1
out['signal-x-tile'] = green['signal-x-tile']
out['signal-y-tile'] = green['signal-y-tile']
end
out['signal-black'] = 1
attack = 0
if var['action'] == "attack" or var['action'] == "depot" then
end
var['action'] = "depot"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment