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

Game, entities and players

The match, players, the local player and the constants that go with them.

game

Match state, the drawn camera and world-to-screen projection, CS2 frame and network stats. Read-only.

16 entriesAllow game scripting

Everything here needs Allow game scripting in Scripts > Security (on by default).

game.connected

function
game.connected() -> boolean

True while in a match (the snapshot is valid).

Returns
  • boolean
Example
Lua
if not game.connected() then return end

game.map

function
game.map() -> string

The current map ("" when not in game).

Returns
  • string
Example
Lua
log.info(game.map())

game.curtime

function
game.curtime() -> number

Game time in seconds.

Returns
  • number
Example
Lua
local t = game.curtime()

game.tickcount

function
game.tickcount() -> integer

Game tick count.

Returns
  • integer
Example
Lua
local t = game.tickcount()

game.fps

function
game.fps() -> number | nil

CS2's frame rate over the last second (its frame counter), not the overlay's (time.fps). nil when not in game or not measured yet.

Returns
  • number | nil
Example
Lua
local f = game.fps()

game.frametime_var

function
game.frametime_var() -> number | nil

Standard deviation of CS2's frame time over the last second, in ms (net_graph's var). nil when not in game or not measured yet.

Returns
  • number | nil
Example
Lua
local var = game.frametime_var()

game.net

function
game.net() -> table | nil

The net channel as net_graph showed it: {loss = percent, choke = percent (incoming), sv_ms = the server's frame time, sv_var_ms = its standard deviation}. nil when not connected or not readable.

Returns
  • table | nil
Example
Lua
local n = game.net() if n then log.info(n.loss .. "% loss") end

game.camera

function
game.camera() -> table | nil

The drawn camera: {origin = vec3, angles = vec3, fov = number}.

Returns
  • table | nil
Example
Lua
local cam = game.camera()

game.view_matrix

function
game.view_matrix() -> number[] | nil

The camera's 4x4 view-projection matrix, 16 numbers row-major (the one world_to_screen uses: the drawn camera in paint, the refreshed one in tick / events).

Returns
  • number[] | nil
Example
Lua
local m = game.view_matrix() local w = m[13] * x + m[14] * y + m[15] * z + m[16]

game.freeze_period

function
game.freeze_period() -> boolean | nil

True in freezetime or the team intro (C_CSGameRules, as of the last drawn frame). nil when not in game or not read yet.

Returns
  • boolean | nil
Example
Lua
if game.freeze_period() then return end

game.binding

function
game.binding(command) -> table | nil

CS2's key bindings of a command (read from cs2 every 2 s): {keys = CS2 key names, vks = virtual keys (for input.is_down), vk = the key the native features use (keyboard first) | nil, wheel = -1 / 1 bound to the wheel down / up else 0, live = false while cs2's table is unreadable (then its default key)}. Commands: "+reload", "+lookatweapon" (inspect), "+use", "+jump", "+duck", "+sprint" (walk), "+attack", "+attack2", "+forward", "+back", "+left", "+right", "drop", "slot1".."slot10", "lastinv", "invnext", "invprev", "buymenu", "+showscores", "+spray_menu", "+radialradio", ... (as typed in a bind, case-insensitive). nil when not in game.

Arguments
NameTypeDescription
commandstring
Returns
  • table | nil
Example
Lua
local b = game.binding("+reload") if b and b.vk then log.info(input.key_name(b.vk)) end

game.action_down

function
game.action_down(command) -> boolean | nil

A key bound to the command is held now (wheel binds never are). false while a menu text field has focus; nil when not in game.

Arguments
NameTypeDescription
commandstring
Returns
  • boolean | nil
Example
Lua
if game.action_down("+lookatweapon") then end

game.ffa

function
game.ffa() -> boolean

Free for all (mp_teammates_are_enemies).

Returns
  • boolean
Example
Lua
if game.ffa() then end

game.damage_scale

function
game.damage_scale() -> table | nil

The server's damage scales: {ct_head, t_head, ct_body, t_body} (mp_damage_scale_*).

Returns
  • table | nil
Example
Lua
local ds = game.damage_scale()

game.world_to_screen

function
game.world_to_screen(pos) -> number, number | nil

Projects a world point with the drawn camera (the one the ESP uses).

Arguments
NameTypeDescription
posvec3
Returns
  • number, number | nil
Example
Lua
local x, y = game.world_to_screen(p.origin)

