wiremod-svn-archive/wire/lua/autorun/server/radiolib.lua

88 lines
2.5 KiB
Lua
Raw Normal View History

2008-06-14 00:55:20 +00:00
-- phenex: Start radio mod.
local radio_channels = {}
local radio_sets = {}
function Radio_Register( o )
table.insert( radio_sets, o )
end
function Radio_TuneOut(ent,ch)
if (ent.Secure == true) then
radio_channels[ent.pl:SteamID()][ch] = {}
else
radio_channels[ch] = {}
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
local retable = {}
for i=1,20 do retable[tostring(i)] = 0 end
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
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
local retable = radio_channels[ent.pl:SteamID()][ch]
for i=1,20 do if (!radio_channels[ent.pl:SteamID()][ch][i]) then retable[tostring(i)] = 0 end end
return retable //Nothing fancy needed :P
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
local retable = radio_channels[ch]
for i=1,20 do if (!radio_channels[ch][i]) then retable[tostring(i)] = 0 end end
return retable //Nothing fancy needed :P
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)
//Rebuilt by high6 to allow defined amount of values/secure lines