aboutsummaryrefslogtreecommitdiff
path: root/gamemode/shared/player_pigeon.lua
blob: 2256af0955a5848372e6af572518f5dba7df0b76 (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
local meta = FindMetaTable("Player")

if (SERVER) then
	util.AddNetworkString("AssignPigeon")
	
	function meta:SpawnPigeon()
		if (IsValid(self.Pigeon)) then return end 
		
		self.Pigeon = ents.Create("ws_pigeon")
		self.Pigeon:SetPos(self:GetPos())
		self.Pigeon:SetPlayer(self)
		self.Pigeon:Spawn()
		self.Pigeon:Activate()
		
		print("Spawned Pigeon: "..self:Nick())
		
		timer.Simple(0.2,function()
		net.Start("AssignPigeon")
			net.WriteEntity(self)
			net.WriteEntity(self.Pigeon)
		net.Broadcast() end)
	end
	
	function meta:UpdatePigeons()
		for k,v in pairs(player.GetAll()) do
			if (IsValid(v.Pigeon)) then
				timer.Simple(math.Rand(0.1,0.2),function()
					net.Start("AssignPigeon")
						net.WriteEntity(v)
						net.WriteEntity(v.Pigeon)
					net.Send(self)
				end)
			end
		end
	end
else
	net.Receive("AssignPigeon",function() net.ReadEntity().Pigeon = net.ReadEntity() end)
end

function meta:GetPigeon()
	return self.Pigeon
end