Skip to content

Examples

To use one, click New on the Scripts page and paste it into the Code view, or save it as a .lua file in %APPDATA%\CitronV2\scripts. Then switch it on in the list.

The first time the Scripts page opens, it puts these four in your scripts folder, switched off.

Your fight config while an enemy is near, your normal one otherwise. Put your own config names and range in the first line.

-- auto_config.lua: your fight config while an enemy is near,
-- your normal one otherwise. Put your own names and range here.
local FIGHT, CALM, RANGE = "Fight", "Default", 12
timer.every(0.5, function()
local near = world.nearestPlayer({ enemies = true, range = RANGE })
local want = near and FIGHT or CALM
if config.current() ~= want then
config.load(want)
end
end)

A notification and a sound when your health drops low, once each time.

-- low_health.lua: a warning when your health drops low,
-- once each time.
local warned = false
events.on("tick", function()
local hp = player.health()
if not hp then return end
if hp <= 6 and not warned then
client.notify("Low health: " .. util.round(hp, 1))
client.sound("SystemExclamation")
warned = true
elseif hp > 10 then
warned = false
end
end)

A box round the nearest enemy, and their name and distance over their head.

-- enemy_marker.lua: a box round the nearest enemy, and over
-- their head their name and how far they are.
events.on("render3d", function()
local p = world.nearestPlayer({ enemies = true, range = 32 })
if p then
draw3d.box(p.x - 0.35, p.y, p.z - 0.35, p.x + 0.35, p.y + p.height, p.z + 0.35, 0xFF5B5B)
end
end)
events.on("render2d", function(ctx)
local p = world.nearestPlayer({ enemies = true, range = 32 })
if not p then return end
local x, y = ctx.worldToScreen(p.x, p.y + p.height + 0.4, p.z)
if x then
ctx.text(string.format("%s %.1fm", p.name, p.distance), x, y, 0xFFFFFF, 16, { align = "center" })
end
end)

Your hits this session and your best combo ever, in the top left corner. The best combo is kept in storage, so it survives restarts.

-- session_stats.lua: your hits this session and your best
-- combo ever, in the top left corner.
local hits = 0
local best = storage.get("bestCombo", 0)
local combo, last = 0, 0
events.on("attack", function(target)
hits = hits + 1
combo = (client.time() - last < 1.5) and combo + 1 or 1
last = client.time()
if combo > best then
best = combo
storage.set("bestCombo", best)
end
end)
events.on("render2d", function(ctx)
ctx.rect(10, 10, 170, 58, 0xB0101114, 8)
ctx.text("Hits " .. hits, 20, 16, 0xFFFFFF, 18)
ctx.text("Best combo " .. best, 20, 40, 0xC8F135, 16)
end)

Put your own webhook link in the first line. In Discord, a channel’s Edit Channel > Integrations > Webhooks makes one.

local HOOK = "https://discord.com/api/webhooks/..."
events.on("death", function()
local where = server.name() ~= "" and server.name() or server.address()
http.webhook(HOOK, player.name() .. " died on " .. where)
end)

Reach up while you hold a sword, back down otherwise. Distance is a range, so it takes a low and a high value.

local reach = modules.get("Reach")
events.on("tick", function()
local id = player.heldItem()
if id:find("sword") then
reach:set("Distance", 3.4, 3.6)
else
reach:set("Distance", 3.0, 3.0)
end
end)

While you hold a key, your view turns smoothly onto the nearest enemy in front of you. Friends and teammates are left out the same way Citron’s combat modules leave them out.

-- aim_example.lua: while you hold the key, your view turns onto the
-- nearest enemy in front of you, smoothly.
local KEY = "MB5" -- hold to aim: "MB4", "MB5", "R", "LAlt", "F"...
local RANGE = 6 -- blocks
local FOV = 90 -- degrees, the whole cone in front of you
local SPEED = 14 -- how fast the view catches up (higher = snappier)
local AIM_HEIGHT = 0.75 -- where on the body: 0 feet, 1 top of the head
local AUTO_CLICK = false -- also click while the crosshair is on them
local CPS = 10
-- an angle into -180..180
local function wrap(a)
return (a + 540) % 360 - 180
end
-- yaw and pitch from your eyes to a point (yaw 0 faces south, +pitch looks down)
local function anglesTo(x, y, z)
local ex, ey, ez = player.eye()
local dx, dy, dz = x - ex, y - ey, z - ez
local flat = math.sqrt(dx * dx + dz * dz)
return math.deg(math.atan(-dx, dz)), -math.deg(math.atan(dy, flat))
end
local function aimPoint(p)
return p.x, p.y + p.height * AIM_HEIGHT, p.z
end
-- the enemy closest to your crosshair inside the cone
local function pick(yaw, pitch)
local _, enemies = world.playersWithin(RANGE, true)
local best, bestOff
for _, p in ipairs(enemies) do
if not p.invisible then
local ty, tp = anglesTo(aimPoint(p))
local off = math.sqrt(wrap(ty - yaw) ^ 2 + (tp - pitch) ^ 2)
if off <= FOV / 2 and (not bestOff or off < bestOff) then
best, bestOff = p, off
end
end
end
return best
end
local lastClick = 0
events.on("frame", function(dt)
if not client.playing() or client.guiOpen() or not input.isKeyDown(KEY) then return end
local yaw, pitch = player.rotation()
if not yaw then return end
local target = pick(yaw, pitch)
if not target then return end
local ty, tp = anglesTo(aimPoint(target))
local k = 1 - math.exp(-SPEED * dt) -- the same feel at any frame rate
player.setRotation(yaw + wrap(ty - yaw) * k, pitch + (tp - pitch) * k)
if AUTO_CLICK then
local onThem = player.lookingAt()
if onThem and onThem.id == target.id and client.time() - lastClick >= 1 / CPS then
lastClick = client.time()
player.attack()
end
end
end)
  • player.setRotation and player.lookAt turn your real view, all the way at once. For a smooth aim, turn part of the way every frame, as the script above does.
  • A script cannot rotate silently: the server sees the same look you do.
  • Player tables have no velocity. To lead a moving target, keep their last x and z by id and work out the difference yourself.
  • There is no line of sight check. world.blockAt can look at blocks, but each new block waits a frame.
  • Citron’s own AimAssist, Sticky Aim, Silent Aura and Trigger Bot already aim and hit. A script can switch and tune them instead of aiming itself: modules.enable("Trigger Bot"), modules.set("AimAssist", "FOV Cone", 60).

Share your own scripts in the Discord’s #client-scripts channel.