From e6bb13bda0b38d9e5b3607a3fadc46310106cf23 Mon Sep 17 00:00:00 2001 From: Afireal Date: Sun, 30 Mar 2025 15:13:32 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/permanent/sv_data.lua | 9 ++++++++ lua/permanent/sv_entity.lua | 27 ++++++++++++---------- lua/weapons/gmod_tool/stools/permanent.lua | 7 +++--- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/lua/permanent/sv_data.lua b/lua/permanent/sv_data.lua index dac05ac..0b7e16a 100644 --- a/lua/permanent/sv_data.lua +++ b/lua/permanent/sv_data.lua @@ -42,12 +42,21 @@ end function permanent.Remove(id) + print("permanent.Remove", id) assert(isstring(id), "invalid index") + print(cache[id]) cache[id] = nil + print(cache[id]) end +hook.Add("ShutDown", "Permanent", function() + + permanent.Push() + +end) + hook.Add("PostGamemodeLoaded", "Permanent", function() currentMap = game.GetMap() diff --git a/lua/permanent/sv_entity.lua b/lua/permanent/sv_entity.lua index bb0c435..39eb2ad 100644 --- a/lua/permanent/sv_entity.lua +++ b/lua/permanent/sv_entity.lua @@ -14,10 +14,12 @@ local Entity = FindMetaTable("Entity") function Entity:MakePermanent(id, steamid) if !IsValid(self) then return end - if hook.Add("OnMakePermanent", self, owner) == false then return end + if hook.Run("OnMakePermanent", self, owner) == false then return end local tbl = {} tbl.class = self:GetClass() + tbl.creator = steamid or "" + tbl.time = os.time() tbl.pos = self:GetPos() tbl.ang = self:GetAngles() @@ -34,12 +36,11 @@ function Entity:MakePermanent(id, steamid) end - id = isstirng(id) and id or tbl.class.."-"..os.time() - tbl.creator = steamid or "" + id = id or tbl.class.."-"..tbl.time permanent.Add(id, tbl) self:Remove() - permaents.Spawn(id) + permanent.Spawn(id) end @@ -50,8 +51,10 @@ function permanent.Spawn(id) local tbl = permanent.Get(id) if !istable(tbl) then return end - local ent = ents.Spawn(tbl.class, tbl.pos, tbl.ang, true) + local ent = ents.Create(tbl.class) if !IsValid(ent) then return end + ent:SetPos(tbl.pos) + ent:SetAngles(tbl.ang) for k, v in pairs(tbl) do @@ -97,13 +100,13 @@ end hook.Add("OnMakePermanent", "EntityBlacklist", function(ent) - if self:IsPlayer() || - self:IsNPC() || - self:IsNextBot() || - self:IsRagdoll() || - self:IsWeapon() || - self:IsVehicle() || - self:IsWorld() + if ent:IsPlayer() || + ent:IsNPC() || + ent:IsNextBot() || + ent:IsRagdoll() || + ent:IsWeapon() || + ent:IsVehicle() || + ent:IsWorld() then return false end end) diff --git a/lua/weapons/gmod_tool/stools/permanent.lua b/lua/weapons/gmod_tool/stools/permanent.lua index 8efcb9e..791b5b2 100644 --- a/lua/weapons/gmod_tool/stools/permanent.lua +++ b/lua/weapons/gmod_tool/stools/permanent.lua @@ -12,7 +12,7 @@ function TOOL:LeftClick(tr) if !IsValid(tr.Entity) then return end if tr.Entity:IsWorld() || tr.Entity:CreatedByMap() then return end - local id = tr.Entity:GetNWString("Permaents.ID", false) + local id = tr.Entity:GetNWString("Permanent.ID", false) tr.Entity:MakePermanent(id, ply:SteamID()) return true @@ -31,7 +31,7 @@ function TOOL:RightClick(tr) if tr.Entity:IsWorld() || tr.Entity:CreatedByMap() then return end if !tr.Entity:GetNWBool("IsPermanent") then return end - local id = tr.Entity:GetNWString("Permaents.ID") + local id = tr.Entity:GetNWString("Permanent.ID") permanent.Remove(id) tr.Entity:Remove() @@ -74,7 +74,6 @@ function TOOL:DrawHUD() end - draw.SimpleTextOutlined(trace.Entity:GetNWString("Permaents.ID"), "GModNotify", x, y, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, color_black) - draw.SimpleTextOutlined(trace.Entity:GetNWString("Permaents.Creator"), "GModNotify", x, y + 25, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, color_black) + draw.SimpleTextOutlined(trace.Entity:GetNWString("Permanent.ID"), "GModNotify", x, y + 16, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, color_black) end \ No newline at end of file