Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let server deinit chips when player leaves #1899

Merged
merged 2 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lua/entities/starfall_processor/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ end)
net.Receive("starfall_processor_kill", function()
local target = net.ReadEntity()
if IsValid(target) and target:GetClass()=="starfall_processor" then
target:Error({message = "Killed by admin", traceback = ""})
target:Error({message = "Killed", traceback = ""})
end
end)

Expand Down
21 changes: 15 additions & 6 deletions lua/starfall/instance.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,21 @@ SF.Instance.__index = SF.Instance
--- A set of all instances that have been created. It has weak keys and values.
-- Instances are put here after initialization.
SF.allInstances = {}
SF.playerInstances = SF.EntityTable("playerInstances", function(ply, instances)
for instance in pairs(instances) do
instance:Error({message = "Player disconnected!", traceback = ""})
end
end)
getmetatable(SF.playerInstances).__index = function() return {} end
if SERVER then
SF.playerInstances = SF.EntityTable("playerInstances", function(ply, instances)
for instance in pairs(instances) do
instance:Error({message = "Player disconnected!", traceback = ""})
if IsValid(instance.entity) then
net.Start("starfall_processor_kill")
net.WriteEntity(instance.entity)
net.Broadcast()
end
end
end)
getmetatable(SF.playerInstances).__index = function() return {} end
else
SF.playerInstances = setmetatable({},{__index = function() return {} end})
end

local plyPrecacheTimeBurst = SF.BurstObject("model_precache_time", "Model precache time", 5, 0.2, "The rate allowed model precache time regenerates.", "Amount of allowed model precache time.")

Expand Down
3 changes: 1 addition & 2 deletions lua/starfall/sflib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ hook.Add("EntityRemoved","SF_CallOnRemove",function(ent)
end
if CLIENT then
timer.Simple(0, function()
-- Can't use IsValid func directly because it can return invalid for recreated entities in clientside
if not ent:IsValid() then
if not IsValid(ent) then
for k, v in pairs(hooks) do
if v[2] then v[2](ent) end
end
Expand Down
Loading