From 5ee8eb4a2b96b4a9916f85ddec5b43ae24ca93d1 Mon Sep 17 00:00:00 2001 From: salmonik Date: Tue, 3 Nov 2026 23:36:58 +0100 Subject: AI: treat scripted NPCs as neutral; Lamarr neutral Read the server m_NPCState and mark NPC_STATE_SCRIPT actors neutral so cutscene NPCs and scripted pets are not aimbot targets and draw in the neutral colour. Add Lamarr (Kleiner's pet headcrab) to the neutral model list as requested. Also log state changes in the NPC debug line and resolve/log m_NPCState in the server datamap summary. --- src/server.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/server.cpp') diff --git a/src/server.cpp b/src/server.cpp index 19be144..c2864c8 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -50,6 +50,7 @@ static int g_srv_relationship = -1; static int g_srv_followtarget = -1; static int g_srv_spawnflags = -1; static int g_srv_hacked = -1; +static int g_srv_npcstate = -1; static bool g_srv_ready = false; static bool g_srv_checked = false; @@ -139,15 +140,16 @@ bool resolve_server_netvars() { // CBaseEntity::m_spawnflags is a DEFINE_KEYFIELD at a low offset. g_srv_spawnflags = datamap_offset("m_spawnflags", FIELD_INTEGER, 0x4); g_srv_hacked = datamap_offset("m_bHackedByAlyx", FIELD_BOOLEAN); + g_srv_npcstate = datamap_offset("m_NPCState", FIELD_INTEGER); g_srv_ready = g_srv_health > 0; if (g_srv_ready) { logf("server datamap (%s): health=%d maxhealth=%d lifeste=%d " "modelindex=%d absvel=%d vel=%d activeweapon=%d relationship=%d " - "followtarget=%d spawnflags=%d hacked=%d", + "followtarget=%d spawnflags=%d hacked=%d npcstate=%d", g_server.path.c_str(), g_srv_health, g_srv_maxhealth, g_srv_lifestate, g_srv_modelindex, g_srv_absvelocity, g_srv_velocity, g_srv_activeweapon, g_srv_relationship, g_srv_followtarget, - g_srv_spawnflags, g_srv_hacked); + g_srv_spawnflags, g_srv_hacked, g_srv_npcstate); fail_logged = false; } else if (!fail_logged) { fail_logged = true; @@ -254,6 +256,18 @@ int server_npc_relation(int idx, int local_idx) { return class_relation; } +// NPC_STATE_SCRIPT = 4 (ai_npcstate.h). Scripted NPCs are passive: cutscene +// actors, Kleiner's Lamarr, scripted soldiers standing down, and so on. +int server_npc_state(int idx) { + if (!g_srv_ready || g_srv_npcstate < 0) + return -1; + void *base = nullptr; + server_entity_health(idx, nullptr, nullptr, &base); + if (!base) + return -1; + return *(int *)((uintptr_t)base + g_srv_npcstate); +} + bool server_npc_has_follow_target(int idx) { if (!g_srv_ready || g_srv_followtarget < 0) return false; -- cgit v1.2.3