xhookLua
Game

world

Players, NPCs, entities, round state, screen projection, traces, autowall and dynamic lights; traces work in on_paint and on_create_move.

Functions

world.get_player

world.get_player(index) -> Entity | nil
NameTypeDescription
indexinteger1 to engine.max_players().

Connected player by slot.

nil for empty or non-player slots.

world.get_players

world.get_players([enemies_only]) -> Entity[]
NameTypeDescription
enemies_onlyoptionalbooleantrue skips your team. Default false.

Connected players except you, as an array.

enemies_only compares team numbers; empty when all share a team.

world.get_entities

world.get_entities([model_filter]) -> Entity[]
NameTypeDescription
model_filteroptionalstringCase-sensitive model path substring, like "w_c4".

Non-player entities with models: grenades, weapons, C4, hostages, NPCs, brushes.

Empty table when not in game.

world.get_entity

world.get_entity(index) -> Entity | nil
NameType
indexinteger

Any live entity by index.

nil if out of range, free or dead.

world.get_npcs

world.get_npcs([enemies_only]) -> Entity[]
NameTypeDescription
enemies_onlyoptionalbooleantrue drops friendly NPCs. Default false.

NPCs the aim and ESP target, including recently unseen ones.

Empty when not in game.

world.bomb

world.bomb() -> table

The bomb (Counter-Strike).

Returns {state, planted, defused, position, in_view, carrier, plant_time, time_left, total, defuser, defuse_progress, damage}, nil when there is none

  • state: "carried", "dropped", "planted" or "defused".
  • position: the bomb when in view, else its radar spot, else the carrier.
  • defuser / defuse_progress are a guess: the game does not send them.
  • damage: to you from where you stand, armor ignored.
  • A dropped bomb's radar spot only reaches terrorists.

world.grenades

world.grenades() -> table[]

Live grenades in view.

Returns {index, type, position, velocity, fuse, land, land_time} each

  • type: "he", "flash", "smoke" (Counter-Strike).
  • fuse: seconds left, nil for smoke. land / land_time: where its flight ends and when.

world.predict_grenade

world.predict_grenade([position, velocity [, fuse]]) -> table
NameTypeDescription
positionoptionalVector
velocityoptionalVector
fuseoptionalnumberStop the path here (HE / flash: 1.5). Default until it rests.

The toss path with its bounces. No arguments: the grenade in your hand.

Returns {points, land, time} | nil

world.local_throw

world.local_throw() -> table

How the grenade in your hand would leave if you threw it now.

Returns {position, velocity, fuse} | nil when you hold none

world.round_time

world.round_time() -> number

HUD round timer, seconds left; correct when loaded mid-round.

0 when unknown; never negative.

world.world_to_screen

world.world_to_screen(pos) -> number, number | nil
NameType
posVector

Projects a world point to the screen.

Returns x, y in pixels, or nil

One nil when behind the camera or off screen.

world.box_to_screen

world.box_to_screen(mins, maxs) -> number, number, number, number | nil
NameTypeDescription
minsVectorMinimum corner.
maxsVectorMaximum corner.

Screen rect around an axis-aligned world box, for 2D ESP.

Returns x, y, w, h pixels, or nil

nil unless all eight corners project.

world.trace_line

world.trace_line(start, end [, mask [, ignore]]) -> trace | nil
NameTypeDescription
startVector
endVector
maskoptionalintegerworld.MASK_* flags, combined with |. Default world.MASK_NORMAL.
ignoreoptionalEntity | integerEntity or index to pass through. Default nil (ignore nothing).

Point trace against world, brush entities and players; never hits you.

Returns Result table (see fields), or nil.

nil without the engine trace interface.

world.trace_hull

world.trace_hull(start, end [, hull [, mask [, ignore]]]) -> trace | nil
NameTypeDescription
startVectorHull centre.
endVector
hulloptionalintegerHULL_* or 3 (large), clamped. Default world.HULL_REGULAR.
maskoptionalintegerworld.MASK_* flags. Default world.MASK_NORMAL.
ignoreoptionalEntity | integerEntity or index to pass through. Default nil.

Sweeps a player hull, to test fit or landing spots.

Returns Result table (see fields), or nil.

Never hits you; nil without the trace interface.

world.is_visible

world.is_visible(from, to [, ignore]) -> boolean, Vector
NameTypeDescription
fromVectorEye or start position.
toVector
ignoreoptionalEntity | integerTarget entity, so it doesn't block. Default nil.

Line of sight ignoring glass; visible past 99% of the distance.

Returns visible, and where the trace stopped

Returns false and to without the trace interface.

world.trace_bullet

world.trace_bullet(from, to) -> number
NameTypeDescription
fromVectorShot origin, usually your eye.
toVectorImpact point.

Autowall: bullet damage with wall penetration and distance falloff.

Returns Damage at to, 0 if blocked.

  • Uses your held weapon's stats; 0 when not in game.
  • Ignores armour and hitgroup multipliers.

world.dlight

world.dlight(origin, radius, r, g, b [, life [, decay [, elight [, key]]]])
NameTypeDescription
originVector
radiusnumberWorld units.
rnumber0 to 255, clamped.
gnumber0 to 255, clamped.
bnumber0 to 255, clamped.
lifeoptionalnumberPulse seconds, min 0.01. Default 0.1.
decayoptionalnumberRadius shrink per second. Default 0.
elightoptionalbooleantrue lights only models. Default false.
keyoptionalinteger0 takes any free slot; else reused. Default 0.

Spawns a short-lived engine dynamic light; call every frame to keep it.

  • Give moving lights their own key (like 1000 + i) to avoid stacking.
  • Does nothing out of game or with no free slot.

world.map_entities

world.map_entities([classname]) -> table[]
NameTypeDescription
classnameoptionalstringExact name, or a prefix ending in * like "func_*".

Entities the map spawns with, read from the map file.

Returns {classname, origin, angles, targetname, model, index, keys}

  • Cached per map. Players and dropped weapons are not in it.
  • keys has every key/value as strings; brush entities without origin get their brush centre.

Fields

world.trace_line() / world.trace_hull() result table

NameTypeDescription
fractionnumber0 to 1 of the path covered; 1 = no hit.
hitbooleanfraction < 1.
endposVectorWhere the trace stopped.
normalVectorHit plane normal.
plane_distnumberHit plane distance from origin.
allsolidbooleanEntire trace inside solid.
startsolidbooleanStart point inside solid.
in_openbooleanPassed through empty space.
in_waterbooleanPassed through water.
hitgroupintegerBody part hit; 0 for non-hitbox.
ent_indexintegerEntity hit, 0 = world.
entityEntityHit entity; only for tracked live entities.

Constants

NameValueDescription
world.HULL_REGULAR0Standing hull, 32x32x72.
world.HULL_DUCKED1Ducked hull, 32x32x36.
world.HULL_POINT2Zero-size; trace_line always uses it.
world.MASK_NORMAL0Hits world, brush entities, players.
world.MASK_STUDIO_IGNORE1Skips studio models.
world.MASK_STUDIO_BOX2Bounding boxes instead of hitboxes.
world.MASK_GLASS_IGNORE4Ignores glass and see-through render modes.
world.MASK_WORLD8World only.
world ยท Lua API ยท xhook