wiremod-svn-archive/wire/lua/weapons/gmod_tool/stools/wire_radio.lua

180 lines
4.9 KiB
Lua
Raw Normal View History

2007-02-04 07:18:10 +00:00
TOOL.Category = "Wire - I/O"
2007-02-04 01:16:06 +00:00
TOOL.Name = "Radio"
TOOL.Command = nil
TOOL.ConfigName = ""
if ( CLIENT ) then
language.Add( "Tool_wire_radio_name", "Radio Tool (Wire)" )
language.Add( "Tool_wire_radio_desc", "Spawns a radio for use with the wire system." )
language.Add( "Tool_wire_radio_0", "Primary: Create/Update Radio" )
language.Add( "WireRadioTool_channel", "Channel:" )
2007-02-07 04:10:32 +00:00
language.Add( "WireRadioTool_model", "Model:" );
language.Add( "WireRadioTool_values", "Values:" );
language.Add( "WireRadioTool_secure", "Secure:" );
2007-02-04 01:16:06 +00:00
language.Add( "sboxlimit_wire_radios", "You've hit the radio limit!" )
language.Add( "undone_wireradio", "Undone Wire Radio" )
end
if (SERVER) then
CreateConVar('sbox_maxwire_radioes',30)
ModelPlug_Register("radio")
2007-02-04 01:16:06 +00:00
end
TOOL.ClientConVar[ "channel" ] = 1
TOOL.ClientConVar["values"] = 4
TOOL.ClientConVar["secure"] = 0
2007-02-07 04:10:32 +00:00
TOOL.ClientConVar[ "model" ] = "models/props_lab/binderblue.mdl"
2007-02-04 01:16:06 +00:00
TOOL.Model = "models/props_lab/binderblue.mdl"
cleanup.Register( "wire_radioes" )
function TOOL:LeftClick( trace )
if (!trace.HitPos) then return false end
if (trace.Entity:IsPlayer()) then return false end
if ( CLIENT ) then return true end
local ply = self:GetOwner()
local _channel = self:GetClientInfo( "channel" )
local model = self:GetClientInfo( "model" )
local values = self:GetClientNumber("values")
local secure = (self:GetClientNumber("secure") ~= 0)
2007-02-04 01:16:06 +00:00
if ( trace.Entity:IsValid() && trace.Entity:GetClass() == "gmod_wire_radio" && trace.Entity.pl == ply ) then
trace.Entity:Setup( _channel,values,secure)
trace.Entity.channel = _channel
2007-02-04 01:16:06 +00:00
return true
end
if ( !self:GetSWEP():CheckLimit( "wire_radioes" ) ) then return false end
local Ang = trace.HitNormal:Angle()
Ang.pitch = Ang.pitch + 90
local wire_radio = MakeWireRadio( ply, model, trace.HitPos, Ang, _channel,values,secure)
2007-02-04 01:16:06 +00:00
local min = wire_radio:OBBMins()
wire_radio:SetPos( trace.HitPos - trace.HitNormal * min.z )
local const = WireLib.Weld(wire_radio, trace.Entity, trace.PhysicsBone, true)
2007-02-04 01:16:06 +00:00
undo.Create("WireRadio")
undo.AddEntity( wire_radio )
undo.SetPlayer( ply )
undo.AddEntity(const)
2007-02-04 01:16:06 +00:00
undo.Finish()
ply:AddCleanup( "wire_radioes", wire_radio )
return true
end
if SERVER then
function MakeWireRadio(pl, Model, Pos, Ang, channel,values, secure, Vel, aVel, frozen )
2007-02-04 01:16:06 +00:00
if ( !pl:CheckLimit( "wire_radioes" ) ) then return nil end
local wire_radio = ents.Create( "gmod_wire_radio" )
wire_radio:SetPos( Pos )
wire_radio:SetAngles( Ang )
2007-02-07 04:10:32 +00:00
wire_radio:SetModel(Model)
2007-02-04 01:16:06 +00:00
wire_radio:Spawn()
wire_radio:Activate()
local ttable = {
2007-02-04 08:20:22 +00:00
channel = channel,
values = values,
secure = secure,
2007-02-04 01:16:06 +00:00
pl = pl,
nocollide = nocollide,
}
table.Merge( wire_radio:GetTable(), ttable )
wire_radio:Setup( channel ,values ,secure )
wire_radio:SetPlayer( pl )
2007-02-04 01:16:06 +00:00
pl:AddCount( "wire_radioes", wire_radio )
return wire_radio
end
duplicator.RegisterEntityClass("gmod_wire_radio", MakeWireRadio, "Model", "Pos", "Ang", "channel","values","secure", "Vel", "aVel", "frozen")
2007-02-04 01:16:06 +00:00
end
function TOOL:UpdateGhostWireRadio( ent, player )
if ( !ent || !ent:IsValid() ) then return end
local tr = utilx.GetPlayerTrace( player, player:GetCursorAimVector() )
local trace = util.TraceLine( tr )
if (!trace.Hit || trace.Entity:IsPlayer() || trace.Entity:GetClass() == "gmod_wire_radio" ) then
ent:SetNoDraw( true )
return
end
local Ang = trace.HitNormal:Angle()
Ang.pitch = Ang.pitch + 90
2007-02-04 01:16:06 +00:00
ent:SetAngles( Ang )
local min = ent:OBBMins()
ent:SetPos( trace.HitPos - trace.HitNormal * min.z )
2007-02-04 01:16:06 +00:00
ent:SetNoDraw( false )
end
function TOOL:Think()
2007-02-07 04:10:32 +00:00
if (!self.GhostEntity || !self.GhostEntity:IsValid() || self.GhostEntity:GetModel() != self:GetClientInfo( "model" )) then
self:MakeGhostEntity( self:GetClientInfo( "model" ), Vector(0,0,0), Angle(0,0,0) )
2007-02-04 01:16:06 +00:00
end
self:UpdateGhostWireRadio( self.GhostEntity, self:GetOwner() )
end
function TOOL.BuildCPanel(panel)
panel:AddControl("Header", { Text = "#Tool_wire_radio_name", Description = "#Tool_wire_radio_desc" })
panel:AddControl("ComboBox", {
Label = "#Presets",
MenuButton = "1",
Folder = "wire_radio",
Options = {
Default = {
wire_radio_channel = "1",
}
},
CVars = {
[0] = "wire_radio_channel",
}
})
panel:AddControl("Slider", {
Label = "#WireRadioTool_channel",
Type = "Integer",
Min = "1",
Max = "30",
Command = "wire_radio_channel"
})
2007-02-07 04:10:32 +00:00
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"
})
2007-02-04 01:16:06 +00:00
end