game.screen_size

function
game.screen_size() -> number, number

Overlay size in pixels.

Returns
  • number, number
Example
Lua
local w, h = game.screen_size()

entities

Players, the local player, grenades, dropped weapons, the C4 and spectators. Read-only.

8 entriesAllow game scripting

Everything here needs Allow game scripting in Scripts > Security (on by default).

entities.local_player

function
entities.local_player() -> LocalPlayer | nil

The local player (valid for this frame).

Returns
  • LocalPlayer | nil
Example
Lua
local me = entities.local_player()

entities.players

function
entities.players([filter]) -> Player[]

Listed players, far to near. filter: "enemies", "teammates", "alive" or nil (all). Dormant players are not listed.

Arguments
NameTypeDescription
filteroptionalstring
Returns
  • Player[]
Example
Lua
for _, p in ipairs(entities.players("enemies")) do end

entities.player

function
entities.player(index) -> Player | nil

The listed player with this controller index.

Arguments
NameTypeDescription
indexinteger
Returns
  • Player | nil
Example
Lua
local p = entities.player(3)

entities.projectiles

function
entities.projectiles() -> table[]

Grenades in flight / burning: {kind = "he"|"flash"|"smoke"|"molotov"|"inferno"|"decoy", index, origin, velocity, center (smoke cloud / fire centre), remaining, detonated, active, thrower, spawn_time, detonate_time, expire_time, lifetime (inferno, else -1), fire_points = vec3[] (inferno only)}. Times are game.curtime() seconds.

Returns
  • table[]
Example
Lua
for _, g in ipairs(entities.projectiles()) do end

entities.items

function
entities.items() -> table[]

Dropped weapons: {index (entity, for scene.item), name, origin, ammo}.

Returns
  • table[]
Example
Lua
for _, it in ipairs(entities.items()) do end

entities.bomb

function
entities.bomb() -> table | nil

The C4: {carried, carrier = index (carried only), planted, ticking, time_left, defuse_left, being_defused, site, origin, blow_time, timer_length, defuse_length}.

Returns
  • table | nil
Example
Lua
local b = entities.bomb()

entities.dormant

function
entities.dormant() -> table[]

Alive players out of the PVS (not in entities.players) that were listed while a game script ran (others are left out): {index, name, team, is_enemy, origin = last listed position, since = seconds since then}.

Returns
  • table[]
Example
Lua
for _, d in ipairs(entities.dormant()) do end

entities.spectators

function
entities.spectators() -> table[]

Spectators: {name, mode, watching_local}.

Returns
  • table[]
Example
Lua
for _, s in ipairs(entities.spectators()) do end

Player

A listed player (entities.players / entities.player). Valid only for the frame it was listed in.

46 entriesAllow game scripting

Everything here needs Allow game scripting in Scripts > Security (on by default).

Player.index

field

Controller entity index.

Returns
  • integer

Player.name

field

Player name.

Returns
  • string

Player.steam_id

field

SteamID64 as a string.

Returns
  • string

Player.team

field

2 = T, 3 = CT.

Returns
  • integer

Player.health

field

Health 0..100.

Returns
  • integer

Player.armor

field

Armor 0..100.

Returns
  • integer

Player.money

field

Money.

Returns
  • integer

Player.ping

field

Ping in ms.

Returns
  • integer

Player.alive

field

Health above 0.

Returns
  • boolean

Player.is_enemy

field

On the other team (or anyone in FFA).

Returns
  • boolean

Player.is_local

field

The local player.

Returns
  • boolean

Player.on_ground

field

Standing on the ground.

Returns
  • boolean

Player.ducked

field

Crouching.

Returns
  • boolean

Player.scoped

field

Scoped in.

Returns
  • boolean

Player.defusing

field

Defusing the bomb.

Returns
  • boolean

Player.flashed

field

Flashed.

Returns
  • boolean

Player.immune

field

Spawn protected.

Returns
  • boolean

Player.helmet

field

Has a helmet.

Returns
  • boolean

Player.defuser

field

Has a defuse kit.

Returns
  • boolean

Player.spotted

field

Spotted by anyone on the radar.

Returns
  • boolean

Player.visible

field

The game's radar spotted bit for the local player (m_bSpottedByMask), not a line of sight: Player:is_visible() traces the map.

Returns
  • boolean

Player.spotted_by

field

