Nailing props to map

Hello,

Props can be nailed to ground, to wall and to sky. It sometimes can be a problem if its accidentally nailed to map. You have to undo (press z) until its unnailed and this might result in losing half of your work.
I’ve been trying to prevent nailing props to world. No success so far.
A little help would be appreciated.

Thanks in advance,

  • Xev

Can’t you just freeze the prop. reload click to unweld everything from the prop and then reweld it to what it was welded to?

Why can it be a problem?

If you want to stop it though do this:

Goto: garrysmod\garrysmod\gamemodes\sandbox\entities\weapons\gmod_tool\stools
ail.lua

And replace it with this code:

[lua]

TOOL.Category = “Constraints”
TOOL.Name = “#Nail
TOOL.Command = nil
TOOL.ConfigName = nil

TOOL.ClientConVar[“forcelimit”] = “0”

TOOL.RightClickAutomatic = true

cleanup.Register( “nails” )

function TOOL:LeftClick( trace )

// Bail if we hit world or a player
if (  !trace.Entity:IsValid() || trace.Entity:IsPlayer() ) then return false end
if (!trace.Entity:EntIndex() == 0) then return false end	

// If there's no physics object then we can't constraint it!
if ( SERVER && !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end

local tr = {}
	tr.start = trace.HitPos
	tr.endpos = trace.HitPos + (self:GetOwner():GetAimVector() * 16.0)
	tr.filter = { self:GetOwner(), trace.Entity }
local trTwo = util.TraceLine( tr )

if ( trTwo.Hit && !trTwo.Entity:IsPlayer() ) then

	// Get client's CVars
	local forcelimit = self:GetClientNumber( "forcelimit" )

	// Client can bail now
	if ( CLIENT ) then return true end

	local vOrigin = trace.HitPos - (self:GetOwner():GetAimVector() * 8.0)
	local vDirection = self:GetOwner():GetAimVector():Angle()

	vOrigin = trace.Entity:WorldToLocal( vOrigin )

	// Weld them!
	local constraint, nail = MakeNail( trace.Entity, trTwo.Entity, trace.PhysicsBone, trTwo.PhysicsBone, forcelimit, vOrigin, vDirection )
	if !constraint:IsValid() then return end

	undo.Create("Nail")
	undo.AddEntity( constraint )
	undo.AddEntity( nail )
	undo.SetPlayer( self:GetOwner() )
	undo.Finish()

	self:GetOwner():AddCleanup( "nails", constraint )		
	self:GetOwner():AddCleanup( "nails", nail )

	return true

end

end

function MakeNail( Ent1, Ent2, Bone1, Bone2, forcelimit, Pos, Ang )

local constraint = constraint.Weld( Ent1, Ent2, Bone1, Bone2, forcelimit, false )

constraint.Type = "Nail"
constraint.Pos = Pos
constraint.Ang = Ang

Pos = Ent1:LocalToWorld( Pos )

local nail = ents.Create( "gmod_nail" )
	nail:SetPos( Pos )
	nail:SetAngles( Ang )
	nail:SetParentPhysNum( Bone1 )
	nail:SetParent( Ent1 )

nail:Spawn()
nail:Activate()

constraint:DeleteOnRemove( nail )

return constraint, nail

end

duplicator.RegisterConstraint( “Nail”, MakeNail, “Ent1”, “Ent2”, “Bone1”, “Bone2”, “forcelimit”, “Pos”, “Ang” )

function TOOL:RightClick( trace )

self:GetWeapon():SetNextSecondaryFire( CurTime() + 0.2 )
return self:LeftClick( trace )

end

function TOOL:Reload( trace )

if (!trace.Entity:IsValid() || trace.Entity:IsPlayer() ) then return false end
if ( CLIENT ) then return true end

local  bool = constraint.RemoveConstraints( trace.Entity, "Nail" )
return bool

end
[/lua]