3
0
Ответвление 0
Этот коммит содержится в:
Afireal 2025-03-30 15:13:32 +05:00
родитель ada6371905
коммит e6bb13bda0
3 изменённых файлов: 27 добавлений и 16 удалений

Просмотреть файл

@ -42,12 +42,21 @@ end
function permanent.Remove(id) function permanent.Remove(id)
print("permanent.Remove", id)
assert(isstring(id), "invalid index") assert(isstring(id), "invalid index")
print(cache[id])
cache[id] = nil cache[id] = nil
print(cache[id])
end end
hook.Add("ShutDown", "Permanent", function()
permanent.Push()
end)
hook.Add("PostGamemodeLoaded", "Permanent", function() hook.Add("PostGamemodeLoaded", "Permanent", function()
currentMap = game.GetMap() currentMap = game.GetMap()

Просмотреть файл

@ -14,10 +14,12 @@ local Entity = FindMetaTable("Entity")
function Entity:MakePermanent(id, steamid) function Entity:MakePermanent(id, steamid)
if !IsValid(self) then return end 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 = {} local tbl = {}
tbl.class = self:GetClass() tbl.class = self:GetClass()
tbl.creator = steamid or ""
tbl.time = os.time()
tbl.pos = self:GetPos() tbl.pos = self:GetPos()
tbl.ang = self:GetAngles() tbl.ang = self:GetAngles()
@ -34,12 +36,11 @@ function Entity:MakePermanent(id, steamid)
end end
id = isstirng(id) and id or tbl.class.."-"..os.time() id = id or tbl.class.."-"..tbl.time
tbl.creator = steamid or ""
permanent.Add(id, tbl) permanent.Add(id, tbl)
self:Remove() self:Remove()
permaents.Spawn(id) permanent.Spawn(id)
end end
@ -50,8 +51,10 @@ function permanent.Spawn(id)
local tbl = permanent.Get(id) local tbl = permanent.Get(id)
if !istable(tbl) then return end 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 if !IsValid(ent) then return end
ent:SetPos(tbl.pos)
ent:SetAngles(tbl.ang)
for k, v in pairs(tbl) do for k, v in pairs(tbl) do
@ -97,13 +100,13 @@ end
hook.Add("OnMakePermanent", "EntityBlacklist", function(ent) hook.Add("OnMakePermanent", "EntityBlacklist", function(ent)
if self:IsPlayer() || if ent:IsPlayer() ||
self:IsNPC() || ent:IsNPC() ||
self:IsNextBot() || ent:IsNextBot() ||
self:IsRagdoll() || ent:IsRagdoll() ||
self:IsWeapon() || ent:IsWeapon() ||
self:IsVehicle() || ent:IsVehicle() ||
self:IsWorld() ent:IsWorld()
then return false end then return false end
end) end)

Просмотреть файл

@ -12,7 +12,7 @@ function TOOL:LeftClick(tr)
if !IsValid(tr.Entity) then return end if !IsValid(tr.Entity) then return end
if tr.Entity:IsWorld() || tr.Entity:CreatedByMap() 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()) tr.Entity:MakePermanent(id, ply:SteamID())
return true return true
@ -31,7 +31,7 @@ function TOOL:RightClick(tr)
if tr.Entity:IsWorld() || tr.Entity:CreatedByMap() then return end if tr.Entity:IsWorld() || tr.Entity:CreatedByMap() then return end
if !tr.Entity:GetNWBool("IsPermanent") 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) permanent.Remove(id)
tr.Entity:Remove() tr.Entity:Remove()
@ -74,7 +74,6 @@ function TOOL:DrawHUD()
end 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("Permanent.ID"), "GModNotify", x, y + 16, 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)
end end