Skip to content

Commit

Permalink
Updated nailer
Browse files Browse the repository at this point in the history
Added axis and ballsocket inputs
Fixes #883
  • Loading branch information
Divran committed Mar 28, 2015
1 parent 014369f commit 2af3ede
Showing 1 changed file with 66 additions and 33 deletions.
99 changes: 66 additions & 33 deletions lua/entities/gmod_wire_nailer.lua
Expand Up @@ -15,7 +15,7 @@ function ENT:Initialize()
self:PhysicsInit( SOLID_VPHYSICS )
self:SetMoveType( MOVETYPE_VPHYSICS )
self:SetSolid( SOLID_VPHYSICS )
self.Inputs = Wire_CreateInputs(self, { "A" })
self.Inputs = WireLib.CreateInputs(self, { "Weld", "Axis", "Ballsocket" })
self:SetBeamLength(2048)
end

Expand All @@ -32,44 +32,77 @@ function ENT:CanNail(trace)
-- If there's no physics object then we can't constraint it!
if not util.IsValidPhysicsObject(trace.Entity, trace.PhysicsBone) then return false end
-- The nailer tool no longer exists, but we ask for permission under its name anyway
if not hook.Run( "CanTool", self:GetOwner(), trace, "nailer" ) then return false end
if hook.Run( "CanTool", self:GetPlayer(), trace, "nailer" ) == false then return false end
return true
end

function ENT:TriggerInput(iname, value)
if iname == "A" and value ~= 0 then
local vStart = self:GetPos()
local vForward = self:GetUp()

local trace1 = util.TraceLine {
start = vStart,
endpos = vStart + (vForward * self:GetBeamLength()),
filter = { self }
}
if not self:CanNail(trace1) then return end

local trace2 = util.TraceLine {
start = trace1.HitPos,
endpos = trace1.HitPos + (vForward * 50.0),
filter = { trace1.Entity, self }
}
if not self:CanNail(trace2) then return end

local constraint = constraint.Weld( trace1.Entity, trace2.Entity, trace1.PhysicsBone, trace2.PhysicsBone, self.Flim )

-- effect on weld (tomb332)
local effectdata = EffectData()
effectdata:SetOrigin( trace2.HitPos )
effectdata:SetNormal( trace1.HitNormal )
effectdata:SetMagnitude( 5 )
effectdata:SetScale( 1 )
effectdata:SetRadius( 10 )
util.Effect( "Sparks", effectdata )
function ENT:TriggerInput(name, value)
if value == 0 then return end

local up = self:GetUp()

local trace1 = util.TraceLine( {
start = self:GetPos(),
endpos = self:GetPos() + up * self:GetBeamLength(),
filter = { self }
} )

if not self:CanNail( trace1 ) then return end

local trace2 = util.TraceLine( {
start = trace1.HitPos,
endpos = trace1.HitPos + up * 50,
filter = { trace1.Entity, self }
} )

if not self:CanNail( trace2 ) then return end

if name == "Weld" then
constraint.Weld( trace1.Entity,
trace2.Entity,
trace1.PhysicsBone,
trace2.PhysicsBone,
self.Flim
)
elseif name == "Axis" then
local phys1 = trace1.Entity:GetPhysicsObject()
local phys2 = trace2.Entity:GetPhysicsObject()
if not IsValid( phys1 ) or not IsValid( phys2 ) then return end

local LPos1 = phys1:WorldToLocal( trace2.HitPos + trace2.HitNormal )
local LPos2 = phys2:WorldToLocal( trace2.HitPos )

constraint.Axis( trace1.Entity,
trace2.Entity,
trace1.PhysicsBone,
trace2.PhysicsBone,
LPos1, LPos2,
self.Flim
)
elseif name == "Ballsocket" then
constraint.Ballsocket( trace1.Entity,
trace2.Entity,
trace1.PhysicsBone,
trace2.PhysicsBone,
trace2.Entity:WorldToLocal(trace1.HitPos),
self.Flim
)
end

-- effect on weld (tomb332)
local effectdata = EffectData()
effectdata:SetOrigin( trace2.HitPos )
effectdata:SetNormal( trace1.HitNormal )
effectdata:SetMagnitude( 5 )
effectdata:SetScale( 1 )
effectdata:SetRadius( 10 )
util.Effect( "Sparks", effectdata, false, true )
end

function ENT:ShowOutput()
self:SetOverlayText("Force Limit: " .. self.Flim )
self:SetOverlayText(string.format( "Range: %s\nForce limit: %s", math.Round(self:GetBeamLength(),2), math.Round(self.Flim,2) ))
end

duplicator.RegisterEntityClass("gmod_wire_nailer", WireLib.MakeWireEnt, "Data", "Flim")
WireLib.AddInputAlias( "A", "Weld" )

duplicator.RegisterEntityClass("gmod_wire_nailer", WireLib.MakeWireEnt, "Data", "Flim", "Range", "ShowBeam")

0 comments on commit 2af3ede

Please sign in to comment.