aboutsummaryrefslogtreecommitdiff
path: root/gamemode/shared/sh_pac.lua
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2016-08-09 17:53:52 -0400
committerAlexander Pickering <alexandermpickering@gmail.com>2016-08-09 17:53:52 -0400
commitd4f197a35c207c9891d3f4dc5e9708af48c935de (patch)
treeee8fd3960c3a3fb4ecaf0f62b50d251f007ebaf3 /gamemode/shared/sh_pac.lua
parent2fe3c4551344870e3784733fce2d95027b5c8382 (diff)
downloadartery-d4f197a35c207c9891d3f4dc5e9708af48c935de.tar.gz
artery-d4f197a35c207c9891d3f4dc5e9708af48c935de.tar.bz2
artery-d4f197a35c207c9891d3f4dc5e9708af48c935de.zip
Added some weapons
Diffstat (limited to 'gamemode/shared/sh_pac.lua')
-rw-r--r--gamemode/shared/sh_pac.lua107
1 files changed, 107 insertions, 0 deletions
diff --git a/gamemode/shared/sh_pac.lua b/gamemode/shared/sh_pac.lua
new file mode 100644
index 0000000..baa7f0b
--- /dev/null
+++ b/gamemode/shared/sh_pac.lua
@@ -0,0 +1,107 @@
+--[[
+ 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)
+ 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