aboutsummaryrefslogtreecommitdiff
path: root/gamemode/shared/player_human.lua
blob: 8fa6997af14a5a4c0ffb32d4eac5038f07e2f317 (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
61
62
63
64
65
66
local meta = FindMetaTable("Player")

if (SERVER) then
	util.AddNetworkString("SetHuman")
	
	function meta:SetHuman(bool)
		self.IsHuman 		= bool
		self.Inventory 		= {}
		self.Weapons 		= {}
		
		net.Start("SetHuman")
			net.WriteEntity(self)
			net.WriteBit(self.IsHuman)
		net.Broadcast()
	end
	
	function meta:UpdateHumans()
		for k,v in pairs(player.GetAll()) do
			if (v.IsHuman) then
				timer.Simple(math.Rand(0.1,0.2),function()
					net.Start("SetHuman")
						net.WriteEntity(v) 
						net.WriteBit(true)
					net.Send(self)
				end)
			end
		end
	end
else
	net.Receive("SetHuman",function() 
		local pl = net.ReadEntity()
		
		pl.IsHuman 		= util.tobool(net.ReadBit()) 
		pl.Inventory 	= {}
		pl.Weapons 		= {}
	end)
end

function meta:IsPigeon()
	return !util.tobool(self.IsHuman)
end

function player.GetAllHumans()
	local dat = {}
	
	for k,v in pairs(player.GetAll()) do
		if (!v:IsPigeon()) then
			table.insert(dat,v)
		end
	end
	
	return dat 
end

function player.GetAllHumansAlive()
	local dat = {}
	
	for k,v in pairs(player.GetAll()) do
		if (!v:IsPigeon() and v:Alive()) then
			table.insert(dat,v)
		end
	end
	
	return dat 
end