Lua · Examples · Events
Kill popup animation
A big centred "+1" that pops in, slides up and fades out on every kill. No sound, pure animation.
Uses: math.lerp, color.alpha, easing
kill_popup_animation.lua
-- name: Kill Popup
-- author: Adolfjon
-- version: 1.0
-- description: Animated +1 in the middle of the screen on every kill.
ui.color("col", "Colour", color(255, 255, 255))
ui.color("hs", "Headshot colour", color(255, 90, 90))
local pops = {}
local function ease_out(t) return 1 - (1 - t) ^ 3 end
function on_kill(e)
pops[#pops + 1] = { at = globals.time(), hs = e.headshot, n = e.round_kills }
end
function on_frame()
local w, h = draw.screen()
local now = globals.time()
for i = #pops, 1, -1 do
local p = pops[i]
local t = (now - p.at) / 1.2
if t >= 1 then
table.remove(pops, i)
else
local rise = ease_out(t) * 60
local scale = t < 0.15 and math.lerp(10, 34, t / 0.15) or 34
local alpha = t < 0.6 and 255 or 255 * (1 - (t - 0.6) / 0.4)
local text = p.n > 1 and ("+" .. p.n) or "+1"
local col = p.hs and ui.get("hs") or ui.get("col")
local tw, th = draw.text_size(text, scale)
draw.text_outline(w / 2 - tw / 2, h * 0.42 - rise - th / 2, text, color.alpha(col, alpha), scale)
end
end
endInstall it
- Press Copy on the code above.
- In the menu, open Lua and press From Clipboard. The file is named from its
-- name:line. - Turn the script on in the list. Its settings show on its own tab.
Change anything you like and press Save (Ctrl+S) in the editor; the script reloads at once. See Getting started for the other ways to add scripts.