Controller indices of the players who spot this one (the radar mask).

Returns
  • integer[]

Player.last_sound

field

game.curtime() of the last sound others hear (footsteps, landing, ...; m_flEmitSoundTime). See the player_sound event.

Returns
  • number

Player.last_fired

field

game.curtime() of the last shot (m_flLastFiredWeaponTime). See the weapon_fire event.

Returns
  • number

Player.sim_time

field

Simulation time of the last update the client got (m_flSimulationTime).

Returns
  • number

Player.hitbox_count

field

Number of hitbox capsules (Player:hitbox / Player:capsule take 1..hitbox_count).

Returns
  • integer

Player.distance

field

Distance to the camera in units.

Returns
  • number

Player.origin

field

Feet position.

Returns
  • vec3

Player.eye_pos

field

Eye position.

Returns
  • vec3

Player.view_angles

field

Pitch, yaw, roll in degrees.

Returns
  • vec3

Player.velocity

field

Velocity in units/s.

Returns
  • vec3

Player.center

field

Body centre.

Returns
  • vec3

Player.mins

field

Collision box minimum (relative).

Returns
  • vec3

Player.maxs

field

Collision box maximum (relative).

Returns
  • vec3

Player.weapon

field

{name = "ak47", type = weapon_type.*, ammo, max_ammo, reloading, item_def, full_auto, damage, armor_ratio, headshot_mult, range, range_modifier, recoil_index, next_attack_tick}.

Returns
  • table

Player:bone

method
Player:bone(id) -> number, number, number | nil

World position of a bone (bone.head, bone.pelvis, ...).

Arguments
NameTypeDescription
idinteger
Returns
  • number, number, number | nil
Example
Lua
local x, y, z = p:bone(bone.head)

Player:bone_screen

method
Player:bone_screen(id) -> number, number | nil

Screen position of a bone.

Arguments
NameTypeDescription
idinteger
Returns
  • number, number | nil
Example
Lua
local x, y = p:bone_screen(bone.head)

Player:bone_rot

method
Player:bone_rot(id) -> number, number, number, number | nil

World rotation of a bone as a quaternion x, y, z, w.

Arguments
NameTypeDescription
idinteger
Returns
  • number, number, number, number | nil
Example
Lua
local qx, qy, qz, qw = p:bone_rot(bone.head)

Player:hitbox

method
Player:hitbox(i) -> table | nil

Hitbox capsule i (1-based, as aim and trigger use them): {index, a = vec3, b = vec3, radius, group = hitgroup.*, bone, name}.

Arguments
NameTypeDescription
iinteger
Returns
  • table | nil
Example
Lua
local h = p:hitbox(1)

Player:hitboxes

method
Player:hitboxes() -> table[]

Every hitbox capsule (as Player:hitbox). Built once per player per logic pass and shared by the calls in it: do not modify it.

Returns
  • table[]
Example
Lua
for _, h in ipairs(p:hitboxes()) do end

Player:capsule

method
Player:capsule(i) -> number, number, number, number, number, number, number, integer | nil

Hitbox capsule i as plain numbers ax, ay, az, bx, by, bz, radius, group: no tables, so the cheap way to walk every capsule of every player each frame (Player:hitboxes costs ~0.8 us a capsule).

Arguments
NameTypeDescription
iinteger
Returns
  • number, number, number, number, number, number, number, integer | nil
Example
Lua
for i = 1, p.hitbox_count do local ax, ay, az, bx, by, bz, r = p:capsule(i) end

Player:is_visible

method
Player:is_visible() -> boolean | nil, string

