Callback Test
Download the complete project ZIP. Preserve the directory structure, including any helper modules. These examples require the live Traceless client; they are not standalone Lua programs.
Individual source downloads:
main.lua
local traceless = require("traceless")
local counts = {
paint = 0,
paint_ui = 0,
setup = 0,
predict_command = 0,
prediction = 0,
override_view = 0,
net_start = 0,
net_end = 0,
pre_render = 0,
post_render = 0,
player_hurt = 0,
round_start = 0,
aim_fire = 0,
aim_hit = 0,
aim_miss = 0,
console_input = 0,
timer = 0
}
local enabled = traceless.ui.new_checkbox("LUA", "Callback test", "Enabled", true)
local accent = traceless.ui.new_color_picker("LUA", "Callback test", "Accent", 125, 210, 255, 255)
local custom_font
local function get_font()
if custom_font == nil then
custom_font = traceless.render.create_font(
"Tahoma",
14,
400,
traceless.render.font_flags.outline)
end
return custom_font
end
local function draw_text(x, y, text, red, green, blue, alpha)
local font = get_font()
if font ~= nil then
traceless.render.font_text(
font,
x,
y,
red,
green,
blue,
alpha,
traceless.render.font_alignment.left,
text)
return
end
traceless.render.text(x, y, red, green, blue, alpha, "", 0, text)
end
traceless.events.on("paint", function()
counts.paint = counts.paint + 1
end)
traceless.events.on("paint_ui", function()
counts.paint_ui = counts.paint_ui + 1
if not traceless.ui.get(enabled) then
return
end
local red, green, blue, alpha = traceless.ui.get(accent)
local x, y = 30, 80
traceless.render.rectangle(x, y, 390, 250, 18, 22, 30, 235)
draw_text(x + 10, y + 10, "Traceless callback test", 255, 255, 255, 255)
draw_text(x + 10, y + 35,
string.format("paint %d | paint_ui %d", counts.paint, counts.paint_ui),
220, 225, 235, 255)
draw_text(x + 10, y + 55,
string.format("setup %d | prediction %d", counts.setup, counts.prediction),
220, 225, 235, 255)
draw_text(x + 10, y + 75,
string.format("predict %d | view %d", counts.predict_command, counts.override_view),
220, 225, 235, 255)
draw_text(x + 10, y + 95,
string.format("net %d/%d | render %d/%d", counts.net_start, counts.net_end, counts.pre_render, counts.post_render),
220, 225, 235, 255)
draw_text(x + 10, y + 115,
string.format("events hurt/round %d/%d", counts.player_hurt, counts.round_start),
220, 225, 235, 255)
draw_text(x + 10, y + 135,
string.format("shots fire/hit/miss %d/%d/%d", counts.aim_fire, counts.aim_hit, counts.aim_miss),
220, 225, 235, 255)
draw_text(x + 10, y + 155,
string.format("console %d | timer %d", counts.console_input, counts.timer),
220, 225, 235, 255)
traceless.render.indicator(red, green, blue, alpha, "callback test active")
end)
traceless.events.on("command.setup", function(command)
counts.setup = counts.setup + 1
local angles = command.view_angles
if angles ~= nil then
command.view_angles = angles
end
local button = command:button("jump")
for _, step in command:subticks() do
if step.when ~= nil then
break
end
end
for _, frame in command:history() do
if frame.frame_number ~= nil then
break
end
end
local forward_move = command.forward_move
if forward_move ~= nil then
command.forward_move = forward_move
end
if counts.setup == 1 and button == nil then
traceless.console.error("callback test: command button state unavailable")
end
end)
traceless.events.on("predict_command", function(command)
counts.predict_command = counts.predict_command + 1
if counts.predict_command == 1
and (command.command_number == nil or command.tick_count == nil) then
traceless.console.error("callback test: predicted command fields unavailable")
end
end)
traceless.events.on("prediction_update", function()
counts.prediction = counts.prediction + 1
end)
traceless.events.on("override_view", function(view)
counts.override_view = counts.override_view + 1
if counts.override_view == 1
and (view == nil or view.fov == nil or view.pitch == nil or view.yaw == nil) then
traceless.console.error("callback test: view fields unavailable")
end
end)
traceless.events.on("net_update_start", function()
counts.net_start = counts.net_start + 1
end)
traceless.events.on("net_update_end", function()
counts.net_end = counts.net_end + 1
end)
traceless.events.on("pre_render", function()
counts.pre_render = counts.pre_render + 1
end)
traceless.events.on("post_render", function()
counts.post_render = counts.post_render + 1
end)
traceless.events.on("player_hurt", function(event)
counts.player_hurt = counts.player_hurt + 1
if counts.player_hurt == 1 and (event == nil or event.name ~= "player_hurt") then
traceless.console.error("callback test: player_hurt event payload unavailable")
end
end)
traceless.events.on("round_start", function(event)
counts.round_start = counts.round_start + 1
if counts.round_start == 1 and (event == nil or event.name ~= "round_start") then
traceless.console.error("callback test: round_start event payload unavailable")
end
end)
traceless.events.on("aim_fire", function(shot)
counts.aim_fire = counts.aim_fire + 1
if counts.aim_fire == 1 and (shot == nil or shot.id == nil) then
traceless.console.error("callback test: aim_fire payload unavailable")
end
end)
traceless.events.on("aim_hit", function(shot)
counts.aim_hit = counts.aim_hit + 1
if counts.aim_hit == 1 and (shot == nil or shot.id == nil) then
traceless.console.error("callback test: aim_hit payload unavailable")
end
end)
traceless.events.on("aim_miss", function(shot)
counts.aim_miss = counts.aim_miss + 1
if counts.aim_miss == 1 and (shot == nil or shot.id == nil) then
traceless.console.error("callback test: aim_miss payload unavailable")
end
end)
traceless.events.on("console_input", function(text)
local command = text:match("^%s*(.-)%s*$")
if command == "traceless_callback_test" then
counts.console_input = counts.console_input + 1
traceless.notify.info("callback test console event received")
return true
end
return false
end)
traceless.timer.after(1, function(label)
counts.timer = counts.timer + 1
if label ~= "callback_test" then
traceless.console.error("callback test: timer argument unavailable")
end
end, "callback_test")
traceless.events.on("shutdown", function()
traceless.console.info("Traceless callback test unloaded")
end)
traceless.console.info("enter traceless_callback_test to exercise console_input")