Lua · Examples
Events
React to kills, deaths, rounds, damage, the bomb and spectators.
Each snippet runs as-is: copy it, press From Clipboard on the Lua page, turn it on. Quick start
#Two ways to listen
A global on_kill and any number of events.on("kill") handlers. Both run.
events_1.lua
function on_kill(e)
print("killed", e.victim, e.weapon)
end
events.on("kill", function(e)
if e.headshot then print("headshot!") end
end)#Damage log
player_hurt fires for every player that lost health.
events_2.lua
local log = {}
events.on("player_hurt", function(e)
if e.enemy then
table.insert(log, 1, e.name .. " -" .. e.damage .. " (" .. e.health .. " left)")
if #log > 6 then table.remove(log) end
end
end)
events.on("round_start", function() log = {} end)
function on_frame()
for i, line in ipairs(log) do
draw.text_outline(20, 300 + i * 16, line, color(255, 200, 200), 13)
end
end#Round stats
Count per round, show at round end.
events_3.lua
local kills = 0
function on_round_start() kills = 0 end
function on_kill(e) kills = e.round_kills end
function on_round_end(e)
notify.push((e.won and "Won" or "Lost") .. " the round with " .. kills .. " kills")
end#Bomb and spectators
Small events with one field or none.
events_4.lua
events.on("bomb_planted", function(e) notify.push("Bomb on " .. (e.site ~= "" and e.site or "?")) end)
events.on("bomb_defused", function() notify.push("Defused") end)
events.on("spectator_join", function(e) print(e.name .. " is watching") end)Full scripts
Complete scripts with a header and settings, ready to use or change.