Map line of sight from the eye to the head, chest, pelvis, hands or feet (the ESP's visibility check, cached per frame). Without a loaded map or with the trace off it is the spotted bit. Counts as one world ray; nil, "ray budget" past the cap.

Returns
  • boolean | nil, string
Example
Lua
if p:is_visible() then end

Player:unseen_ms

method
Player:unseen_ms() -> integer | nil

ms since a visibility check last found this player visible (the ESP's, aim's or this script's is_visible); nil when never.

Returns
  • integer | nil
Example
Lua
if (p:unseen_ms() or 1e9) < 500 then end

Player:box

method
Player:box() -> number, number, number, number | nil

Screen box x1, y1, x2, y2 (the ESP's box).

Returns
  • number, number, number, number | nil
Example
Lua
local x1, y1, x2, y2 = p:box()

Player:screen

method
Player:screen() -> number, number | nil

Screen position of the feet.

Returns
  • number, number | nil
Example
Lua
local x, y = p:screen()

Player:set_material

methodAllow custom shaders
Player:set_material(m [, opts]) -> boolean

Draw this player with m instead of the configured chams (also when chams are off for it) for 1 s, or opts.lease seconds (at most 3600): renew it (each tick) to keep it. nil clears. Needs "Allow custom shaders" (and game).

Arguments
NameTypeDescription
mMaterial | nil
optsoptionaltable
Returns
  • boolean

Needs Allow custom shaders in Scripts > Security (off by default).

Example
Lua
for _, p in ipairs(entities.players()) do if p.is_enemy then p:set_material(holo) end end

LocalPlayer

The local player (entities.local_player()).

24 entriesAllow game scripting

Everything here needs Allow game scripting in Scripts > Security (on by default).

LocalPlayer.alive

field

Alive.

Returns
  • boolean

LocalPlayer.team

field

Team.

Returns
  • integer

LocalPlayer.view_team

field

Team of the spectated player while dead.

Returns
  • integer

LocalPlayer.health

field

Health.

Returns
  • integer

LocalPlayer.armor

field

Armor.

Returns
  • integer

LocalPlayer.on_ground

field

On the ground.

Returns
  • boolean

LocalPlayer.flash_alpha

field

Flash overlay 0..255.

Returns
  • number

LocalPlayer.shots_fired

field

Shots in the current spray.

Returns
  • integer

LocalPlayer.origin

field

Feet position.

Returns
  • vec3

LocalPlayer.eye_pos

field

Eye position.

Returns
  • vec3

LocalPlayer.view_angles

field

View angles.

Returns
  • vec3

LocalPlayer.velocity

field

Velocity.

Returns
  • vec3

LocalPlayer.aim_punch

field

Aim punch angles.

Returns
  • vec3

LocalPlayer.weapon

field

Active weapon (as Player.weapon).

Returns
  • table

LocalPlayer.observer_mode

field

Observer mode while dead (2 = first person, 3 = chase, 4 = roaming), 0 alive.

Returns
  • integer

LocalPlayer.spectating

field

Controller index of the listed player we spectate while dead.

Returns
  • integer | nil

LocalPlayer.controlling_bot

field

Controlling a bot (takeover).

Returns
  • boolean

LocalPlayer.crosshair_id

field

Entity index under the crosshair (m_iIDEntIndex), 0 or -1 for none.

Returns
  • integer

LocalPlayer.tick_base

field

The controller's tick base.

Returns
  • integer

LocalPlayer.next_attack

field

game.curtime() the pawn may attack again.

Returns
  • number

LocalPlayer.fov_sens_adjust

field

Mouse sensitivity factor of the current zoom (m_flFOVSensitivityAdjust).

Returns
  • number

LocalPlayer.flags

field

Pawn flags (bit 0 = on ground).

Returns
  • integer

LocalPlayer.index

field

Controller index.

Returns
  • integer | nil

LocalPlayer.name

field

Name.

Returns
  • string | nil

bone

Bone ids for Player:bone and Player:bone_screen.

1 entry

bone.head

constantAllow game scripting

Bone ids: origin, pelvis, spine_0..3, neck, head, clavicle_l/r, shoulder_l/r, elbow_l/r, hand_l/r, hip_l/r, knee_l/r, foot_l/r, chest.

Returns
  • integer

Needs Allow game scripting in Scripts > Security (on by default).

Example
Lua
p:bone_screen(bone.head)

hitgroup

Hitgroup ids (head, chest, ...) for world.penetration and the combat.* states.

1 entry

hitgroup.head

constantAllow game scripting

Hitgroups: generic, head, chest, stomach, left_arm, right_arm, left_leg, right_leg, neck.

Returns
  • integer

Needs Allow game scripting in Scripts > Security (on by default).

Example
Lua
if e.hitgroup == hitgroup.head then end

weapon_type

Weapon type ids (Player.weapon.type).

1 entry

weapon_type.rifle

constantAllow game scripting

Weapon types: knife, pistol, smg, rifle, shotgun, sniper, lmg, c4, taser, grenade, equipment, healthshot.

Returns
  • integer

Needs Allow game scripting in Scripts > Security (on by default).

Example
Lua
if p.weapon.type == weapon_type.sniper then end