evasivedocs
CS2 scriptingLua 5.4.9 · 25 guides · 292 API entries
API reference

Aim, attack and keys

Acting through approved scripts.

keys

Press the keys CS2 binds to game commands (+jump, slot3, ...). Only in an approved version of the file.

18 entriesAllow scripts to aim, shoot and press keys

Everything here needs Allow scripts to aim, shoot and press keys in Scripts > Security (off by default).

keys.press

function
keys.press(cmd [, ms]) -> boolean, string

Presses the key CS2 binds to a game command ("+jump", "slot3", ...) for ms, clamped 10..200; refused "unbound" when CS2 binds no key to the command. Same rules as input.press.

Arguments
NameTypeDefaultDescription
cmdstring
msoptionalnumber30
Returns
  • boolean, string
Example
Lua
events.on("tick", function() keys.press("+jump", 30) end)

keys.tap

function
keys.tap(cmd [, ms]) -> boolean, string

Alias of keys.press.

Arguments
NameTypeDefaultDescription
cmdstring
msoptionalnumber30
Returns
  • boolean, string
Example
Lua
events.on("tick", function() keys.tap("+jump", 30) end)

keys.down

function
keys.down(cmd) -> boolean, string

Holds a game command's key on a 2 s lease, like input.down.

Arguments
NameTypeDescription
cmdstring
Returns
  • boolean, string
Example
Lua
events.on("tick", function() keys.down("+jump") end)

keys.up

function
keys.up(cmd) -> boolean, string

Releases this state's hold of a game command's key. Accepted also while actions are blocked (menu open, panic, ...): a release is never refused for the gate.

Arguments
NameTypeDescription
cmdstring
Returns
  • boolean, string
Example
Lua
events.on("tick", function() keys.up("+jump") end)

keys.release

function
keys.release(cmd) -> boolean, string

Alias of keys.up.

Arguments
NameTypeDescription
cmdstring
Returns
  • boolean, string
Example
Lua
events.on("tick", function() keys.release("+jump") end)

keys.hold

function
keys.hold(cmd, ms) -> boolean, string

Holds a game command's key for ms, clamped 1..2000, like input.hold.

Arguments
NameTypeDescription
cmdstring
msnumber
Returns
  • boolean, string
Example
Lua
events.on("tick", function() keys.hold("+jump", 30) end)

keys.release_all

function
keys.release_all() -> boolean, string

Releases everything this state holds: its keys, its queued or held attack and its aim lease. Accepted also while actions are blocked (menu open, panic, ...): a release is never refused for the gate.

Returns
  • boolean, string
Example
Lua
events.on("tick", function() keys.release_all() end)

keys.reload

function
keys.reload() -> boolean, string

Presses +reload for 30 ms.

Returns
  • boolean, string
Example
Lua
events.on("tick", function() keys.reload() end)

keys.inspect

function
keys.inspect() -> boolean, string

Presses +lookatweapon for 30 ms.

Returns
  • boolean, string
Example
Lua
events.on("tick", function() keys.inspect() end)

keys.use

function
keys.use() -> boolean, string

Presses +use for 30 ms.

Returns
  • boolean, string
Example
Lua
events.on("tick", function() keys.use() end)

keys.drop

function
keys.drop() -> boolean, string

Presses drop for 30 ms.

Returns
  • boolean, string
Example
Lua
events.on("tick", function() keys.drop() end)

keys.jump

function
keys.jump() -> boolean, string

Presses +jump for 30 ms. Called again while the key is still down it extends the hold instead of jumping again.

Returns
  • boolean, string
Example
Lua
events.on("tick", function() keys.jump() end)

keys.duck

function
keys.duck([ms]) -> boolean, string

Holds +duck for ms, clamped 1..2000. The 30 ms default is a tap: pass a longer time, or call it every tick, to stay crouched.

Arguments
NameTypeDefaultDescription
msoptionalnumber30
Returns
  • boolean, string
Example
Lua
events.on("tick", function() keys.duck() end)

keys.walk

function
keys.walk([ms]) -> boolean, string

Holds +sprint (CS2 walk) for ms, clamped 1..2000. The 30 ms default is a tap: pass a longer time, or call it every tick, to keep walking.

Arguments
NameTypeDefaultDescription
msoptionalnumber30
Returns
  • boolean, string
Example
Lua
events.on("tick", function() keys.walk() end)

keys.slot

function
keys.slot(n) -> boolean, string

Presses slot1..slot10.

Arguments
NameTypeDescription
ninteger
Returns
  • boolean, string
