-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsv_propadder.lua
61 lines (51 loc) · 1.8 KB
/
sv_propadder.lua
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
----// Prop Adder //----
-- Author: Exho
-- Version: 10/15/14
if SERVER then
AddCSLuaFile()
PropSpawnerDir = "propadder/"..game.GetMap().."_props.txt" -- Directory where the spawn files are CREATED under the /data/ folder
PropSpawnerReadDir = "maps/" ..game.GetMap().. "_props.txt" -- Directory where spawn files should BE in order to be read
local col = Color( 241, 196, 15 )
local function SpawnPropFromTxt()
MsgC( col, "* Creating Props *\n" )
if not file.Exists( PropSpawnerReadDir, "GAME" ) then
MsgC( col, "* No props needed on this map! *\n" )
return
end
local txt = file.Read( PropSpawnerReadDir, "GAME" ) -- Read the spawns file
local tab = util.JSONToTable( txt )
for k, v in pairs(tab) do -- Loop through the table of spawns
local ent = ents.Create("prop_physics")
ent:SetPos(v.pos)
ent:SetModel(v.mdl)
ent:SetAngles(v.ang)
ent:Spawn()
ent.TxtSpawned = true -- In case we need to clean them up
end
MsgC( col, "* Finished Creating Props *\n" )
end
local function DestroySpawnedProps()
MsgC( col, "* Cleaning up Spawned Props *\n" )
local Count = 0
for k, v in pairs(ents.GetAll()) do
if v.TxtSpawned or v.PSpawned and IsValid(v) then -- If spawned from Txt or the Wep, remove
v:Remove()
Count = Count + 1
end
end
if Count == 0 then
MsgC( col, "* No spawned props to clean up *\n" )
return
end
MsgC( col, "* All spawned props are banished *\n" )
end
hook.Add( "InitPostEntity", "AutomaticPropRearming", SpawnPropFromTxt) -- Spawn custom props after all the regular ones have
concommand.Add( "padd_spawn",function(ply)
if not ply:IsSuperAdmin() then return false end
SpawnPropFromTxt()
end)
concommand.Add( "padd_cleanup",function(ply)
if not ply:IsSuperAdmin() then return false end
DestroySpawnedProps()
end)
end