--[[ All the functions related to networking pac's ]] if CLIENT then local function applypac(who,pacname) local pactxt = file.Read("artery/pacs/"..pacname..".txt","DATA") print("got pac txt",pactxt) if pactxt == nil then print("requesting pac") net.Start("requestpac") net.WriteString(pacname) net.SendToServer() timer.Simple(5,function() --5 seconds is probably enough time to load a pac, right? print("trying to re-apply pac") applypac(who,pacname) end) else if who.AttachPACPart == nil then print("setting up ent for pac") pac.SetupENT(who) end print("pactxt was",pactxt) local pactbl = CompileString("return {"..pactxt.."}",pacname)() print("pactbl is") PrintTable(pactbl) print("who is",who) who:AttachPACPart(pactbl) print("Pac Equiped!") end end local function removepac(who,pacname) local pactxt = file.Read("artery/pacs/"..pacname..".txt","DATA") assert(pactxt ~= nil, "Attempted to remove a pac that dosn't exist") assert(who.RemovePACPart ~= nil,"That entity isn't set up to have pacs!") local pactbl = CompileString("return {" .. pactxt .. "}", pacname)() who:RemovePACPart(pactbl) end net.Receive("loadpac",function() local pacname = net.ReadString() local pacdata = util.Decompress(net.ReadString()) file.Write("artery/pacs/"..pacname..".txt",pacdata) end) net.Receive("applypac",function() print("apply ing pac") local towho = net.ReadEntity() local pacname = net.ReadString() applypac(towho,pacname) end) net.Receive("removepac",function() local towho = net.ReadEntity() local pacname = net.ReadString() removepac(towho,pacname) end) else for _,v in pairs({ "applypac", "removepac", "requestpac", "loadpac", })do util.AddNetworkString(v) end net.Receive("requestpac",function(ln,ply) local pacname = net.ReadString() local pacdata = file.Read("artery/pacs/"..pacname..".txt","DATA") assert(pacdata ~= nil,string.format("Client %q requested pac that dosn't exist %q",ply:Nick(),pacname)) net.Start("loadpac") net.WriteString(pacname) net.WriteString(util.Compress(pacdata)) net.Send(ply) end) local playerpacs = {} ART.ApplyPAC = function(to,pacname) print("Applying pac") net.Start("applypac") net.WriteEntity(to) net.WriteString(pacname) net.Broadcast() playerpacs[to] = playerpacs[to] or {} table.insert(playerpacs[to],pacname) end hook.Add( "PlayerInitialSpawn", "loadpacs", function(ply) timer.Simple(5,function() --Wait 5 seconds, hopefully they're ok to go by then for k,v in pairs(playerpacs) do for i,j in pairs(v) do net.Start("applypac") net.WriteEntity(k) net.WriteString(j) net.Send(ply) end end end) end) ART.RemovePAC = function(to,pacname) net.Start("removepac") net.WriteEntity(to) net.WriteString(pacname) net.Broadcast() table.RemoveByValue(playerpacs[to], pacname) end end local paclist