aboutsummaryrefslogtreecommitdiff
path: root/gamemode/server/world.lua
blob: 9d23c7b60f5cfb9adcf0ab2a4996ca469779add3 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
local random = math.random
local traceline = util.TraceLine
local contents  = util.PointContents
local Up 		= Vector(0,0,1)

function GM:GeneratePropRain()
	local Items = {
		GetItemByName("Wood"),
		GetItemByName("Rock"),
		GetItemByName("Crystal"),
	}

	--THIS PIECE OF CODE IS FOR OLDER VERSIONS OF WS MAPS! ITS CRAP BUT WE HAVE TO... For WS players!
	local areas = {}

	for i,area in pairs(ents.FindByClass("info_target")) do
		if (area:GetName() == "survival_spawn") then
			local parent = area:GetParent()
			if (IsValid(parent)) then
				areas[area] = parent
			end
		end
	end

	for pAe,pBe in pairs(areas) do
		local pA,pB = pAe:GetPos(),pBe:GetPos()
		local Dis = pA:Distance(pB)

		for i = 1,40+math.ceil(Dis/70) do
			local V = Vector(random(pB.x,pA.x),random(pB.y,pA.y),random(pB.z,pA.z))
			local Tr = traceline({start=V,endpos=V-Up*40000})
			local Pos = Tr.HitPos+Up*20
			local C  = contents(Pos)

			if (C != CONTENTS_WATER and C != CONTENTS_WATER+CONTENTS_TRANSLUCENT) then
				local drop = ents.Create("ws_item")
				drop.Item = Items[random(1,3)]
				drop:SetModel(drop.Item.Model)
				drop:SetPos(Pos)
				drop:Spawn()
				drop:GetPhysicsObject():Sleep()
			end
		end

		--Shop spawn
		local V = Vector(random(pB.x,pA.x),random(pB.y,pA.y),random(pB.z,pA.z))
		local Tr = traceline({start=V,endpos=V-Up*40000})
		local Pos = Tr.HitPos+Up*20
		local C  = contents(Pos)

		if (C != CONTENTS_WATER and C != CONTENTS_WATER+CONTENTS_TRANSLUCENT) then
			local drop = ents.Create("ws_shop")
			drop:SetPos(Pos)
			drop:Spawn()
			drop:Activate()
		end
	end
	--END... Newer versions of maps should use a brush entity instead.
end