2008-06-14 00:55:20 +00:00
|
|
|
|
|
|
|
-- phenex: Start radio mod.
|
|
|
|
local radio_channels = {}
|
|
|
|
local radio_sets = {}
|
2009-01-17 13:17:12 +00:00
|
|
|
local radio_num = {}
|
2008-06-14 00:55:20 +00:00
|
|
|
|
|
|
|
function Radio_Register( o )
|
|
|
|
table.insert( radio_sets, o )
|
|
|
|
end
|
|
|
|
|
2009-01-17 13:17:12 +00:00
|
|
|
function Radio_TuneIn(ent,ch)
|
|
|
|
if (ent.Secure == true) then
|
|
|
|
if (radio_channels[ent.pl:SteamID()] == nil) then
|
|
|
|
radio_num[ent.pl:SteamID()] = {}
|
|
|
|
end
|
|
|
|
radio_num[ent.pl:SteamID()][ch] = (radio_num[ent.pl:SteamID()][ch] or 0) + 1
|
|
|
|
else
|
|
|
|
radio_num[ch] = (radio_num[ch] or 0) + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-10-31 22:36:20 +00:00
|
|
|
function Radio_TuneOut(ent,ch)
|
|
|
|
if (ent.Secure == true) then
|
2008-11-01 23:43:12 +00:00
|
|
|
if (radio_channels[ent.pl:SteamID()] == nil) then
|
|
|
|
radio_channels[ent.pl:SteamID()] = {}
|
|
|
|
end
|
2009-01-17 13:17:12 +00:00
|
|
|
radio_num[ent.pl:SteamID()][ch] = (radio_num[ent.pl:SteamID()][ch] or 0) - 1
|
2009-01-17 18:17:18 +00:00
|
|
|
if ((radio_num[ent.pl:SteamID()][ch] or 0) == 0) then
|
2009-01-17 13:17:12 +00:00
|
|
|
radio_channels[ent.pl:SteamID()][ch] = {}
|
|
|
|
end
|
2008-10-31 22:36:20 +00:00
|
|
|
else
|
2009-01-17 18:17:18 +00:00
|
|
|
radio_num[ch] = (radio_num[ch] or 1) - 1
|
2009-01-17 13:17:12 +00:00
|
|
|
if (radio_num[ch] == 0) then
|
|
|
|
// Msg(" Clear radio channels "..ch.."\n")
|
|
|
|
radio_channels[ch] = {}
|
|
|
|
end
|
2008-10-31 22:36:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
for i, o in ipairs( radio_sets ) do
|
|
|
|
if (not IsEntity(o.Entity)) then
|
|
|
|
table.remove(radio_sets, i)
|
|
|
|
elseif (o.Channel == ch && o.Entity:EntIndex() != ent:EntIndex()) then
|
2009-01-17 18:17:18 +00:00
|
|
|
if (radio_channels[ch] == null) then
|
|
|
|
radio_channels[ch] = {}
|
2009-01-17 13:17:12 +00:00
|
|
|
end
|
|
|
|
|
2009-01-17 18:17:18 +00:00
|
|
|
local retable = radio_channels[ch]
|
|
|
|
for i=1,20 do if (!radio_channels[ch][tostring(i)]) then retable[tostring(i)] = 0 end end
|
|
|
|
|
|
|
|
// Msg("Tune out: notifying a radio on channel "..ch.."\n")
|
|
|
|
|
2008-10-31 22:36:20 +00:00
|
|
|
o:ReceiveRadio(retable)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-06-14 00:55:20 +00:00
|
|
|
function Radio_Transmit(ent,ch,k,v)
|
|
|
|
if (ent.Secure == true) then
|
|
|
|
if (radio_channels[ent.pl:SteamID()] == nil) then radio_channels[ent.pl:SteamID()] = {} end
|
|
|
|
if (radio_channels[ent.pl:SteamID()][ch] == nil) then radio_channels[ent.pl:SteamID()][ch] = {} end
|
|
|
|
radio_channels[ent.pl:SteamID()][ch][k] = v
|
|
|
|
else
|
|
|
|
if (radio_channels[ch] == nil) then radio_channels[ch] = {} end
|
|
|
|
radio_channels[ch][k] = v
|
|
|
|
end
|
|
|
|
|
|
|
|
for i, o in ipairs( radio_sets ) do
|
|
|
|
if (not IsEntity(o.Entity)) then
|
|
|
|
table.remove(radio_sets, i)
|
|
|
|
elseif (o.Channel == ch && o.Entity:EntIndex() != ent:EntIndex()) then
|
|
|
|
if (o.Secure == true && ent.Secure == true) then
|
|
|
|
if (o.pl:EntIndex() == ent.pl:EntIndex()) then
|
|
|
|
o:SReceiveRadio(k,v)
|
|
|
|
end
|
|
|
|
elseif (o.Secure == false && ent.Secure == false) then
|
|
|
|
o:SReceiveRadio(k,v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-17 18:17:18 +00:00
|
|
|
function Radio_ChannelOccupied(ent,ch)
|
|
|
|
if (ent.Secure == true) then
|
|
|
|
if (radio_channels[ent.pl:SteamID()] == nil) then
|
|
|
|
radio_num[ent.pl:SteamID()] = {}
|
|
|
|
end
|
|
|
|
if ((radio_num[ent.pl:SteamID()][ch] or 0) ~= 0) then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
else
|
|
|
|
// print("is occupied "..ch.." = "..radio_num[ch] or 0)
|
|
|
|
if ((radio_num[ch] or 0) ~= 0) then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2008-10-31 22:36:20 +00:00
|
|
|
function Radio_Receive(ent, ch)
|
2008-06-14 00:55:20 +00:00
|
|
|
if (ent.Secure == true) then
|
|
|
|
if (radio_channels[ent.pl:SteamID()] == nil) then return {} end
|
|
|
|
if (type(radio_channels[ent.pl:SteamID()][ch]) == "table") then
|
2008-10-31 22:36:20 +00:00
|
|
|
local retable = radio_channels[ent.pl:SteamID()][ch]
|
2009-01-17 13:17:12 +00:00
|
|
|
for i=1,20 do if (!radio_channels[ent.pl:SteamID()][ch][tostring(i)]) then retable[tostring(i)] = 0 end end
|
2008-10-31 22:36:20 +00:00
|
|
|
return retable //Nothing fancy needed :P
|
2008-10-07 18:28:23 +00:00
|
|
|
else
|
|
|
|
local retable = {}
|
|
|
|
for i=1,20 do retable[tostring(i)] = 0 end
|
|
|
|
return retable
|
2008-06-14 00:55:20 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
if (type(radio_channels[ch]) == "table") then
|
2008-10-31 22:36:20 +00:00
|
|
|
local retable = radio_channels[ch]
|
2009-01-17 13:17:12 +00:00
|
|
|
for i=1,20 do if (!radio_channels[ch][tostring(i)]) then retable[tostring(i)] = 0 end end
|
|
|
|
|
2008-10-31 22:36:20 +00:00
|
|
|
return retable //Nothing fancy needed :P
|
2008-10-07 18:28:23 +00:00
|
|
|
else
|
|
|
|
local retable = {}
|
|
|
|
for i=1,20 do retable[tostring(i)] = 0 end
|
|
|
|
return retable
|
2008-06-14 00:55:20 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return {}
|
|
|
|
end
|
|
|
|
|
|
|
|
local radio_twowaycounter = 0
|
|
|
|
|
|
|
|
function Radio_GetTwoWayID()
|
|
|
|
radio_twowaycounter = radio_twowaycounter + 1
|
|
|
|
return radio_twowaycounter
|
|
|
|
end
|
|
|
|
|
|
|
|
-- phenex: End radio mod.
|
|
|
|
//Modified by High6 (To support 4 values)
|
2008-02-07 12:58:13 +00:00
|
|
|
//Rebuilt by high6 to allow defined amount of values/secure lines
|