Reading & Writing Netprops
Access Source engine networked properties (netprops) via direct field lookups on entity objects.
Direct Property Lookups
Section titled “Direct Property Lookups”Fields not defined as built-in API methods resolve directly against the entity’s receive tables:
local me = entity.get_local_player()if not me then return end
-- Read netpropslocal health = me.m_iHealthlocal origin = me.m_vecOriginlocal flags = me.m_fFlags
-- Modify netpropsme.m_flFlashDuration = 0Resolution Rules
Section titled “Resolution Rules”- Short Property Names: Use bare names (e.g.
m_iHealth, notDT_BasePlayer.m_iHealth). - Recursive Lookup: Traverses nested datatables automatically.
- Invalid Properties: Non-existent properties return
nil. Writing to invalid properties is ignored.
Type Conversions
Section titled “Type Conversions”| Source Data Type | Lua Type | Notes |
|---|---|---|
int, short, byte, char |
number |
Packed integers are unpacked automatically. |
float |
number |
Single precision float. |
Vector |
vector |
vector(x, y, z) |
QAngle |
qangle |
qangle(pitch, yaw, roll) |
string / char* |
string |
Null-terminated string. |
EHANDLE |
number |
Entity handle (pass to entity.from_handle). |
| Array / Datatable | Array Wrapper | 0-based memory wrapper. |
Netprop Arrays
Section titled “Netprop Arrays”Netprop arrays return 0-based memory wrappers:
Example: Reading Weapons Inventory
Section titled “Example: Reading Weapons Inventory”local me = entity.get_local_player()if not me then return end
-- m_hMyWeapons is a 64-element handle arraylocal weapons = me.m_hMyWeapons
for i = 0, 63 do local handle = weapons[i] if handle == -1 or handle == 0xFFFFFFFF then break end
local weapon = entity.from_handle(handle) if weapon then print(string.format("Slot %d: %s", i, weapon:get_classname())) endendExample: Player Resource Table
Section titled “Example: Player Resource Table”local res = entity.get_player_resource()if res then for i = 1, globals.max_players do local kills = res.m_iKills[i] local deaths = res.m_iDeaths[i] local ping = res.m_iPing[i] endend