Examples New

Complete xiao.cmd scripts - auto sprint, bunny hop, silent aim, server only spin, input logger and cost monitor.

Each script runs as is: paste it in the Lua tab, press Execute, and Clear VM to stop it.

Inside a cmd callback xiao.game returns nothing, so the scripts that need the world read it in think and keep it in an upvalue (see Execution contexts).

Auto sprint

Sprint whenever the player walks forward and does not sneak. The client simulates the sprint, so nothing needs fixing.

xiao.cmd.hook("createmove", "auto_sprint", function(cmd)
    if cmd:get_forward_move() > 0.5 and not cmd:has_button("sneak_down") then
        cmd:set_button("sprint_down")
    end
end)

Bunny hop

Jump on every tick spent on the ground while moving. on_ground is read once per frame on the render thread.

local grounded = false

xiao.signal.add("think", "bhop_state", function()
    local me = xiao.game.player()
    grounded = me ~= nil and me.on_ground == true
end)

xiao.cmd.hook("createmove", "bhop", function(cmd)
    local forward, left = cmd:get_move()
    if grounded and (forward ~= 0 or left ~= 0) then
        cmd:set_button("jump_down")
    end
end)

Silent aim

Aim the server at the closest player within 6 blocks while the view stays where the player looks. lock_angles carries the angles to the packet of the same tick and turns the movement so that the server keeps the path of the client.

local target

xiao.signal.add("think", "silent_target", function()
    target = nil
    local best = 6
    for _, p in ipairs(xiao.game.players()) do
        if p.distance ~= nil and p.distance < best then
            best, target = p.distance, {p.x, p.y, p.z}
        end
    end
end)

xiao.cmd.hook("createmove", "silent_aim", function(cmd)
    if target == nil then return end
    local x, y, z = cmd:get_position()
    local dx, dy, dz = target[1] - x, target[2] - y, target[3] - z
    local yaw = math.deg(math.atan2(-dx, dz))
    local pitch = math.deg(-math.atan2(dy, math.sqrt(dx * dx + dz * dz)))
    cmd:lock_angles()
    cmd:set_view_angles(pitch, yaw)
end)

Server only spin

Turn the body the server sees by 30 degrees per packet. The movement is turned back so that the server walks the same path as the client, and packets already aimed by the aura are left alone.

local spin = 0

xiao.cmd.hook("authinput", "spin", function(cmd)
    if cmd:native_aim() then return end
    spin = (spin + 30) % 360
    local pitch, yaw = cmd:get_view_angles()
    cmd:set_view_angles(pitch, yaw + spin)
    cmd:rotate_movement(yaw)
end)

Input logger

Print the buttons of the packet each time they change, with the client tick of the packet.

local last = ""

xiao.cmd.hook("authinput", "log", function(cmd)
    local names = {}
    for _, index in ipairs(cmd:get_buttons()) do
        names[#names + 1] = xiao.cmd.button_name(index) or tostring(index)
    end
    local text = table.concat(names, " ")
    if text ~= last then
        last = text
        print(cmd:command_number(), text)
    end
end)

Buttons come in index order: a player walking forward prints up block_breaking_delay_enabled vertical_collision, and W+D while sprinting adds sprint_down, right and sprinting.

Cost monitor

Print the cost of both layers every 5 seconds, from the render thread.

local elapsed = 0

xiao.signal.add("think", "cmd_cost", function(dt)
    elapsed = elapsed + dt
    if elapsed < 5 then return end
    elapsed = 0
    local s = xiao.cmd.stats()
    print(("createmove %d ticks %.1f us busy %d | authinput %d packets %.1f us busy %d"):format(
        s.createmove.calls, s.createmove.avg_us, s.createmove.busy,
        s.authinput.calls, s.authinput.avg_us, s.authinput.busy))
end)