Skip to content

Commit

Permalink
colored ropes support
Browse files Browse the repository at this point in the history
  • Loading branch information
robotboy655 committed Jun 9, 2021
1 parent f9d774f commit 5d76527
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ TOOL.ClientConVar[ "rdamping" ] = "0.01"
TOOL.ClientConVar[ "material" ] = "cable/cable"
TOOL.ClientConVar[ "width" ] = "2"
TOOL.ClientConVar[ "stretch_only" ] = "1"
TOOL.ClientConVar[ "color_r" ] = "255"
TOOL.ClientConVar[ "color_g" ] = "255"
TOOL.ClientConVar[ "color_b" ] = "255"

TOOL.Information = {
{ name = "left", stage = 0 },
Expand Down Expand Up @@ -43,15 +46,17 @@ function TOOL:LeftClick( trace )
local rdamping = self:GetClientNumber( "rdamping" )
local constant = self:GetClientNumber( "constant" )
local stretchonly = self:GetClientNumber( "stretch_only" )
local colorR = self:GetClientNumber( "color_r" )
local colorG = self:GetClientNumber( "color_g" )
local colorB = self:GetClientNumber( "color_b" )

-- Get information we're about to use
local Ent1, Ent2 = self:GetEnt( 1 ), self:GetEnt( 2 )
local Bone1, Bone2 = self:GetBone( 1 ), self:GetBone( 2 )
local LPos1, LPos2 = self:GetLocalPos( 1 ), self:GetLocalPos( 2 )
local constraint, rope = constraint.Elastic( Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, constant, damping, rdamping, material, width, stretchonly )
local constraint, rope = constraint.Elastic( Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, constant, damping, rdamping, material, width, stretchonly, Color( colorR, colorG, colorB, 255 ) )

-- Add The constraint to the players undo table

undo.Create( "Elastic" )
if ( IsValid( constraint ) ) then undo.AddEntity( constraint ) end
if ( IsValid( rope ) ) then undo.AddEntity( rope ) end
Expand Down Expand Up @@ -104,5 +109,6 @@ function TOOL.BuildCPanel( CPanel )

CPanel:AddControl( "Slider", { Label = "#tool.elastic.width", Command = "elastic_width", Type = "Float", Min = 0, Max = 20 } )
CPanel:AddControl( "RopeMaterial", { Label = "#tool.elastic.material", ConVar = "elastic_material" } )
CPanel:AddControl( "Color", { Label = "#tool.elastic.color", Red = "elastic_color_r", Green = "elastic_color_g", Blue = "elastic_color_b" } )

end
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ TOOL.ClientConVar[ "fixed" ] = "1"
TOOL.ClientConVar[ "speed" ] = "64"
TOOL.ClientConVar[ "toggle" ] = "1"
TOOL.ClientConVar[ "material" ] = "cable/rope"
TOOL.ClientConVar[ "color_r" ] = "255"
TOOL.ClientConVar[ "color_g" ] = "255"
TOOL.ClientConVar[ "color_b" ] = "255"

TOOL.Information = {
{ name = "left", stage = 0 },
Expand Down Expand Up @@ -52,6 +55,9 @@ function TOOL:LeftClick( trace )
local speed = self:GetClientNumber( "speed", 64 )
local material = self:GetClientInfo( "material" )
local toggle = self:GetClientNumber( "toggle" ) != 0
local colorR = self:GetClientNumber( "color_r" )
local colorG = self:GetClientNumber( "color_g" )
local colorB = self:GetClientNumber( "color_b" )

-- Get information we're about to use
local Ent1, Ent2 = self:GetEnt( 1 ), self:GetEnt( 2 )
Expand All @@ -62,7 +68,7 @@ function TOOL:LeftClick( trace )
local Length1 = ( WPos1 - WPos2 ):Length()
local Length2 = Length1 + AddLength

local constraint, rope, controller, slider = constraint.Hydraulic( self:GetOwner(), Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, Length1, Length2, width, bind, fixed, speed, material, toggle )
local constraint, rope, controller, slider = constraint.Hydraulic( self:GetOwner(), Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, Length1, Length2, width, bind, fixed, speed, material, toggle, Color( colorR, colorG, colorB, 255 ) )

undo.Create( "Hydraulic" )
if ( IsValid( constraint ) ) then undo.AddEntity( constraint ) end
Expand Down Expand Up @@ -153,6 +159,9 @@ function TOOL:RightClick( trace )
local speed = self:GetClientNumber( "speed", 64 )
local material = self:GetClientInfo( "material" )
local toggle = self:GetClientNumber( "toggle" ) != 0
local colorR = self:GetClientNumber( "color_r" )
local colorG = self:GetClientNumber( "color_g" )
local colorB = self:GetClientNumber( "color_b" )

-- Get information we're about to use
local Ent1, Ent2 = self:GetEnt( 1 ), self:GetEnt( 2 )
Expand All @@ -163,7 +172,7 @@ function TOOL:RightClick( trace )
local Length1 = ( WPos1 - WPos2 ):Length()
local Length2 = Length1 + AddLength

local constraint, rope, controller, slider = constraint.Hydraulic( self:GetOwner(), Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, Length1, Length2, width, bind, fixed, speed, material, toggle )
local constraint, rope, controller, slider = constraint.Hydraulic( self:GetOwner(), Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, Length1, Length2, width, bind, fixed, speed, material, toggle, Color( colorR, colorG, colorB, 255 ) )

undo.Create( "Hydraulic" )
if ( IsValid( constraint ) ) then undo.AddEntity( constraint ) end
Expand Down Expand Up @@ -216,5 +225,6 @@ function TOOL.BuildCPanel( CPanel )

CPanel:AddControl( "Slider", { Label = "#tool.hydraulic.width", Command = "hydraulic_width", Type = "Float", Min = 0, Max = 5 } )
CPanel:AddControl( "RopeMaterial", { Label = "#tool.hydraulic.material", ConVar = "hydraulic_material" } )
CPanel:AddControl( "Color", { Label = "#tool.hydraulic.color", Red = "hydraulic_color_r", Green = "hydraulic_color_g", Blue = "hydraulic_color_b" } )

end
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ TOOL.ClientConVar[ "fixed" ] = "1"
TOOL.ClientConVar[ "period" ] = "1"
TOOL.ClientConVar[ "material" ] = "cable/rope"
TOOL.ClientConVar[ "starton" ] = "0"
TOOL.ClientConVar[ "color_r" ] = "255"
TOOL.ClientConVar[ "color_g" ] = "255"
TOOL.ClientConVar[ "color_b" ] = "255"

TOOL.Information = {
{ name = "left", stage = 0 },
Expand Down Expand Up @@ -52,6 +55,9 @@ function TOOL:LeftClick( trace )
local period = self:GetClientNumber( "period", 1 )
local starton = self:GetClientNumber( "starton" ) == 1
local material = self:GetClientInfo( "material" )
local colorR = self:GetClientNumber( "color_r" )
local colorG = self:GetClientNumber( "color_g" )
local colorB = self:GetClientNumber( "color_b" )

-- If AddLength is 0 then what's the point.
if ( AddLength == 0 ) then
Expand All @@ -74,7 +80,7 @@ function TOOL:LeftClick( trace )

local amp = Length2 - Length1

local constraint, rope, controller, slider = constraint.Muscle( self:GetOwner(), Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, Length1, Length2, width, bind, fixed, period, amp, starton, material )
local constraint, rope, controller, slider = constraint.Muscle( self:GetOwner(), Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, Length1, Length2, width, bind, fixed, period, amp, starton, material, Color( colorR, colorG, colorB, 255 ) )

undo.Create( "Muscle" )
if ( IsValid( constraint ) ) then undo.AddEntity( constraint ) end
Expand Down Expand Up @@ -161,6 +167,9 @@ function TOOL:RightClick( trace )
local period = self:GetClientNumber( "period", 64 )
local starton = self:GetClientNumber( "starton" )
local material = self:GetClientInfo( "material" )
local colorR = self:GetClientNumber( "color_r" )
local colorG = self:GetClientNumber( "color_g" )
local colorB = self:GetClientNumber( "color_b" )

-- Get information we're about to use
local Ent1, Ent2 = self:GetEnt( 1 ), self:GetEnt( 2 )
Expand All @@ -173,7 +182,7 @@ function TOOL:RightClick( trace )

local amp = Length2 - Length1

local constraint, rope, controller, slider = constraint.Muscle( self:GetOwner(), Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, Length1, Length2, width, bind, fixed, period, amp, starton, material )
local constraint, rope, controller, slider = constraint.Muscle( self:GetOwner(), Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, Length1, Length2, width, bind, fixed, period, amp, starton, material, Color( colorR, colorG, colorB, 255 ) )

undo.Create( "Muscle" )
if ( IsValid( constraint ) ) then undo.AddEntity( constraint ) end
Expand Down Expand Up @@ -226,5 +235,6 @@ function TOOL.BuildCPanel( CPanel )

CPanel:AddControl( "Slider", { Label = "#tool.muscle.width", Command = "muscle_width", Type = "Float", Min = 0, Max = 5 } )
CPanel:AddControl( "RopeMaterial", { Label = "#tool.muscle.material", ConVar = "muscle_material" } )
CPanel:AddControl( "Color", { Label = "#tool.muscle.color", Red = "muscle_color_r", Green = "muscle_color_g", Blue = "muscle_color_b" } )

end
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ TOOL.ClientConVar[ "width" ] = "3"
TOOL.ClientConVar[ "forcelimit" ] = "0"
TOOL.ClientConVar[ "rigid" ] = "0"
TOOL.ClientConVar[ "material" ] = "cable/cable"
TOOL.ClientConVar[ "color_r" ] = "255"
TOOL.ClientConVar[ "color_g" ] = "255"
TOOL.ClientConVar[ "color_b" ] = "255"

TOOL.Information = {
{ name = "left", stage = 0 },
Expand Down Expand Up @@ -36,6 +39,9 @@ function TOOL:LeftClick( trace )
local forcelimit = self:GetClientNumber( "forcelimit" )
local rigid = self:GetClientNumber( "rigid" ) == 1
local material = self:GetClientInfo( "material" )
local colorR = self:GetClientNumber( "color_r" )
local colorG = self:GetClientNumber( "color_g" )
local colorB = self:GetClientNumber( "color_b" )

-- Get information we're about to use
local Ent1 = self:GetEnt( 1 )
Expand All @@ -47,7 +53,7 @@ function TOOL:LeftClick( trace )
local WPos2 = self:GetPos( 2 )
local WPos3 = self:GetPos( 3 )

local constraint = constraint.Pulley( Ent1, Ent4, Bone1, Bone4, LPos1, LPos4, WPos2, WPos3, forcelimit, rigid, width, material )
local constraint, rop1, rop2, rop3 = constraint.Pulley( Ent1, Ent4, Bone1, Bone4, LPos1, LPos4, WPos2, WPos3, forcelimit, rigid, width, material, Color( colorR, colorG, colorB, 255 ) )

undo.Create( "Pulley" )
undo.AddEntity( constraint )
Expand Down Expand Up @@ -96,5 +102,6 @@ function TOOL.BuildCPanel( CPanel )

CPanel:AddControl( "Slider", { Label = "#tool.pulley.width", Command = "pulley_width", Type = "Float", Min = 0, Max = 10 } )
CPanel:AddControl( "RopeMaterial", { Label = "#tool.pulley.material", ConVar = "pulley_material" } )
CPanel:AddControl( "Color", { Label = "#tool.pulley.color", Red = "pulley_color_r", Green = "pulley_color_g", Blue = "pulley_color_b" } )

end
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ TOOL.ClientConVar[ "addlength" ] = "0"
TOOL.ClientConVar[ "material" ] = "cable/rope"
TOOL.ClientConVar[ "width" ] = "2"
TOOL.ClientConVar[ "rigid" ] = "0"
TOOL.ClientConVar[ "color_r" ] = "255"
TOOL.ClientConVar[ "color_g" ] = "255"
TOOL.ClientConVar[ "color_b" ] = "255"

TOOL.Information = {
{ name = "left", stage = 0 },
Expand Down Expand Up @@ -43,19 +46,23 @@ function TOOL:LeftClick( trace )
local width = self:GetClientNumber( "width" )
local rigid = self:GetClientNumber( "rigid" ) == 1

local colorR = self:GetClientNumber( "color_r" )
local colorG = self:GetClientNumber( "color_g" )
local colorB = self:GetClientNumber( "color_b" )

-- Get information we're about to use
local Ent1, Ent2 = self:GetEnt( 1 ), self:GetEnt( 2 )
local Bone1, Bone2 = self:GetBone( 1 ), self:GetBone( 2 )
local WPos1, WPos2 = self:GetPos( 1 ), self:GetPos( 2 )
local LPos1, LPos2 = self:GetLocalPos( 1 ), self:GetLocalPos( 2 )
local length = ( WPos1 - WPos2 ):Length()

local constraint, rope = constraint.Rope( Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, length, addlength, forcelimit, width, material, rigid )
local constraint, rope = constraint.Rope( Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, length, addlength, forcelimit, width, material, rigid, Color( colorR, colorG, colorB, 255 ) )

-- Clear the objects so we're ready to go again
self:ClearObjects()

-- Add The constraint to the players undo table
-- Add the constraint to the players undo table

undo.Create( "Rope" )
undo.AddEntity( constraint )
Expand Down Expand Up @@ -101,14 +108,18 @@ function TOOL:RightClick( trace )
local width = self:GetClientNumber( "width" )
local rigid = self:GetClientNumber( "rigid" ) == 1

local colorR = self:GetClientNumber( "color_r" )
local colorG = self:GetClientNumber( "color_g" )
local colorB = self:GetClientNumber( "color_b" )

-- Get information we're about to use
local Ent1, Ent2 = self:GetEnt( 1 ), self:GetEnt( 2 )
local Bone1, Bone2 = self:GetBone( 1 ), self:GetBone( 2 )
local WPos1, WPos2 = self:GetPos( 1 ), self:GetPos( 2 )
local LPos1, LPos2 = self:GetLocalPos( 1 ), self:GetLocalPos( 2 )
local length = ( WPos1 - WPos2 ):Length()

local constraint, rope = constraint.Rope( Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, length, addlength, forcelimit, width, material, rigid )
local constraint, rope = constraint.Rope( Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, length, addlength, forcelimit, width, material, rigid, Color( colorR, colorG, colorB, 255 ) )

-- Clear the objects and set the last object as object 1
self:ClearObjects()
Expand All @@ -117,7 +128,7 @@ function TOOL:RightClick( trace )
self:SetObject( iNum + 1, Ent2, trace.HitPos, Phys, Bone2, trace.HitNormal )
self:SetStage( iNum + 1 )

-- Add The constraint to the players undo table
-- Add the constraint to the players undo table
undo.Create( "Rope" )
undo.AddEntity( constraint )
if ( IsValid( rope ) ) then undo.AddEntity( rope ) end
Expand Down Expand Up @@ -168,4 +179,6 @@ function TOOL.BuildCPanel( CPanel )
CPanel:AddControl( "Slider", { Label = "#tool.rope.width", Command = "rope_width", Type = "Float", Min = 0, Max = 10 } )
CPanel:AddControl( "RopeMaterial", { Label = "#tool.rope.material", ConVar = "rope_material" } )

CPanel:AddControl( "Color", { Label = "#tool.rope.color", Red = "rope_color_r", Green = "rope_color_g", Blue = "rope_color_b" } )

end
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ TOOL.Name = "#tool.slider.name"

TOOL.ClientConVar[ "width" ] = "1.5"
TOOL.ClientConVar[ "material" ] = "cable/cable"
TOOL.ClientConVar[ "color_r" ] = "255"
TOOL.ClientConVar[ "color_g" ] = "255"
TOOL.ClientConVar[ "color_b" ] = "255"

TOOL.Information = {
{ name = "left", stage = 0 },
Expand Down Expand Up @@ -36,12 +39,16 @@ function TOOL:LeftClick( trace )
local width = self:GetClientNumber( "width", 1.5 )
local material = self:GetClientInfo( "material" )

local colorR = self:GetClientNumber( "color_r" )
local colorG = self:GetClientNumber( "color_g" )
local colorB = self:GetClientNumber( "color_b" )

-- Get information we're about to use
local Ent1, Ent2 = self:GetEnt( 1 ), self:GetEnt( 2 )
local Bone1, Bone2 = self:GetBone( 1 ), self:GetBone( 2 )
local LPos1, LPos2 = self:GetLocalPos( 1 ), self:GetLocalPos( 2 )

local constraint, rope = constraint.Slider( Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, width, material )
local constraint, rope = constraint.Slider( Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, width, material, Color( colorR, colorG, colorB, 255 ) )

undo.Create( "Slider" )
if ( IsValid( constraint ) ) then undo.AddEntity( constraint ) end
Expand Down Expand Up @@ -119,12 +126,16 @@ function TOOL:RightClick( trace )
local width = self:GetClientNumber( "width", 1.5 )
local material = self:GetClientInfo( "material" )

local colorR = self:GetClientNumber( "color_r" )
local colorG = self:GetClientNumber( "color_g" )
local colorB = self:GetClientNumber( "color_b" )

-- Get information we're about to use
local Ent1, Ent2 = self:GetEnt( 1 ), self:GetEnt( 2 )
local Bone1, Bone2 = self:GetBone( 1 ), self:GetBone( 2 )
local LPos1, LPos2 = self:GetLocalPos( 1 ), self:GetLocalPos( 2 )

local constraint, rope = constraint.Slider( Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, width, material )
local constraint, rope = constraint.Slider( Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, width, material, Color( colorR, colorG, colorB, 255 ) )

undo.Create( "Slider" )
if ( IsValid( constraint ) ) then undo.AddEntity( constraint ) end
Expand Down Expand Up @@ -168,4 +179,6 @@ function TOOL.BuildCPanel( CPanel )
CPanel:AddControl( "Slider", { Label = "#tool.slider.width", Command = "slider_width", Type = "Float", Min = 0, Max = 10 } )
CPanel:AddControl( "RopeMaterial", { Label = "#tool.slider.material", ConVar = "slider_material" } )

CPanel:AddControl( "Color", { Label = "#tool.slider.color", Red = "slider_color_r", Green = "slider_color_g", Blue = "slider_color_b" } )

end
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ TOOL.ClientConVar[ "fwd_speed" ] = "64"
TOOL.ClientConVar[ "bwd_speed" ] = "64"
TOOL.ClientConVar[ "fwd_group" ] = "44"
TOOL.ClientConVar[ "bwd_group" ] = "41"
TOOL.ClientConVar[ "color_r" ] = "255"
TOOL.ClientConVar[ "color_g" ] = "255"
TOOL.ClientConVar[ "color_b" ] = "255"

TOOL.Information = {
{ name = "left", stage = 0 },
Expand Down Expand Up @@ -43,14 +46,17 @@ function TOOL:LeftClick( trace )
local bwd_bind = self:GetClientNumber( "bwd_group", 41 )
local fwd_speed = self:GetClientNumber( "fwd_speed", 64 )
local bwd_speed = self:GetClientNumber( "bwd_speed", 64 )
local colorR = self:GetClientNumber( "color_r" )
local colorG = self:GetClientNumber( "color_g" )
local colorB = self:GetClientNumber( "color_b" )
local toggle = false

-- Get information we're about to use
local Ent1, Ent2 = self:GetEnt( 1 ), self:GetEnt( 2 )
local Bone1, Bone2 = self:GetBone( 1 ), self:GetBone( 2 )
local LPos1, LPos2 = self:GetLocalPos( 1 ), self:GetLocalPos( 2 )

local constraint, rope, controller = constraint.Winch( self:GetOwner(), Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, width, fwd_bind, bwd_bind, fwd_speed, bwd_speed, material, toggle )
local constraint, rope, controller = constraint.Winch( self:GetOwner(), Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, width, fwd_bind, bwd_bind, fwd_speed, bwd_speed, material, toggle, Color( colorR, colorG, colorB, 255 ) )

undo.Create( "Winch" )
if ( IsValid( constraint ) ) then undo.AddEntity( constraint ) end
Expand Down Expand Up @@ -137,13 +143,16 @@ function TOOL:RightClick( trace )
local bwd_bind = self:GetClientNumber( "bwd_group", 41 )
local fwd_speed = self:GetClientNumber( "fwd_speed", 64 )
local bwd_speed = self:GetClientNumber( "bwd_speed", 64 )
local colorR = self:GetClientNumber( "color_r" )
local colorG = self:GetClientNumber( "color_g" )
local colorB = self:GetClientNumber( "color_b" )

-- Get information we're about to use
local Ent1, Ent2 = self:GetEnt( 1 ), self:GetEnt( 2 )
local Bone1, Bone2 = self:GetBone( 1 ), self:GetBone( 2 )
local LPos1, LPos2 = self:GetLocalPos( 1 ), self:GetLocalPos( 2 )

local constraint, rope, controller = constraint.Winch( self:GetOwner(), Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, width, fwd_bind, bwd_bind, fwd_speed, bwd_speed, material )
local constraint, rope, controller = constraint.Winch( self:GetOwner(), Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, width, fwd_bind, bwd_bind, fwd_speed, bwd_speed, material, Color( colorR, colorG, colorB, 255 ) )

undo.Create( "Winch" )
if ( IsValid( constraint ) ) then undo.AddEntity( constraint ) end
Expand Down Expand Up @@ -187,5 +196,6 @@ function TOOL.BuildCPanel( CPanel )
CPanel:AddControl( "Slider", { Label = "#tool.winch.width", Command = "winch_rope_width", Type = "Float", Min = 0, Max = 10 } )

CPanel:AddControl( "RopeMaterial", { Label = "#tool.winch.material", ConVar = "winch_rope_material" } )
CPanel:AddControl( "Color", { Label = "#tool.winch.color", Red = "winch_color_r", Green = "winch_color_g", Blue = "winch_color_b" } )

end
Loading

2 comments on commit 5d76527

@thegrb93
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robotboy655 rope with 0 width makes CreateKeyframeRope return nil and then errors at SetColor. Should check both rope and color aren't nil.

@robotboy655
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thegrb93 It is already fixed on dev beta.

Please sign in to comment.