Game state

Entities and world

Find players and entities, read their fields and trace through the world.

Two entity APIs share the same objects. With entity.* a field is its value (pawn.m_iHealth, pawn.m_iHealth = 100 writes it). With entities.* a field is an accessor (pawn.m_iHealth:get(), :set(v), :get_as("uint8")). Any schema field of the entity's class or of its parent classes works; the type comes from the game's schema (numbers, bool, vectors, colors, handles, handle lists, strings, pointers and embedded structures).

FunctionParametersReturnsDescription
entity.get_local_player()pawn or nilAlso entity.get_local_player_or_spec(), entity.get_local_controller().
entity.players:for_each(fn)fn(pawn)noneentity.controllers, entity.weapons, entity.projectiles; list:get_all() returns an array.
entity.get_by_index(i)entity or nilget_by_handle(h), get_all(class), from_address(addr, class)
entities.players:for_each(fn)fn(entry)noneentry.entity, entry.handle. Lists: players, controllers, items, dropped_items, projectiles, all. for_each_z goes far to near.
entities.get_local_pawn()entity or nilget_local_controller(), get_by_class(name), list(kind)

Methods on every entity: get_address, get_class_name, get_name, get_health, get_team, is_alive, is_enemy, is_local, is_dormant, get_abs_origin, get_abs_angles, get_speed_vector, get_eye_pos, get_eye_angles, get_view_offset, get_bone_position(bone), get_hitbox_center(hitbox), get_bounding_box() (screen Rect), get_collision_bounds(), get_controller, get_pawn, get_active_weapon, get_weapons, get_observer_target, get_observer_mode, get_steam_id, get_string_steam_id, is_scoped, get_armor, get_flags, is_on_ground, get_prop(name), set_prop(name, v), cast(class). Weapons: get_def_index, get_data, get_type, get_clip, get_max_clip, get_max_speed, is_gun.

FunctionParametersReturnsDescription
trace.line(from, to, opts?)opts.ignore: entityresult or nilIgnores the local player by default. Result: hit, fraction, entity, normal, position, end_pos, start_in_solid.
trace.hull(from, to, mins?, maxs?)result or nilPlayer hull when mins and maxs are omitted.
luna.local_state()tableLocal player movement state: origin, speed_vector, speed, on_ground, flags, move_type, health, duck_amount, max_speed, ...
game.engine:in_game()boolAlso client_cmd(cmd), get_screen_size(), get_last_server_tick().
game.global_vars.cur_timenumberreal_time, frame_time, tick_count, frame_count, map_name
game.cvar:find(name)ConVar or nilget_float, get_int, get_bool, get_string, set_float, set_int, set_bool, .value. Shortcuts: cvar.get_float(name), ...
globals.curtime()numberrealtime, frametime, tickcount, tickinterval, framecount, mapname, fps
game.exec(command)boolRuns a console command. game.chat_print(text), game.play_sound(path)