Skip to content

Instantly share code, notes, and snippets.

@keipes
Created August 15, 2015 06:43
Show Gist options
  • Save keipes/74a422058e55ac80c7fe to your computer and use it in GitHub Desktop.
Save keipes/74a422058e55ac80c7fe to your computer and use it in GitHub Desktop.
function Update()
target = acquireTarget(800)
if target ~= nil then
fireAt(target)
end
end
function acquireTarget(minDistance)
target = nil
for i = 0, I:GetNumberOfMainframes(), 1 do
for j = 0, I:GetNumberOfTargets(i), 1 do
t = I:GetTargetInfo(i, j)
if t.Valid and (target == nil or t.Priority < target.Priority) and t.Position.GroundDistance < minDistance then
target = t
end
end
end
return target
end
function fireAt(target)
for i = 0, I:GetWeaponCount(), 1 do
weaponInfo = I:GetWeaponInfo(i)
if weaponInfo.Valid then
weaponPosition = I:GetWeaponInfo(i).GlobalPosition
targetPosition = target.AimPointPosition
I:AimWeaponInDirection(
i,
targetPosition.x- weaponPosition.x,
targetPosition.y - weaponPosition.y,
targetPosition.z - weaponPosition.z,
0)
I:FireWeapon(i, 0)
end
end
end
I:BindUpdateFunction(Update)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment