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

World and combat

Map traces, smokes, grenades and combat.

world

The map: visibility and bullet traces against the collision mesh, wallbang damage, smokes, grenade arcs and the minimap. Read-only.

8 entriesAllow game scripting

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

world.ready

function
world.ready() -> boolean

True once the map's collision mesh is loaded (world_physics; props, doors, players and smoke do not block).

Returns
  • boolean
Example
Lua
if not world.ready() then return end

world.visible

function
world.visible(from, to) -> boolean | nil, string

No map triangle between the two points (the last 0.1 u at the target and the first 1 u at the start ignored). nil without a map; one world ray: nil, "ray budget" past 256 a logic pass.

Arguments
NameTypeDescription
fromvec3
tovec3
Returns
  • boolean | nil, string
Example
Lua
if world.visible(me.eye_pos, p.eye_pos) then end

world.trace

function
world.trace(from, to) -> table | nil, string

The first surface entered: {hit, pos, normal, dist, fraction 0..1, surface = material name}; hit = false (pos = to, fraction 1) when clear. nil without a map; one world ray.

Arguments
NameTypeDescription
fromvec3
tovec3
Returns
  • table | nil, string
Example
Lua
local t = world.trace(cam.origin, cam.origin + fwd * 4096)

world.penetration

function
world.penetration(from, to, target [, hitgroup]) -> table | nil, string

The local weapon's bullet through the map to target (the native wallbang model, after the target's armour): {ok, damage, walls, thickness, reason}. nil without a map; nil, "penetration budget" past 32 a logic pass.

Arguments
NameTypeDefaultDescription
fromvec3
tovec3
targetPlayer
hitgroupoptionalinteger1
Returns
  • table | nil, string
Example
Lua
local r = world.penetration(me.eye_pos, p:hitbox(1).a, p, hitgroup.head)

world.smokes

function
world.smokes() -> table[]

Active smokes as the world visuals model them: {center, radii = vec3, density 0..1}.

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

world.through_smoke

function
world.through_smoke(from, to) -> boolean | nil, string

The segment crosses an active smoke (the check aim and trigger use). One world ray.

Arguments
NameTypeDescription
fromvec3
tovec3
Returns
  • boolean | nil, string
Example
Lua
if world.through_smoke(me.eye_pos, p.eye_pos) then end

world.predict_grenade

function
world.predict_grenade(origin, velocity, kind [, remaining]) -> table | nil, string

A grenade arc as the native prediction simulates it (64 tick, bounces off the map mesh; free flight without one): {points = vec3[] per tick, bounces = vec3[], end_pos, duration seconds}. kind: "he", "flash", "smoke", "molotov", "incendiary", "decoy"; remaining = fuse seconds left (a grenade in flight). nil, "prediction budget" past 4 a logic pass.

Arguments
NameTypeDescription
originvec3
velocityvec3
kindstring
remainingoptionalnumber
Returns
  • table | nil, string
Example
Lua
local arc = world.predict_grenade(g.origin, g.velocity, g.kind, g.remaining)

world.overview

function
world.overview() -> table | nil

CS2's minimap for the map: {map, x, y = world of the image's top-left, scale = world units per pixel of the 1024 px image, has_lower, split_z, image, lower_image = draw.image ids}. Pixel (u, v) = ((wx - x) / scale, (y - wy) / scale). nil while loading (the first call starts it) or without one. The images count against the 4 images from memory a script holds.

Returns
  • table | nil
Example
Lua
local ov = world.overview() if ov then draw.image(ov.image, 0, 0, 256, 256) end

combat

What the native aim and trigger decided this logic pass. Read-only.

2 entriesAllow game scripting

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

combat.aim_state

function
combat.aim_state() -> table | nil

What the native aim decided this logic pass: {active (key held and allowed to aim), target = controller index | nil, hitbox, hitgroup, point, fov, damage, penetrated, sent (mouse moved), blocked = reason or ""}.

Returns
  • table | nil
Example
Lua
local a = combat.aim_state() if a and a.target then end

combat.trigger_state

function
combat.trigger_state() -> table | nil

What the native trigger decided this logic pass: {state ("key up", "holding", "fired", ...), target = controller index | nil, hitgroup, damage, fire_in_ms, hit_chance, fired, penetrated, reject, presses}.

Returns
  • table | nil
Example
Lua
local t = combat.trigger_state()