2015-03-14 02:35:30 +08:00
|
|
|
GM.MaxChannels = {}
|
2018-05-02 06:32:59 +08:00
|
|
|
GM.MaxChannels["turret"] = 7
|
|
|
|
|
|
|
|
GM.ChannelsToClass = {}
|
|
|
|
GM.ChannelsToClass["turret"] = {"prop_gunturret", "prop_gunturret_buckshot", "prop_gunturret_assault", "prop_gunturret_rocket"}
|
2015-03-14 02:35:30 +08:00
|
|
|
|
|
|
|
function GM:GetFreeChannel(class)
|
|
|
|
local max = self.MaxChannels[class]
|
|
|
|
if not max then return 1 end
|
|
|
|
|
|
|
|
local taken_channels = {}
|
|
|
|
|
2018-05-02 06:32:59 +08:00
|
|
|
for _, j in pairs(self.ChannelsToClass[class]) do
|
|
|
|
for _, ent in pairs(ents.FindByClass(j)) do
|
|
|
|
if ent:IsValid() and ent.GetChannel then
|
|
|
|
taken_channels[ent:GetChannel()] = true
|
|
|
|
end
|
2015-03-14 02:35:30 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
for i=1, max do
|
|
|
|
if not taken_channels[i] then
|
|
|
|
return i
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return -1
|
|
|
|
end
|
|
|
|
|
|
|
|
function GM:HasFreeChannel(class)
|
|
|
|
return self:GetFreeChannel(class) >= 1
|
|
|
|
end
|