From 547146dbf101557497c260ac5dd36cdbc499fb1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B0=D0=BB=D0=B0=D0=B2=D0=B0=D1=82=20=D0=A2=D0=B0?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2?= <91839650+relaxtakenotes@users.noreply.github.com> Date: Thu, 9 Nov 2023 11:38:03 +0500 Subject: [PATCH] handle missing physics gracefully (#114) --- .../beatrun/gamemode/sh/BuildMode.lua | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/beatrun/gamemodes/beatrun/gamemode/sh/BuildMode.lua b/beatrun/gamemodes/beatrun/gamemode/sh/BuildMode.lua index b12d21d..ace38af 100644 --- a/beatrun/gamemodes/beatrun/gamemode/sh/BuildMode.lua +++ b/beatrun/gamemodes/beatrun/gamemode/sh/BuildMode.lua @@ -619,8 +619,10 @@ if SERVER then a:Spawn() local phys = a:GetPhysicsObject() - phys:EnableMotion(false) - phys:Sleep() + if IsValid(phys) then + phys:EnableMotion(false) + phys:Sleep() + end a:PhysicsDestroy() a:SetHealth(inf) @@ -1404,14 +1406,19 @@ if CLIENT then if bind ~= "buildmode" and not camcontrol then return true end end - hook.Add("OnEntityCreated", "BuildModeProps", function(ent) - if not ent:GetNW2Bool("BRProtected") and ent:GetClass() == "prop_physics" or buildmode_ents[ent:GetClass()] then - if not BuildMode then ent.buildmode_placed_manually = true end - - table.insert(buildmode_placed, ent) - end + hook.Add("InitPostEntity", "buildmode_create_hook", function() + timer.Simple(2, function() + hook.Add("OnEntityCreated", "BuildModeProps", function(ent) + if not ent:GetNW2Bool("BRProtected") and ent:GetClass() == "prop_physics" or buildmode_ents[ent:GetClass()] then + if not BuildMode then ent.buildmode_placed_manually = true end + + table.insert(buildmode_placed, ent) + end + end) + end) end) + local dragorigin = nil function BuildModeDrag()