Example
Lua
events.on("tick", function() keys.slot(3) end)

keys.lastinv

function
keys.lastinv() -> boolean, string

Presses lastinv.

Returns
  • boolean, string
Example
Lua
events.on("tick", function() keys.lastinv() end)

keys.next_weapon

function
keys.next_weapon() -> boolean, string

Presses invnext; a wheel-only binding gets one wheel notch.

Returns
  • boolean, string
Example
Lua
events.on("tick", function() keys.next_weapon() end)

keys.prev_weapon

function
keys.prev_weapon() -> boolean, string

Presses invprev; a wheel-only binding gets one wheel notch.

Returns
  • boolean, string
Example
Lua
events.on("tick", function() keys.prev_weapon() end)

aim

Turn the view through native aim, on a 60 ms lease. Only in an approved version of the file.

3 entriesAllow scripts to aim, shoot and press keys

Everything here needs Allow scripts to aim, shoot and press keys in Scripts > Security (off by default).

aim.look_at

function
aim.look_at(pos [, opts]) -> boolean, string

Asks native aim to turn the view smoothly toward a world point (a vec3, or x, y, z). opts: fov (degrees from the crosshair, default 10, capped by Script aim max FOV); aim_time_ms (default 40, clamped between Minimum aim time and 2000; the weapon's Aim profile time wins when longer, and its reaction delay, curve, noise and overshoot apply); player (a Player index: then that player must be alive and not spawn-protected, and the aim leads its movement); hitgroup (0..10, a tag only: the aim point stays the position); mode = "assist" (default: yields while native aim has its own target) or "override" (needs Scripts may replace the Aim target). The request is a 60 ms lease: repeat it every tick or combat event. true means accepted, not moved: nothing moves while the point is outside fov, the held item is not a firearm or is reloading or empty, the weapon's Aim profile is off or blocks (in air, flashed, smoke), an overlay attack press is held, or (assist) native aim has a target. Script aim turns at most 900 deg/s, timed on the real frame time, so the speed is the same at any fps; the first frame of a new script aim only starts its clock and does not move. When the user moves the mouse the lease ends and aim requests are refused "hand" for 200 ms.

Arguments
NameTypeDescription
posvec3
optsoptionaltable
Returns
  • boolean, string
Example
Lua
events.on("tick", function() aim.look_at(vec3(100, 200, 64), {fov=5}) end)

aim.turn

function
aim.turn(d_pitch, d_yaw [, opts]) -> boolean, string

Like aim.look_at, toward the current view turned by d_pitch, d_yaw degrees (+d_pitch looks down, +d_yaw turns left; pitch stops at 89). The turn is from the view at each call, so repeating aim.turn(0, 2) keeps the target moving as one continuous motion. opts: fov (degrees from the crosshair, default 10, capped by Script aim max FOV); aim_time_ms (default 40, clamped between Minimum aim time and 2000; the weapon's Aim profile time wins when longer, and its reaction delay, curve, noise and overshoot apply); player (a Player index: then that player must be alive and not spawn-protected, and the aim leads its movement); hitgroup (0..10, a tag only: the aim point stays the position); mode = "assist" (default: yields while native aim has its own target) or "override" (needs Scripts may replace the Aim target). The request is a 60 ms lease: repeat it every tick or combat event. true means accepted, not moved: nothing moves while the point is outside fov, the held item is not a firearm or is reloading or empty, the weapon's Aim profile is off or blocks (in air, flashed, smoke), an overlay attack press is held, or (assist) native aim has a target. Script aim turns at most 900 deg/s, timed on the real frame time, so the speed is the same at any fps; the first frame of a new script aim only starts its clock and does not move. When the user moves the mouse the lease ends and aim requests are refused "hand" for 200 ms.

Arguments
NameTypeDescription
d_pitchnumber
d_yawnumber
optsoptionaltable
Returns
  • boolean, string
Example
Lua
events.on("tick", function() aim.turn(0, 2) end)

aim.release

function
aim.release() -> boolean, string

Ends this state's aim lease. Accepted also while actions are blocked (menu open, panic, ...): a release is never refused for the gate.

Returns
  • boolean, string
Example
Lua
events.on("tick", function() aim.release() end)

attack

Primary and secondary attack presses through the trigger safety gates. Only in an approved version of the file.

4 entriesAllow scripts to aim, shoot and press keys

Everything here needs Allow scripts to aim, shoot and press keys in Scripts > Security (off by default).

attack.fire

function
attack.fire([opts]) -> boolean, string

Queues one primary press. opts: hold_ms (default 30, 1..200), delay_ms (default 0, 0..1000). Hold and delay are raised to the humanize.script profile's draw. Primary attacks are refused "combat" unless the held weapon has ammo, is not reloading and its Triggerbot profile is enabled with its no-air, no-flash and smoke conditions met; any attack is refused "native" while a native trigger or the nade helper is attacking, "physical" while the user holds the button, "busy" while an attack is queued or held, "rate" past 8 attacks per second. A queued press not sent within 250 ms of its time is dropped; a held one is released as soon as a condition fails.

Arguments
NameTypeDescription
optsoptionaltable
Returns
  • boolean, string
Example
Lua
events.on("tick", function() attack.fire({hold_ms=30}) end)

attack.hold

function
attack.hold(ms) -> boolean, string

One primary press held ms, clamped 1..200, like attack.fire({hold_ms = ms}). Hold and delay are raised to the humanize.script profile's draw. Primary attacks are refused "combat" unless the held weapon has ammo, is not reloading and its Triggerbot profile is enabled with its no-air, no-flash and smoke conditions met; any attack is refused "native" while a native trigger or the nade helper is attacking, "physical" while the user holds the button, "busy" while an attack is queued or held, "rate" past 8 attacks per second. A queued press not sent within 250 ms of its time is dropped; a held one is released as soon as a condition fails.

Arguments
NameTypeDescription
msnumber
Returns
  • boolean, string
Example
Lua
events.on("tick", function() attack.hold(50) end)

attack.secondary

function
attack.secondary([ms]) -> boolean, string

One secondary press held ms, clamped 1..200. The rules of attack.fire apply except the weapon and Triggerbot profile conditions.

Arguments
NameTypeDefaultDescription
msoptionalnumber30
Returns
  • boolean, string
Example
Lua
events.on("tick", function() attack.secondary(30) end)

attack.release

function
attack.release() -> boolean, string

Releases this state's queued or held attack. Accepted also while actions are blocked (menu open, panic, ...): a release is never refused for the gate.

Returns
  • boolean, string
Example
Lua
events.on("tick", function() attack.release() end)

act

This script's action status: allowed, the last refusal reason, held keys, leases and rates.

1 entryAllow scripts to aim, shoot and press keys

Everything here needs Allow scripts to aim, shoot and press keys in Scripts > Security (off by default).

act.status

function
act.status() -> table

This state's action status: {allowed, panic, reason, aim_live, attack_live, accepted, refused, held = {vk, ...}, rate = {edges_last_second, presses_last_second}, leases = {aim, attack}}. allowed: it may act now; reason: why not (live while blocked: menu, chat, focus, ...), else its last refusal or why its holds were dropped ("" after an accepted call); accepted / refused: its call counts; held: the keys it holds; edges_last_second: its key presses, releases and wheel notches in the last second (limit 20); presses_last_second: its attack presses in the last second (limit 8; key presses are not counted); leases.aim / leases.attack: the same as aim_live / attack_live. Its keys, attack and aim lease are dropped when one of its callbacks raises an error ("error"), runs past its own time cap (2 ms, 0.5 ms for combat) or uses at least half of the frame budget itself before the budget stops it ("budget"); a callback stopped only because other scripts used the budget keeps them. Every action call returns true, "" or false and one of these reasons: permission (act off), unsafe (insecure FFI allowed), not running, approval, panic, menu (overlay menu or an overlay text field), local player (none, or dead); input disabled (Allow input is off), focus (CS2 is not the foreground window), cursor (CS2 shows a cursor: console, buy menu or another game menu), chat (CS2 chat is open), gate (the overlay has not read a game frame yet); unbound (CS2 binds no key to the command); binding (mouse3..mouse5 or the wheel not bound); key (a key scripts may never press); chord; physical (the user holds the key); native (an overlay feature uses it); owner (another script holds it); duration; rate; hand (the mouse moved in the last 200 ms); override; target; combat; busy (an attack is already queued or held); command; slot; position; mode; override disabled; unavailable; and in act.status only, after the runtime dropped this state's holds: budget (one of its callbacks overran), error (one of its callbacks raised an error). The act, aim, attack and keys tables and input.press / down / up / hold / release_all exist only when the script declares act and this exact source version is approved: test act ~= nil. Deny in Action approvals is saved: that version is not offered again, also after a restart, until the file changes. Allowing insecure FFI stops a running action script. Script panic (Stop script actions on the Scripts page) releases everything and refuses "panic" until reset; the app panic key latches it too, but only while that key also unloads (set, and no other bind uses it).

Returns
  • table
Example
Lua
local status = act.status()