Airstrike¶
An active ability on a key: takedowns earn airstrike charges, and pressing the key calls one down on the nearest enemy. Shows events, game.emit from another mod, game.store and a key setting.
| Mod id | Kind | Files |
|---|---|---|
airstrike |
Lua code | 4 |
Copy the whole folder into mods/ in the save folder to try it. Browse it on GitHub.
mod.json¶
{
"id": "airstrike",
"title": "Airstrike",
"version": "1.0",
"api": 1,
"author": "Taxation Evasion",
"description": "An active ability on a key: takedowns earn airstrike charges, and pressing the key calls one down on the nearest enemy. Shows events, game.emit from another mod, game.store and a key setting.",
"scripts": ["main.lua"],
"after": ["bounty_board"],
"settings": [
{
"id": "strike",
"label": "AIRSTRIKE KEY",
"type": "key",
"default": "Q",
"help": "Calls an airstrike on the nearest enemy when you have a charge."
}
]
}
main.lua¶
-- Airstrike: takedowns earn charges; the AIRSTRIKE KEY (a `key` setting the
-- player can rebind) spends one to blast the nearest enemy from the air.
local Charges = require('lib.charges')
game.on('run_start', function(s) s.airstrike = Charges.new() end)
-- Every takedown counts, however it happened.
game.on('enemy_death', function(s, e)
if s.airstrike and Charges.takedown(s.airstrike) then game.sound(s, 'StartingBeepHi', 0.25) end
end)
-- A claimed Bounty Board bounty is worth a full charge, when that mod is on.
-- Listening to a mod that is not loaded is fine: nothing arrives.
game.on('bounty_board.claimed', function(s)
local a = s.airstrike
if a and a.charges < Charges.MAX then a.charges = a.charges + 1 end
end)
game.on('key', function(s, id)
local a = s.airstrike
if id ~= 'airstrike.strike' or not a or a.charges < 1 then return end
local target = game.target(s, 400)
if not target or not target.role then return end -- enemies only
a.charges, a.called = a.charges - 1, a.called + 1
local _, killed = game.blast(s, target.x, target.y, 70, 60)
-- Whatever survives the blast is left spinning.
for _, e in ipairs(game.enemies(s, target.x, target.y, 110)) do game.stun(s, e, 1.5) end
game.sound(s, 'explosion_rumble', 0.5)
a.flash = {x = target.x, y = target.y, t = s.time}
-- The best single strike, kept across runs.
if #killed > (game.store('best') or 0) then game.store('best', #killed) end
game.emit(s, 'airstrike.called', {x = target.x, y = target.y, killed = #killed})
end)
game.on('draw_world', function(s, d)
local f = s.airstrike and s.airstrike.flash
if not f or s.time - f.t > 0.4 then return end
local k = 1 - (s.time - f.t) / 0.4
d.circle(f.x, f.y, 70 * (1.2 - 0.2 * k), 'amber', 0.35 * k)
d.light(f.x, f.y, 200, 'amber', d.reduced_flashes and 0.4 * k or k)
end)
-- Charges as small arrows above the speedometer, filled when ready.
game.on('draw_hud', function(s, d)
local a = s.airstrike
if not a then return end
d.anchor('bottom')
for i = 1, Charges.MAX do
local x, y = 296 + (i - 1) * 16, 300
local c = i <= a.charges and 'amber' or 'gray'
d.triangle(x, y + 10, x + 12, y + 10, x + 6, y, c, i <= a.charges and 1 or 0.4)
end
d.text(game.text('airstrike.best', {best = game.store('best') or 0}), 320, 314, 'gray', 'center', 0.8)
end)
lib/charges.lua¶
-- Charge bookkeeping, in a file of its own: main.lua loads it with
-- require('lib.charges').
local M = {MAX = 3, PER = 4} -- up to 3 charges; one per 4 takedowns
function M.new() return {charges = 1, progress = 0, called = 0} end
-- One takedown toward the next charge. True when a charge was earned.
function M.takedown(a)
if a.charges >= M.MAX then return false end
a.progress = a.progress + 1
if a.progress < M.PER then return false end
a.progress, a.charges = 0, a.charges + 1
return true
end
return M