summaryrefslogtreecommitdiff
path: root/lua/autorun/saveprops.lua
blob: ec3455d2e34e38794de1c32f324374b467625004 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
if CLIENT then return end
local function saveparts()
	local spawndata = {"local e"}
	for k,v in pairs(ents.GetAll()) do
		if v:GetPersistent() then
			local c = v:GetColor()
			local a = v:GetAngles()
			local p = v:GetPos()
			spawndata[#spawndata + 1] = string.format([[
e = ents.Create(%q)
e:SetModel(%q)
e:SetMaterial(%q)
e:SetColor(Color(%d,%d,%d,%d))
e:SetAngles(Angle(%d,%d,%d))
e:SetPos(Vector(%d,%d,%d))
e:Spawn()
e:GetPhysicsObject():EnableMotion(false)
			]],
			v:GetClass(),
			v:GetModel(),
			v:GetMaterial(),
			c.r,c.g,c.b,c.a,
			a.p,a.y,a.r,
			p.x,p.y,p.z)
		end
	end
	local fstr = table.concat(spawndata,"\n")
	local path = "artery/maps/" .. game.GetMap() .. "/ents.txt"
	print("Writing file", fstr," to",path)
	file.Write(path,fstr)
end

concommand.Add("artery_save_persistent_props",saveparts)

--[[
hook.Add("ShutDown","artery_save_persistent_props",function()

end)
]]