diff --git a/wire/lua/autorun/server/radiolib.lua b/wire/lua/autorun/server/radiolib.lua index 58becdb..7b53c8e 100644 --- a/wire/lua/autorun/server/radiolib.lua +++ b/wire/lua/autorun/server/radiolib.lua @@ -7,27 +7,43 @@ function Radio_Register( o ) table.insert( radio_sets, o ) end -function Radio_Transmit( ch, A,B,C,D ) - radio_channels[ch] = {} - radio_channels[ch]['A'] = A - radio_channels[ch]['B'] = B - radio_channels[ch]['C'] = C - radio_channels[ch]['D'] = D +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) then - o:ReceiveRadio(A,B,C,D) + 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( ch ) - if (type(radio_channels[ch]) == "table") then - return radio_channels[ch]['A'] or 0,radio_channels[ch]['B'] or 0,radio_channels[ch]['C'] or 0, radio_channels[ch]['D'] or 0 +function Radio_Receive(ent ,ch ) + 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 + return radio_channels[ent.pl:SteamID()][ch] //Nothing fancy needed :P + end + else + if (type(radio_channels[ch]) == "table") then + return radio_channels[ch] //Nothing fancy needed :P + end end - return 0,0,0,0 + return {} end local radio_twowaycounter = 0 @@ -38,4 +54,5 @@ function Radio_GetTwoWayID() end -- phenex: End radio mod. -//Modified by High6 (To support 4 values) \ No newline at end of file +//Modified by High6 (To support 4 values) +//Rebuilt by high6 to allow defined amount of values/secure lines \ No newline at end of file diff --git a/wire/lua/entities/gmod_wire_input/init.lua b/wire/lua/entities/gmod_wire_input/init.lua index b5797cb..1c21a5c 100644 --- a/wire/lua/entities/gmod_wire_input/init.lua +++ b/wire/lua/entities/gmod_wire_input/init.lua @@ -28,7 +28,6 @@ end function ENT:Setup(keygroup, toggle, value_off, value_on) self.keygroup = keygroup self.toggle = (toggle == 1) - self.toggle = toggle self.value_off = value_off self.value_on = value_on self.Value = value_off diff --git a/wire/lua/entities/gmod_wire_radio/init.lua b/wire/lua/entities/gmod_wire_radio/init.lua index 1b68339..1770acb 100644 --- a/wire/lua/entities/gmod_wire_radio/init.lua +++ b/wire/lua/entities/gmod_wire_radio/init.lua @@ -13,8 +13,8 @@ function ENT:Initialize() self.Entity:SetMoveType( MOVETYPE_VPHYSICS ) self.Entity:SetSolid( SOLID_VPHYSICS ) - self.Inputs = Wire_CreateInputs(self.Entity, { "A", "B", "C", "D", "Channel"}) - self.Outputs = Wire_CreateOutputs(self.Entity, { "A", "B", "C", "D" }) + self.Inputs = Wire_CreateInputs(self, { "Channel"}) + self.Outputs = Wire_CreateOutputs(self, { "ERRORS!!!" }) self.Channel = 1 self.Transmitting = 0 @@ -22,36 +22,85 @@ function ENT:Initialize() Radio_Register(self) end -function ENT:Setup(channel) - channel = math.floor(channel) +function ENT:Setup(channel,values,secure) + channel = math.floor(tonumber(channel) or 0) self.Channel = channel - self.PrevOutput = nil - - self:ShowOutput(Radio_Receive(channel)) + self.Secure = secure + self.Old = false + if (tonumber(values) == nil) then + values = 4 + self.Old = true + else + values = math.Round(values) + if (values > 20) then + values = 20 + end + if (values < 1) then + values = 1 + end + end + self.Values = values + local onames = {} + if (self.Old == false) then + for i = 1,self.Values do + onames[i] = tostring(i) //without tostring() you kill the debugger. + end + else + onames = {"A","B","C","D"} + end + + Wire_AdjustOutputs(self,onames) + table.insert(onames,"Channel") + Wire_AdjustInputs(self,onames) + + self:ReceiveRadio(Radio_Receive(self,self.Channel)) end function ENT:TriggerInput(iname, value) - if (iname == "A" || iname == "B" || iname == "C" || iname == "D") then - self.Inputs[iname].Value = value - Radio_Transmit(self.Channel, self.Inputs.A.Value or 0,self.Inputs.B.Value or 0,self.Inputs.C.Value or 0,self.Inputs.D.Value or 0) - self:ShowOutput(self.Outputs.A.Value or 0,self.Outputs.B.Value or 0,self.Outputs.C.Value or 0,self.Outputs.D.Value or 0) - end if (iname == "Channel") then self.Channel = math.floor(value) - self:ShowOutput(Radio_Receive(self.Channel)) + self:ReceiveRadio(Radio_Receive(self,self.Channel)) + elseif (iname != nil && value != nil) then + self.Inputs[iname].Value = value + self:Transmit(self.Channel,iname,value) end + self:ShowOutput() end -function ENT:ReceiveRadio(A,B,C,D) - self:ShowOutput(A,B,C,D) +function ENT:Transmit(channel,k,v) + Radio_Transmit(self,self.Channel,k,v) end -function ENT:ShowOutput(A,B,C,D) - Wire_TriggerOutput(self.Entity,"A",A) - Wire_TriggerOutput(self.Entity,"B",B) - Wire_TriggerOutput(self.Entity,"C",C) - Wire_TriggerOutput(self.Entity,"D",D) - self:SetOverlayText( "(Channel " .. self.Channel .. ") Transmit A: " .. (self.Inputs.A.Value or 0) .. " B: " .. (self.Inputs.B.Value or 0) .. " C: " .. (self.Inputs.C.Value or 0) .. " D: " .. (self.Inputs.D.Value or 0) .. "\nReceive A: " .. (self.Outputs.A.Value or 0) .. " B: " .. (self.Outputs.B.Value or 0) .. " C: " .. (self.Outputs.C.Value or 0) .. " D: " .. (self.Outputs.D.Value or 0) ) +function ENT:ReceiveRadio(values) + if (values == nil) then return end + local i = 1 + for k,o in pairs(values) do + Wire_TriggerOutput(self,k,o) + if (i >= self.Values) then self:ShowOutput() return end + i = i + 1 + end + self:ShowOutput() +end +function ENT:SReceiveRadio(k,v) + if (k == nil || v == nil) then return end + Wire_TriggerOutput(self,k,v) + self:ShowOutput() +end +function ENT:ShowOutput() + if (self.Old == true) then + self:SetOverlayText( "(Channel " .. self.Channel .. ") Transmit A: " .. (self.Inputs.A.Value or 0) .. " B: " .. (self.Inputs.B.Value or 0) .. " C: " .. (self.Inputs.C.Value or 0) .. " D: " .. (self.Inputs.D.Value or 0) .. "\nReceive A: " .. (self.Outputs.A.Value or 0) .. " B: " .. (self.Outputs.B.Value or 0) .. " C: " .. (self.Outputs.C.Value or 0) .. " D: " .. (self.Outputs.D.Value or 0) ) + else + local overlay = "(Channel " .. self.Channel .. ") Transmit" + for i=1,self.Values do + if (k!= "Channel") then if (self.Outputs[tostring(i)] != nil) then overlay = overlay .. " " .. (tostring(i) or "Error") .. ":" .. math.Round((self.Inputs[tostring(i)].Value or 0)*1000)/1000 end end + end + overlay = overlay .. "\nReceive" + for i=1,self.Values do + if (self.Outputs[tostring(i)] != nil) then overlay = overlay .. " " .. (tostring(i) or "Error") .. ":" .. math.Round((self.Outputs[tostring(i)].Value or 0)*1000)/1000 end + end + if (self.Secure == true) then overlay = overlay .. "\nSecured" end + self:SetOverlayText( overlay ) + end end function ENT:OnRestore() @@ -59,3 +108,12 @@ function ENT:OnRestore() Radio_Register(self) end + +function ENT:OnRemove() + if (!self.Channel) then return end + for k,v in pairs(self.Inputs) do + if (v.Value != 0) then + self:Transmit(self.Channel,tostring(k),0) + end + end +end diff --git a/wire/lua/weapons/gmod_tool/stools/wire_radio.lua b/wire/lua/weapons/gmod_tool/stools/wire_radio.lua index 7e0ab62..c659b20 100644 --- a/wire/lua/weapons/gmod_tool/stools/wire_radio.lua +++ b/wire/lua/weapons/gmod_tool/stools/wire_radio.lua @@ -9,6 +9,8 @@ if ( CLIENT ) then language.Add( "Tool_wire_radio_0", "Primary: Create/Update Radio" ) language.Add( "WireRadioTool_channel", "Channel:" ) language.Add( "WireRadioTool_model", "Model:" ); + language.Add( "WireRadioTool_values", "Values:" ); + language.Add( "WireRadioTool_secure", "Secure:" ); language.Add( "sboxlimit_wire_radios", "You've hit the radio limit!" ) language.Add( "undone_wireradio", "Undone Wire Radio" ) end @@ -19,6 +21,8 @@ if (SERVER) then end TOOL.ClientConVar[ "channel" ] = 1 +TOOL.ClientConVar["values"] = 4 +TOOL.ClientConVar["secure"] = 0 TOOL.ClientConVar[ "model" ] = "models/props_lab/binderblue.mdl" TOOL.Model = "models/props_lab/binderblue.mdl" @@ -32,11 +36,13 @@ function TOOL:LeftClick( trace ) local ply = self:GetOwner() - local _channel = self:GetClientInfo( "channel" ) - local model = self:GetClientInfo( "model" ) + local _channel = self:GetClientInfo( "channel" ) + local model = self:GetClientInfo( "model" ) + local values = self:GetClientNumber("values") + local secure = (self:GetClientNumber("secure") ~= 0) if ( trace.Entity:IsValid() && trace.Entity:GetClass() == "gmod_wire_radio" && trace.Entity.pl == ply ) then - trace.Entity:Setup( _channel ) + trace.Entity:Setup( _channel,values,secure) trace.Entity.channel = _channel return true end @@ -46,7 +52,7 @@ function TOOL:LeftClick( trace ) local Ang = trace.HitNormal:Angle() Ang.pitch = Ang.pitch + 90 - local wire_radio = MakeWireRadio( ply, model, trace.HitPos, Ang, _channel ) + local wire_radio = MakeWireRadio( ply, model, trace.HitPos, Ang, _channel,values,secure) local min = wire_radio:OBBMins() wire_radio:SetPos( trace.HitPos - trace.HitNormal * min.z ) @@ -66,7 +72,7 @@ end if SERVER then - function MakeWireRadio(pl, Model, Pos, Ang, channel, Vel, aVel, frozen ) + function MakeWireRadio(pl, Model, Pos, Ang, channel,values, secure, Vel, aVel, frozen ) if ( !pl:CheckLimit( "wire_radioes" ) ) then return nil end local wire_radio = ents.Create( "gmod_wire_radio" ) @@ -76,22 +82,24 @@ if SERVER then wire_radio:Spawn() wire_radio:Activate() - wire_radio:Setup( channel ) - wire_radio:SetPlayer( pl ) - local ttable = { channel = channel, + values = values, + secure = secure, pl = pl, nocollide = nocollide, } table.Merge( wire_radio:GetTable(), ttable ) + + wire_radio:Setup( channel ,values ,secure ) + wire_radio:SetPlayer( pl ) pl:AddCount( "wire_radioes", wire_radio ) return wire_radio end - duplicator.RegisterEntityClass("gmod_wire_radio", MakeWireRadio, "Model", "Pos", "Ang", "channel", "Vel", "aVel", "frozen") + duplicator.RegisterEntityClass("gmod_wire_radio", MakeWireRadio, "Model", "Pos", "Ang", "channel","values","secure", "Vel", "aVel", "frozen") end @@ -154,4 +162,18 @@ function TOOL.BuildCPanel(panel) }) ModelPlug_AddToCPanel(panel, "radio", "wire_radio", "#WireRadioTool_model", nil, "#WireRadioTool_model") + + panel:AddControl("Slider", { + Label = "#WireRadioTool_values", + Type = "Integer", + Min = "1", + Max = "20", + Command = "wire_radio_values" + }) + + panel:AddControl("CheckBox", { + Label = "#WireRadioTool_secure", + Command = "wire_radio_secure" + }) + end diff --git a/wire/lua/weapons/gmod_tool/stools/wire_textreceiver.lua b/wire/lua/weapons/gmod_tool/stools/wire_textreceiver.lua index ba393c7..fe42163 100644 --- a/wire/lua/weapons/gmod_tool/stools/wire_textreceiver.lua +++ b/wire/lua/weapons/gmod_tool/stools/wire_textreceiver.lua @@ -94,7 +94,7 @@ function TOOL:LeftClick( trace ) if (string.len(parsetext) == 1) then parsetext = parsetext .. parsetext end - if (string.len(parsetext) > 2) then self:GetOwner():SendLua( "GAMEMODE:AddNotify('WTF ARE YOU DOING!!!', NOTIFY_GENERIC, 7);" ) return false end + if (string.len(parsetext) > 2) then self:GetOwner():SendLua( "GAMEMODE:AddNotify('Parse text cannot be more than 2 characters!', NOTIFY_GENERIC, 7);" ) return false end if (table.Count(lines)==0) then return false end