2007-02-04 01:16:06 +00:00
|
|
|
|
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:" );
|
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)
|
|
|
|
end
|
|
|
|
|
|
|
|
TOOL.ClientConVar[ "channel" ] = 1
|
2007-02-07 04:10:32 +00:00
|
|
|
TOOL.ClientConVar[ "model" ] = "models/props_lab/binderblue.mdl"
|
|
|
|
|
|
|
|
if (SERVER) then
|
|
|
|
ModelPlug_Register("radio")
|
|
|
|
end
|
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()
|
|
|
|
|
|
|
|
|
|
|
|
// Get client's CVars
|
|
|
|
local _channel = self:GetClientInfo( "channel" )
|
2007-02-07 04:10:32 +00:00
|
|
|
local model = self:GetClientInfo( "model" )
|
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 )
|
2007-02-04 08:20:22 +00:00
|
|
|
trace.Entity:GetTable().channel = _channel
|
2007-02-04 01:16:06 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
if ( !self:GetSWEP():CheckLimit( "wire_radioes" ) ) then return false end
|
|
|
|
|
2007-03-29 01:03:02 +00:00
|
|
|
local Ang = trace.HitNormal:Angle()
|
|
|
|
Ang.pitch = Ang.pitch + 90
|
|
|
|
|
|
|
|
local wire_radio = MakeWireRadio( ply, model, trace.HitPos, Ang, _channel )
|
2007-02-04 01:16:06 +00:00
|
|
|
|
|
|
|
local min = wire_radio:OBBMins()
|
2007-04-12 17:34:02 +00:00
|
|
|
wire_radio:SetPos( trace.HitPos - trace.HitNormal * min.z )
|
2007-03-22 03:27:52 +00:00
|
|
|
|
|
|
|
// Don't weld to world
|
2007-03-28 23:24:55 +00:00
|
|
|
/*local const
|
2007-03-22 03:27:52 +00:00
|
|
|
if ( trace.Entity:IsValid() ) then
|
|
|
|
local const = constraint.Weld( wire_radio, trace.Entity, 0, trace.PhysicsBone, 0, true, true )
|
|
|
|
|
|
|
|
// Don't disable collision if it's not attached to anything
|
|
|
|
if ( collision == 0 ) then
|
|
|
|
wire_radio:GetPhysicsObject():EnableCollisions( false )
|
|
|
|
wire_radio:GetTable().nocollide = true
|
|
|
|
end
|
2007-03-28 23:24:55 +00:00
|
|
|
end*/
|
|
|
|
local const = WireLib.Weld(wire_radio, trace.Entity, trace.PhysicsBone, true)
|
2007-03-22 03:27:52 +00:00
|
|
|
|
2007-02-04 01:16:06 +00:00
|
|
|
undo.Create("WireRadio")
|
|
|
|
undo.AddEntity( wire_radio )
|
|
|
|
undo.SetPlayer( ply )
|
2007-03-22 03:27:52 +00:00
|
|
|
undo.AddEntity(const)
|
2007-02-04 01:16:06 +00:00
|
|
|
undo.Finish()
|
|
|
|
|
|
|
|
|
|
|
|
ply:AddCleanup( "wire_radioes", wire_radio )
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
function TOOL:RightClick( trace )
|
|
|
|
return self:LeftClick( trace )
|
|
|
|
end
|
|
|
|
|
|
|
|
if SERVER then
|
|
|
|
|
2007-02-07 04:10:32 +00:00
|
|
|
function MakeWireRadio(pl, Model, Pos, Ang, channel, 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()
|
|
|
|
|
|
|
|
wire_radio:Setup( channel )
|
|
|
|
wire_radio:SetPlayer( pl )
|
|
|
|
|
|
|
|
local ttable =
|
|
|
|
{
|
2007-02-04 08:20:22 +00:00
|
|
|
channel = channel,
|
2007-02-04 01:16:06 +00:00
|
|
|
pl = pl,
|
|
|
|
nocollide = nocollide,
|
|
|
|
description = description
|
|
|
|
}
|
|
|
|
|
|
|
|
table.Merge( wire_radio:GetTable(), ttable )
|
|
|
|
|
|
|
|
pl:AddCount( "wire_radioes", wire_radio )
|
|
|
|
|
|
|
|
return wire_radio
|
|
|
|
end
|
|
|
|
|
2007-02-07 04:10:32 +00:00
|
|
|
duplicator.RegisterEntityClass("gmod_wire_radio", MakeWireRadio, "Model", "Pos", "Ang", "channel", "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
|
|
|
|
|
2007-03-29 01:03:02 +00:00
|
|
|
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()
|
2007-04-12 17:34:02 +00:00
|
|
|
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")
|
2007-02-04 01:16:06 +00:00
|
|
|
end
|