From 025ef8554016a2647f31244cf6413d80dba91847 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sun, 25 Mar 2018 12:58:22 -0400 Subject: Fix #3 Allows pacs that have been loaded on join to be removed Also loads player data much sooner after the player spawns in. --- gamemode/core/pac/cl_pac.lua | 18 ++++++++++++------ gamemode/core/pac/sv_pac.lua | 10 ++++++---- 2 files changed, 18 insertions(+), 10 deletions(-) (limited to 'gamemode/core/pac') diff --git a/gamemode/core/pac/cl_pac.lua b/gamemode/core/pac/cl_pac.lua index 490ad31..477d65d 100644 --- a/gamemode/core/pac/cl_pac.lua +++ b/gamemode/core/pac/cl_pac.lua @@ -19,22 +19,28 @@ if pac == nil then return --Don't execute this file! end -timer.Simple(0,function() - net.Start("artery_getworldpacs") - net.SendToServer() -end) - local CLIENT_PAC_DIR = "artery/client/pacs" file.CreateDir(CLIENT_PAC_DIR) local function loadpac(ent,name,hash) + if (not ent) or (not ent:IsValid()) then + timer.Simple(1,function() + loadpac(ent,name,hash) + end) + return + end print("Told to apply pac", name, "to ent", ent) local filepath = string.format(CLIENT_PAC_DIR .. "/%s.txt",name) local filetext = file.Read(filepath,"DATA") if ent.AttachPACPart == nil then pac.SetupENT(ent) - assert(ent.AttachPACPart ~= nil,"Failed to set up ent",ent) + if ent.AttachPACPart == nil then + timer.Simple(1,function() + loadpac(ent,name,hash) + end) + return + end end if filetext and (tonumber(util.CRC(filetext)) == hash) then print("The file on our local system is up to date, applying!") diff --git a/gamemode/core/pac/sv_pac.lua b/gamemode/core/pac/sv_pac.lua index 916430c..6c9a731 100644 --- a/gamemode/core/pac/sv_pac.lua +++ b/gamemode/core/pac/sv_pac.lua @@ -140,10 +140,12 @@ function p3.GetPacs(what) end --If a player joins the server, tell them all about the pacs that are applied -net.Receive("artery_getworldpacs",function(ln,ply) - net.Start("artery_giveworldpacs") - net.WriteTable(appliedpacs) - net.Send(ply) +hook.Add("PlayerLoadout","send_world_pacs",function(ply) + timer.Simple(1,function() + net.Start("artery_giveworldpacs") + net.WriteTable(appliedpacs) + net.Send(ply) + end) end) local max_pacs_in_cache = 10 -- cgit v1.2.3-70-g09d2