blob: b97393266dadb33fd16ab7b75765d9c5b7ff9c7d (
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
|
local insert = table.insert
if (SERVER) then
util.AddNetworkString("OpenLootventory")
util.AddNetworkString("DemandLootventoryUpdate")
function OpenLootventory(pl,items,entity)
if (!IsValid(pl) or !items) then return end
net.Start("OpenLootventory")
net.WriteEntity(entity)
for k,v in pairs(items) do
if (v.Name and v.Quantity) then
net.WriteBit(true)
net.WriteString(v.Name)
net.WriteUInt(v.Quantity,32)
end
end
net.Send(pl)
end
net.Receive("DemandLootventoryUpdate",function(siz,pl)
local ent = net.ReadEntity()
if (!IsValid(ent) or !ent.GetItems) then return end
if (pl:GetPos():Distance(ent:GetPos()) > 200) then return end
OpenLootventory(pl,ent:GetItems(),ent)
end)
else
net.Receive("OpenLootventory",function()
local dat = {}
local ent = net.ReadEntity()
while (util.tobool(net.ReadBit())) do
local Ab = GetItemByName(net.ReadString())
local Co = net.ReadUInt(32)
if (Ab and Co > 0) then insert(dat,{Name = Ab.Name, Quantity = Co}) end
end
MakeLootventory(dat,ent)
GAMEMODE:OnSpawnMenuOpen()
end)
function DemandLootventoryUpdate(entity)
if (!IsLootventoryOpen()) then return end
net.Start("DemandLootventoryUpdate")
net.WriteEntity(entity)
net.SendToServer()
end
end
|