From d65d63b55c612532150391afdad0fc11532aedae Mon Sep 17 00:00:00 2001 From: Yahzy Date: Wed, 18 Nov 2026 21:53:38 +0100 Subject: [PATCH 1/2] Add Player:StripWeapons, Player:LagCompensation and Entity:MuzzleFlash Used by weapon_base, weapon_medkit and the sandbox weapons, which errored with 'attempt to call method ... (a nil value)'. --- Game.Shared/GarrysMod/LuaEntity.cs | 7 +++++++ Game.Shared/GarrysMod/LuaPlayer.cs | 26 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/Game.Shared/GarrysMod/LuaEntity.cs b/Game.Shared/GarrysMod/LuaEntity.cs index d0d1b4f0..d6f3149f 100644 --- a/Game.Shared/GarrysMod/LuaEntity.cs +++ b/Game.Shared/GarrysMod/LuaEntity.cs @@ -96,6 +96,13 @@ static int Entity__IsMarkedForDeletion(ILuaInterface lua) { return 1; } + [LuaMethod] + static int Entity__MuzzleFlash(ILuaInterface lua) { + BaseEntity ent = Get_Entity(1, false)!; + ent.GetBaseAnimating()?.DoMuzzleFlash(); + return 0; + } + [LuaMethod] static int Entity__Remove(ILuaInterface lua) { if (LuaEnts.IsRendering()) { diff --git a/Game.Shared/GarrysMod/LuaPlayer.cs b/Game.Shared/GarrysMod/LuaPlayer.cs index fcdfaa26..9a599b55 100644 --- a/Game.Shared/GarrysMod/LuaPlayer.cs +++ b/Game.Shared/GarrysMod/LuaPlayer.cs @@ -1,3 +1,4 @@ +using System.Runtime.CompilerServices; using Source; #if CLIENT_DLL || GAME_DLL @@ -601,6 +602,24 @@ static int Player__GetInfo(ILuaInterface lua) { #endif } + [LuaMethod] + static int Player__LagCompensation(ILuaInterface lua) { +#if GAME_DLL + BasePlayer player = Get_Player(1, false)!; + bool start = lua.GetBool(2); + + // Only meaningful while a user command is being processed (predicted hooks) + if (Unsafe.IsNullRef(ref player.GetCurrentUserCommand())) + return 0; + + if (start) + lagcompensation.StartLagCompensation(player); + else + lagcompensation.FinishLagCompensation(player); +#endif + return 0; + } + [LuaMethod] static int Player__GetInfoNum(ILuaInterface lua) { if (!LuaConVar.IsAllowedToGetConvarInfo(lua.GetString(2))) @@ -631,6 +650,13 @@ static int Player__RemoveAllAmmo(ILuaInterface lua) { return 0; } + [LuaMethod] + static int Player__StripWeapons(ILuaInterface lua) { + BasePlayer player = Get_Player(1, false)!; + player.RemoveAllWeapons(); + return 0; + } + [LuaMethod] static int Player__SelectWeapon(ILuaInterface lua) { BasePlayer player = Get_Player(1, false)!; From ab3004e689c03998b0529927b7a09deb3c077f05 Mon Sep 17 00:00:00 2001 From: Yahzy Date: Wed, 18 Nov 2026 22:00:54 +0100 Subject: [PATCH 2/2] Make Entity:IsNPC return the entity's real NPC state It always returned false, breaking addons and gamemodes that filter NPCs. --- Game.Shared/GarrysMod/LuaEntity.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Game.Shared/GarrysMod/LuaEntity.cs b/Game.Shared/GarrysMod/LuaEntity.cs index d6f3149f..8f51101e 100644 --- a/Game.Shared/GarrysMod/LuaEntity.cs +++ b/Game.Shared/GarrysMod/LuaEntity.cs @@ -1056,7 +1056,8 @@ static int Entity__IsPlayer(ILuaInterface lua) { [LuaMethod] static int Entity__IsNPC(ILuaInterface lua) { - lua.PushBool(false); + BaseEntity? ent = Get_Entity(1, true); + lua.PushBool(ent != null && ent.IsNPC()); return 1; }