Permalink
Browse files

Tool Updates

* Reduced gap between entities in Axis, Motor, Wheel, Emitter & Weld
Easy tools
* Added ghosting for Hoverball, Emitter, Light & Lamp tools
* Removed useless code parts/Improved code formatting
* Improved positioning for Lamp & Light tools
  • Loading branch information...
1 parent 267608d commit 14ef1cbb0849f27a360f97eba05880fa4b1752f2 @robotboy655 robotboy655 committed Sep 21, 2013
@@ -61,11 +61,7 @@ function TOOL:LeftClick( trace )
Phys1:SetAngles( TargetAngle )
-- Move the object so that the hitpos on our object is at the second hitpos
- local TargetPos = WPos2 + (Phys1:GetPos() - self:GetPos(1))
- local TargetPos = WPos2 + (Phys1:GetPos() - self:GetPos(1)) + (Norm2)
-
- -- Offset slightly so it can rotate
- TargetPos = TargetPos + Norm2
+ local TargetPos = WPos2 + ( Phys1:GetPos() - self:GetPos( 1 ) ) + ( Norm2 * 0.2 )
-- Set the position
Phys1:SetPos( TargetPos )
@@ -144,8 +140,7 @@ function TOOL:RightClick( trace )
--Phys1:SetAngles( TargetAngle )
- local TargetPos = WPos2 + (Phys1:GetPos() - self:GetPos(1)) + (Norm2)
-
+ local TargetPos = WPos2 + ( Phys1:GetPos() - self:GetPos( 1 ) ) + ( Norm2 * 0.2 )
Phys1:Wake()
@@ -12,20 +12,6 @@ TOOL.ClientConVar[ "effect" ] = "sparks"
cleanup.Register( "emitter" )
--- Add Default Language translation (saves adding it to the txt files)
-if ( CLIENT ) then
-
- language.Add( "Tool_emitter_name", "Emitter" )
- language.Add( "Tool_emitter_desc", "Emitter Emits effects eh?" )
- language.Add( "Tool_emitter_0", "Click somewhere to spawn an emitter. Click on an existing emitter to change it." )
-
- language.Add( "Undone_emitter", "Undone Emitter" )
- language.Add( "Cleanup_emitter", "Emitter" )
- language.Add( "Cleaned_emitter", "Cleaned up all Emitters" )
-
-end
-
-
function TOOL:LeftClick( trace, worldweld )
worldweld = worldweld or false
@@ -35,7 +21,7 @@ function TOOL:LeftClick( trace, worldweld )
-- If there's no physics object then we can't constraint it!
if ( SERVER && !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end
- if (CLIENT) then return true end
+ if ( CLIENT ) then return true end
local ply = self:GetOwner()
@@ -46,7 +32,7 @@ function TOOL:LeftClick( trace, worldweld )
local effect = self:GetClientInfo( "effect" )
-- Safe(ish) limits
- delay = math.Clamp( delay, 0.05, 20 )
+ delay = math.Clamp( delay, 0.05, 20 )
-- We shot an existing emitter - just change its values
if ( trace.Entity:IsValid() && trace.Entity:GetClass() == "gmod_emitter" && trace.Entity.pl == ply ) then
@@ -61,25 +47,22 @@ function TOOL:LeftClick( trace, worldweld )
if ( !self:GetSWEP():CheckLimit( "emitters" ) ) then return false end
- if ( trace.Entity != NULL && (!trace.Entity:IsWorld() || worldweld) ) then
-
- trace.HitPos = trace.HitPos + trace.HitNormal * -5
-
- else
-
- trace.HitPos = trace.HitPos + trace.HitNormal * 2
+ local Pos = trace.HitPos
+ if ( trace.Entity != NULL && ( !trace.Entity:IsWorld() || worldweld ) ) then else
+
+ Pos = Pos + trace.HitNormal
end
local Ang = trace.HitNormal:Angle()
Ang:RotateAroundAxis( trace.HitNormal, 0 )
- local emitter = MakeEmitter( ply, key, delay, toggle, effect, starton, nil, nil, nil, nil, { Pos = trace.HitPos, Angle = Ang } )
+ local emitter = MakeEmitter( ply, key, delay, toggle, effect, starton, nil, nil, nil, nil, { Pos = Pos, Angle = Ang } )
local weld
-- Don't weld to world
- if ( trace.Entity != NULL && (!trace.Entity:IsWorld() || worldweld) ) then
+ if ( trace.Entity != NULL && ( !trace.Entity:IsWorld() || worldweld ) ) then
weld = constraint.Weld( emitter, trace.Entity, 0, trace.PhysicsBone, 0, true, true )
@@ -110,7 +93,7 @@ if (SERVER) then
if ( IsValid( ply ) && !ply:CheckLimit( "emitters" ) ) then return nil end
local emitter = ents.Create( "gmod_emitter" )
- if (!emitter:IsValid()) then return false end
+ if ( !emitter:IsValid() ) then return false end
@@ -158,6 +141,37 @@ if (SERVER) then
end
+function TOOL:UpdateGhostEmitter( ent, player )
+
+ if ( !IsValid( ent ) ) then return end
+
+ local tr = util.GetPlayerTrace( player )
+ local trace = util.TraceLine( tr )
+ if ( !trace.Hit ) then return end
+
+ if ( trace.Entity:IsPlayer() || trace.Entity:GetClass() == "gmod_emitter" ) then
+
+ ent:SetNoDraw( true )
+ return
+
+ end
+
+ ent:SetPos( trace.HitPos )
+ ent:SetAngles( trace.HitNormal:Angle() )
+
+ ent:SetNoDraw( false )
+
+end
+
+function TOOL:Think()
+
+ if ( !IsValid( self.GhostEntity ) || self.GhostEntity:GetModel() != /*self:GetClientInfo( "model" )*/ "models/props_lab/tpplug.mdl" ) then
+ self:MakeGhostEntity( "models/props_lab/tpplug.mdl", Vector( 0, 0, 0 ), Angle( 0, 0, 0 ) )
+ end
+
+ self:UpdateGhostEmitter( self.GhostEntity, self:GetOwner() )
+
+end
-- NOTE!! The . instead of : here - there is no 'self' argument!!
-- This is just a function on the table - not a member function!
@@ -150,6 +150,40 @@ if (SERVER) then
end
+function TOOL:UpdateGhostHoverball( ent, player )
+
+ if ( !IsValid( ent ) ) then return end
+
+ local tr = util.GetPlayerTrace( player )
+ local trace = util.TraceLine( tr )
+ if ( !trace.Hit ) then return end
+
+ if ( trace.Entity:IsPlayer() || trace.Entity:GetClass() == "gmod_hoverball" ) then
+
+ ent:SetNoDraw( true )
+ return
+
+ end
+
+ if ( trace.Entity:IsWorld() ) then
+ trace.HitPos = trace.HitPos + trace.HitNormal * 8
+ end
+
+ ent:SetPos( trace.HitPos )
+
+ ent:SetNoDraw( false )
+
+end
+
+function TOOL:Think()
+
+ if ( !IsValid( self.GhostEntity ) || self.GhostEntity:GetModel() != self:GetClientInfo( "model" ) ) then
+ self:MakeGhostEntity( self:GetClientInfo( "model" ), Vector( 0, 0, 0 ), Angle( 0, 0, 0 ) )
+ end
+
+ self:UpdateGhostHoverball( self.GhostEntity, self:GetOwner() )
+
+end
function TOOL.BuildCPanel( CPanel )
@@ -176,6 +210,3 @@ list.Set( "HoverballModels", "models/dav0r/hoverball.mdl", {} )
list.Set( "HoverballModels", "models/MaxOfS2D/hover_rings.mdl", {} )
list.Set( "HoverballModels", "models/MaxOfS2D/hover_classic.mdl", {} )
list.Set( "HoverballModels", "models/MaxOfS2D/hover_basic.mdl", {} )
-list.Set( "HoverballModels", "models/MaxOfS2D/hover_basic.mdl", {} )
-list.Set( "HoverballModels", "models/MaxOfS2D/hover_basic.mdl", {} )
-list.Set( "HoverballModels", "models/MaxOfS2D/hover_basic.mdl", {} )
@@ -22,9 +22,9 @@ function TOOL:LeftClick( trace )
if ( IsValid( trace.Entity ) && trace.Entity:IsPlayer() ) then return false end
if ( CLIENT ) then return true end
-
+
local ply = self:GetOwner()
- local pos, ang = trace.HitPos + trace.HitNormal * 10, trace.HitNormal:Angle()
+ local pos = trace.HitPos
local r = math.Clamp( self:GetClientNumber( "r" ), 0, 255 )
local g = math.Clamp( self:GetClientNumber( "g" ), 0, 255 )
@@ -65,6 +65,12 @@ function TOOL:LeftClick( trace )
lamp = MakeLamp( ply, r, g, b, key, toggle, texture, mdl, fov, distance, bright, !toggle, { Pos = pos, Angle = Angle(0, 0, 0) } )
+ local CurPos = lamp:GetPos()
+ local NearestPoint = lamp:NearestPoint( CurPos - ( trace.HitNormal * 512 ) )
+ local LampOffset = CurPos - NearestPoint
+
+ lamp:SetPos( trace.HitPos + LampOffset )
+
undo.Create("Lamp")
undo.AddEntity( lamp )
undo.SetPlayer( self:GetOwner() )
@@ -156,6 +162,40 @@ if ( SERVER ) then
end
+function TOOL:UpdateGhostLamp( ent, player )
+
+ if ( !IsValid( ent ) ) then return end
+
+ local tr = util.GetPlayerTrace( player )
+ local trace = util.TraceLine( tr )
+ if ( !trace.Hit ) then return end
+
+ if ( trace.Entity:IsPlayer() || trace.Entity:GetClass() == "gmod_lamp" ) then
+
+ ent:SetNoDraw( true )
+ return
+
+ end
+
+ local CurPos = ent:GetPos()
+ local NearestPoint = ent:NearestPoint( CurPos - ( trace.HitNormal * 512 ) )
+ local LampOffset = CurPos - NearestPoint
+
+ ent:SetPos( trace.HitPos + LampOffset )
+
+ ent:SetNoDraw( false )
+
+end
+
+function TOOL:Think()
+
+ if ( !IsValid( self.GhostEntity ) || self.GhostEntity:GetModel() != self:GetClientInfo( "model" ) ) then
+ self:MakeGhostEntity( self:GetClientInfo( "model" ), Vector( 0, 0, 0 ), Angle( 0, 0, 0 ) )
+ end
+
+ self:UpdateGhostLamp( self.GhostEntity, self:GetOwner() )
+
+end
function TOOL.BuildCPanel( CPanel )
@@ -19,15 +19,15 @@ cleanup.Register( "lights" )
function TOOL:LeftClick( trace, attach )
if trace.Entity && trace.Entity:IsPlayer() then return false end
- if (CLIENT) then return true end
- if (attach == nil) then attach = true end
+ if ( CLIENT ) then return true end
+ if ( attach == nil ) then attach = true end
-- If there's no physics object then we can't constraint it!
if ( SERVER && attach && !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end
local ply = self:GetOwner()
- local pos, ang = trace.HitPos + trace.HitNormal * 10, trace.HitNormal:Angle() - Angle( 90, 0, 0 )
+ local pos, ang = trace.HitPos + trace.HitNormal * 8, trace.HitNormal:Angle() - Angle( 90, 0, 0 )
local r = math.Clamp( self:GetClientNumber( "r" ), 0, 255 )
local g = math.Clamp( self:GetClientNumber( "g" ), 0, 255 )
@@ -119,6 +119,38 @@ function TOOL:RightClick( trace )
end
+function TOOL:UpdateGhostLight( ent, player )
+
+ if ( !IsValid( ent ) ) then return end
+
+ local tr = util.GetPlayerTrace( player )
+ local trace = util.TraceLine( tr )
+ if ( !trace.Hit ) then return end
+
+ if ( trace.Entity:IsPlayer() || trace.Entity:GetClass() == "gmod_light" ) then
+
+ ent:SetNoDraw( true )
+ return
+
+ end
+
+ ent:SetPos( trace.HitPos + trace.HitNormal * 8 )
+ ent:SetAngles( trace.HitNormal:Angle() - Angle( 90, 0, 0 ) )
+
+ ent:SetNoDraw( false )
+
+end
+
+function TOOL:Think()
+
+ if ( !IsValid( self.GhostEntity ) || self.GhostEntity:GetModel() != /*self:GetClientInfo( "model" )*/ "models/MaxOfS2D/light_tubular.mdl" ) then
+ self:MakeGhostEntity( "models/MaxOfS2D/light_tubular.mdl", Vector( 0, 0, 0 ), Angle( 0, 0, 0 ) )
+ end
+
+ self:UpdateGhostLight( self.GhostEntity, self:GetOwner() )
+
+end
+
function TOOL.BuildCPanel( CPanel )
-- HEADER
@@ -68,10 +68,7 @@ function TOOL:LeftClick( trace )
Phys1:SetAngles( TargetAngle )
-- Move the object so that the hitpos on our object is at the second hitpos
- local TargetPos = WPos2 + (Phys1:GetPos() - self:GetPos(1))
-
- -- Offset slightly so it can rotate
- TargetPos = TargetPos + (2*Norm2)
+ local TargetPos = WPos2 + ( Phys1:GetPos() - self:GetPos( 1 ) ) + ( Norm2 * 0.2 )
-- Set the position
Phys1:SetPos( TargetPos )
@@ -315,4 +315,4 @@ list.Set( "ThrusterSounds", "#Energy", { thruster_soundname = "combine.sheild_lo
list.Set( "ThrusterSounds", "#Ring Flutter", { thruster_soundname = "k_lab.ringsrotating" } )
list.Set( "ThrusterSounds", "#Resonance", { thruster_soundname = "k_lab.teleport_rings_high" } )
list.Set( "ThrusterSounds", "#Drop Ship", { thruster_soundname = "k_lab2.DropshipRotorLoop" } )
-list.Set( "ThrusterSounds", "#Little Machine", { thruster_soundname = "Town.d1_town_01_spin_loop" } )
+list.Set( "ThrusterSounds", "#Little Machine", { thruster_soundname = "Town.d1_town_01_spin_loop" } )
@@ -74,7 +74,7 @@ function TOOL:RightClick( trace )
Phys1:SetAngles( TargetAngle )
-- Move the object so that the hitpos on our object is at the second hitpos
- local TargetPos = WPos2 + (Phys1:GetPos() - self:GetPos(1)) + (Norm2)
+ local TargetPos = WPos2 + ( Phys1:GetPos() - self:GetPos( 1 ) )
-- Set the position
Phys1:SetPos( TargetPos )
@@ -127,15 +127,15 @@ function TOOL:RightClick( trace )
Phys1:EnableMotion( true )
- undo.Create("Weld")
+ undo.Create( "Weld" )
undo.AddEntity( constraint )
undo.SetPlayer( self:GetOwner() )
undo.Finish()
self:GetOwner():AddCleanup( "constraints", constraint )
local WPos1, WPos2 = self:GetPos(1), self:GetPos(2)
- local Norm1, Norm2 = self:GetNormal(1), self:GetNormal(2)
+ local Norm1, Norm2 = self:GetNormal(1), self:GetNormal(2)
end
@@ -182,19 +182,15 @@ function TOOL:Think()
Phys1:SetAngles( angle )
-- Move so spots join up
- local Norm2 = self:GetNormal(2)
- local TargetPos = WPos2 + (Phys1:GetPos() - self:GetPos(1)) + (Norm2)
+ local Norm2 = self:GetNormal( 2 )
+ local TargetPos = WPos2 + ( Phys1:GetPos() - self:GetPos( 1 ) )
Phys1:SetPos( TargetPos )
Phys1:Wake()
end
end
-
-
-
-
end
function TOOL:Reload( trace )
Oops, something went wrong.

0 comments on commit 14ef1cb

Please sign in to comment.