--[[ A lazy loader for pac3 costumes, used for weapons/armor/ect. ]] --As soon as the client connects, request the names of all the pac's on the server --If the player dosen't have PAC3 installed, then overwrite all pac-related network events to display an error. if pac == nil then local function no_pac_panic() error("This gamemode require PAC3 to display armor/cloths, please be sure clients are downloading this addon from somewhere (perferably the workshop!)") end local networkmsgs = { "artery_downloadpac", "artery_applypac", "artery_giveworldpacs", "artery_removepac" } for k,v in pairs(networkmsgs) do net.Receive(v,no_pac_panic) end no_pac_panic() 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) 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) end if filetext and (tonumber(util.CRC(filetext)) == hash) then print("The file on our local system is up to date, applying!") local pactbl = CompileString(string.format("return {%s}",filetext),name)() ent:AttachPACPart(pactbl) else--Cache is old, download the new pac! print("The file on our local system was out of date! Downloading...") net.Start("artery_requestpac") net.WriteString(name) net.SendToServer() --1 second is probably long enough to download a pac, right? timer.Simple(1,function() loadpac(ent,name,hash) end) end end local function unloadpac(ent,name,hash) local filepath = string.format(CLIENT_PAC_DIR .. "/%s.txt",name) local filetext = file.Read(filepath,"DATA") local pactbl = CompileString(string.format("return {%s}",filetext),name)() ent:RemovePACPart(pactbl) end net.Receive("artery_downloadpac",function() local pac_name = net.ReadString() local pac_txt = net.ReadString() --local pac_hash = net.ReadUInt(32) local filepath = string.format(CLIENT_PAC_DIR .. "/%s.txt",pac_name) file.Write(filepath,pac_txt) end) net.Receive("artery_applypac",function() local pac_ent = net.ReadEntity() local pac_name = net.ReadString() local pac_hash = net.ReadUInt(32) loadpac(pac_ent,pac_name,pac_hash) end) net.Receive("artery_giveworldpacs",function() local pactbl = net.ReadTable() for ent,pacnames in pairs(pactbl) do for name, hash in pairs(pacnames) do loadpac(ent,name,hash) end end end) net.Receive("artery_removepac",function() local pac_ent = net.ReadEntity() local pac_name = net.ReadString() local pac_hash = net.ReadUInt(32) unloadpac(pac_ent,pac_name,pac_hash) end)