Problem with my handcuffs

Hi,

Few days ago i tried to edit handcuffs for my dark rp server and i’m going mad…
I try to make when someone is handcuffed he recover all his weapons before be handcuffed. But he recovered only these weapons :


 			tr.Entity:Give("weapon_physgun")
			tr.Entity:Give("gmod_camera")
			tr.Entity:Give("gmod_tool")
			tr.Entity:Give("pocket")
			tr.Entity:Give("keys") 

Can you help me please, i would like the player if he has a weapon he recover it, etc…

All the code past here :



if SERVER then

	AddCSLuaFile( "shared.lua" )
	
	resource.AddFile("materials/katharsmodels/handcuffs/handcuffs_body.vmf")
	resource.AddFile("materials/katharsmodels/handcuffs/handcuffs_body.vtf")
	resource.AddFile("materials/katharsmodels/handcuffs/handcuffs_claw.vmf")
	resource.AddFile("materials/katharsmodels/handcuffs/handcuffs_claw.vtf")
	resource.AddFile("models/katharsmodels/handcuffs/handcuffs-1.mdl")
	resource.AddFile("models/katharsmodels/handcuffs/handcuffs-3.mdl")
	resource.AddFile("materials/katharsmodels/handcuffs/handcuffs_extras.vmf")
	resource.AddFile("materials/katharsmodels/handcuffs/handcuffs_extras.vtf")
	
end
---------------------------------------------------------------------------|
SWEP.Author   	    	= "Buzzofwar"
SWEP.Contact        	= "Buzzofwar"
SWEP.PrintName			= "Handcuffs"
SWEP.Purpose        	= "To make it difficult for others to run away"
SWEP.Instructions   	= "Left click to put cuffs on. Right click to take take cuffs off."
SWEP.Spawnable      	= true
SWEP.AdminSpawnable 	= true
SWEP.HoldType 			= "none"  
SWEP.Category 			= "Police Pack"    
SWEP.ViewModel      	= "models/katharsmodels/handcuffs/handcuffs-1.mdl"
SWEP.WorldModel   		= "models/weapons/w_stunbaton.mdl"
---------------------------------------------------------------------------|

-----------------------------Primary Info----------------------------------|
SWEP.Primary.NumShots		= 1	
SWEP.Primary.Delay			= 0.9 	
SWEP.Primary.Recoil			= 0	
SWEP.Primary.Ammo         	= "none"	
SWEP.Primary.Damage			= 0	
SWEP.Primary.Cone			= 0 	
SWEP.Primary.ClipSize		= -1	
SWEP.Primary.DefaultClip	= -1	
SWEP.Primary.Automatic   	= false	
-----------------------------Primary Info----------------------------------|

----------------------------Secondary Info---------------------------------|
SWEP.Secondary.Delay		= 0.9
SWEP.Secondary.Recoil		= 0
SWEP.Secondary.Damage		= 0
SWEP.Secondary.NumShots		= 1
SWEP.Secondary.Cone			= 0
SWEP.Secondary.ClipSize		= -1
SWEP.Secondary.DefaultClip	= -1
SWEP.Secondary.Automatic   	= false
SWEP.Secondary.Ammo         = "none"
----------------------------Secondary Info---------------------------------|

---------------------------------------------------------------------------|
 function SWEP:Reload()
end 
---------------------------------------------------------------------------|

---------------------------------------------------------------------------|
 if ( CLIENT ) then
	function SWEP:GetViewModelPosition( pos, ang )
		ang:RotateAroundAxis( ang:Forward(), 90 ) 
		pos = pos + ang:Forward()*6
		return pos, ang
	end 
end
---------------------------------------------------------------------------|

---------------------------------------------------------------------------|
function SWEP:Think()
end
---------------------------------------------------------------------------|

-----------------------------Initialize------------------------------------|
function SWEP:Initialize()
	self:SetWeaponHoldType(self.HoldType)
	if ( SERVER ) then
    self:SetWeaponHoldType(self.HoldType)
	end
end
-----------------------------Initialize------------------------------------|
function Slow( ply )
    ply:SetWalkSpeed( 50 )
end

-----------------------------PrimaryAttack---------------------------------|
function SWEP:PrimaryAttack()
	local trace = { }
	trace.start = self.Owner:EyePos();
	trace.endpos = trace.start + self.Owner:GetAimVector() * 95;
	trace.filter = self.Owner;
		
	
	local tr = util.TraceLine( trace );
	
	if( tr.Entity:IsValid() and ( tr.Entity:IsPlayer() ) ) then
		if( tr.Entity:GetNWBool( "FrozenYay" ) == true ) then
			return; end
		tr.Entity:SetNWBool( "FrozenYay", true )
		self.Owner:PrintMessage	(HUD_PRINTCENTER,"Player Has Been Handcuffed.")
		tr.Entity:PrintMessage	(HUD_PRINTCENTER,"You Have Been Handcuffed.")
		self.Owner:EmitSound("npc/metropolice/vo/holdit.wav", 50, 100)
		tr.Entity:EmitSound("npc/metropolice/vo/holdit.wav", 50, 100)

		tr.Entity:SetWalkSpeed(20)
		tr.Entity:SetRunSpeed(20)
		
		     if not IsValid(self.Owner) then return end
        self.IsWeaponChecking = false

        if CLIENT then return end
        local result = ""
        local stripped = {}
        local trace = self.Owner:GetEyeTrace()
        if not IsValid(trace.Entity) or not trace.Entity:IsPlayer() then return end
        for k,v in pairs(trace.Entity:GetWeapons()) do
                local class = v:GetClass()
     
      
                   
           

                if SERVER then

                trace.Entity:StripWeapon(class)
                result = result..", "..class
                table.insert(stripped, {class, trace.Entity:GetAmmoCount(v:GetPrimaryAmmoType()),
                v:GetPrimaryAmmoType(), trace.Entity:GetAmmoCount(v:GetSecondaryAmmoType()), v:GetSecondaryAmmoType(),
                v:Clip1(), v:Clip2()})
       end
	   end
	   end
	   end
	   
		
-----------------------------PrimaryAttack---------------------------------|

----------------------------SecondaryAttack--------------------------------|
function SWEP:SecondaryAttack()
	if SERVER then
	local trace = { }
	trace.start = self.Owner:EyePos();
	trace.endpos = trace.start + self.Owner:GetAimVector() * 95;
	trace.filter = self.Owner;
		
	local tr = util.TraceLine( trace );
		
	if ( tr.Entity:IsValid() and ( tr.Entity:IsPlayer() ) ) then
		if( tr.Entity:GetNWBool( "FrozenYay" ) == true ) then
			tr.Entity:SetNWBool( "FrozenYay", false )
			tr.Entity:SetWalkSpeed(160)
			tr.Entity:SetRunSpeed(240)
			tr.Entity:Give("weapon_physgun")
			tr.Entity:Give("gmod_camera")
			tr.Entity:Give("gmod_tool")
			tr.Entity:Give("pocket")
			tr.Entity:Give("keys")
		self.Owner:EmitSound("npc/metropolice/vo/getoutofhere.wav", 50, 100)
		tr.Entity:EmitSound("npc/metropolice/vo/getoutofhere.wav", 50, 100)

		else
			self.Owner:PrintMessage( HUD_PRINTCENTER, "Player isn't handcuffed." );
			tr.Entity:PrintMessage(HUD_PRINTCENTER,"You Have Been Released.");
			
		end
	end
end
end


Thank you very much if you help me !

Store the players weapons in a table when they get handcuffed, then give each weapon in the table when they they are being unhandcuffed?

Why not make the handcuffs a weapon the player can’t switch away from ( return false in SWEP:Holster( ) ), and remove the weapon from the player when they are no longer cuffed?

Yes i don’t know how to make that, but i’ll try… :slight_smile:

Doesn’t work for me … I don’t know why…

look at darkrps native sleep module, it already has a method for saving all your weapons when you go to sleep and giving them back when you wake up, all you need to do is copy it over to your swep and your all good

Ok i try too !

Doesn’t work too…

[editline]30th June 2014[/editline]

I think i’m going to find the solution ! I’ve modified the code :



if SERVER then
 
        AddCSLuaFile( "shared.lua" )
       
        resource.AddFile("materials/katharsmodels/handcuffs/handcuffs_body.vmf")
        resource.AddFile("materials/katharsmodels/handcuffs/handcuffs_body.vtf")
        resource.AddFile("materials/katharsmodels/handcuffs/handcuffs_claw.vmf")
        resource.AddFile("materials/katharsmodels/handcuffs/handcuffs_claw.vtf")
        resource.AddFile("models/katharsmodels/handcuffs/handcuffs-1.mdl")
        resource.AddFile("models/katharsmodels/handcuffs/handcuffs-3.mdl")
        resource.AddFile("materials/katharsmodels/handcuffs/handcuffs_extras.vmf")
        resource.AddFile("materials/katharsmodels/handcuffs/handcuffs_extras.vtf")
       
end
---------------------------------------------------------------------------|
SWEP.Author             = "None"
SWEP.Contact            = "None"
SWEP.PrintName                  = "Handcuffs"
SWEP.Purpose            = "To make it difficult for others to run away"
SWEP.Instructions       = "Left click to put cuffs on. Right click to take take cuffs off."
SWEP.Spawnable          = true
SWEP.AdminSpawnable     = true
SWEP.HoldType                   = "none"    
SWEP.ViewModel          = "models/katharsmodels/handcuffs/handcuffs-1.mdl"
SWEP.WorldModel                 = "models/weapons/w_stunbaton.mdl"
---------------------------------------------------------------------------|
 
-----------------------------Primary Info----------------------------------|
SWEP.Primary.NumShots           = 1    
SWEP.Primary.Delay                      = 0.9  
SWEP.Primary.Recoil                     = 0    
SWEP.Primary.Ammo               = "none"       
SWEP.Primary.Damage                     = 0    
SWEP.Primary.Cone                       = 0    
SWEP.Primary.ClipSize           = -1   
SWEP.Primary.DefaultClip        = -1   
SWEP.Primary.Automatic          = false
-----------------------------Primary Info----------------------------------|
 
----------------------------Secondary Info---------------------------------|
SWEP.Secondary.Delay            = 0.9
SWEP.Secondary.Recoil           = 0
SWEP.Secondary.Damage           = 0
SWEP.Secondary.NumShots         = 1
SWEP.Secondary.Cone                     = 0
SWEP.Secondary.ClipSize         = -1
SWEP.Secondary.DefaultClip      = -1
SWEP.Secondary.Automatic        = false
SWEP.Secondary.Ammo         = "none"
----------------------------Secondary Info---------------------------------|
 
---------------------------------------------------------------------------|
 function SWEP:Reload()
end
---------------------------------------------------------------------------|
 
---------------------------------------------------------------------------|
 if ( CLIENT ) then
        function SWEP:GetViewModelPosition( pos, ang )
                ang:RotateAroundAxis( ang:Forward(), 90 )
                pos = pos + ang:Forward()*6
                return pos, ang
        end
end
---------------------------------------------------------------------------|
 
---------------------------------------------------------------------------|
function SWEP:Think()
end
---------------------------------------------------------------------------|
 
-----------------------------Initialize------------------------------------|
function SWEP:Initialize()
        self:SetWeaponHoldType(self.HoldType)
        if ( SERVER ) then
    self:SetWeaponHoldType(self.HoldType)
        end
end
-----------------------------Initialize------------------------------------|
function Slow( ply )
    ply:SetWalkSpeed( 50 )
end
 
-----------------------------PrimaryAttack---------------------------------|
function SWEP:PrimaryAttack()
        local trace = { }
        trace.start = self.Owner:EyePos();
        trace.endpos = trace.start + self.Owner:GetAimVector() * 95;
        trace.filter = self.Owner;
               
       
        local tr = util.TraceLine( trace );
       
        if( tr.Entity:IsValid() and ( tr.Entity:IsPlayer() ) ) then
                if( tr.Entity:GetNWBool( "FrozenYay" ) == true ) then
                        return; end
                tr.Entity:SetNWBool( "FrozenYay", true )
                self.Owner:PrintMessage (HUD_PRINTCENTER,"Player Has Been Handcuffed.")
                tr.Entity:PrintMessage  (HUD_PRINTCENTER,"You Have Been Handcuffed.")
                self.Owner:EmitSound("npc/metropolice/vo/holdit.wav", 50, 100)
                tr.Entity:EmitSound("npc/metropolice/vo/holdit.wav", 50, 100)
 
                tr.Entity:SetWalkSpeed(20)
                tr.Entity:SetRunSpeed(20)
                        tr.Entity.OldWeapon = tr.Entity:GetWeapons()
                     if not IsValid(self.Owner) then return end
        self.IsWeaponChecking = false
 
 
        if CLIENT then return end
        local result = ""
        local stripped = {}
        local trace = self.Owner:GetEyeTrace()
        if not IsValid(trace.Entity) or not trace.Entity:IsPlayer() then return end
        for k,v in pairs(trace.Entity:GetWeapons()) do
                local class = v:GetClass()
     
     
                   
           
 
                if SERVER then
 
                trace.Entity:StripWeapon(class)
                result = result..", "..class
                table.insert(stripped, {class, trace.Entity:GetAmmoCount(v:GetPrimaryAmmoType()),
                v:GetPrimaryAmmoType(), trace.Entity:GetAmmoCount(v:GetSecondaryAmmoType()), v:GetSecondaryAmmoType(),
                v:Clip1(), v:Clip2()})
       end
           end
           end
           end
               
-----------------------------PrimaryAttack---------------------------------|
 
----------------------------SecondaryAttack--------------------------------|
function SWEP:SecondaryAttack()
        if SERVER then
        local trace = { }
        trace.start = self.Owner:EyePos();
        trace.endpos = trace.start + self.Owner:GetAimVector() * 95;
        trace.filter = self.Owner;
               
        local tr = util.TraceLine( trace );
               
        if ( tr.Entity:IsValid() and ( tr.Entity:IsPlayer() ) ) then
                if( tr.Entity:GetNWBool( "FrozenYay" ) == true ) then
                        tr.Entity:SetNWBool( "FrozenYay", false )
                        tr.Entity:SetWalkSpeed(160)
                        tr.Entity:SetRunSpeed(240)
                        for k, v in pairs(tr.Entity.OldWeapon) do tr.Entity:Give(v:GetClass()) end
 
                self.Owner:EmitSound("npc/metropolice/vo/getoutofhere.wav", 50, 100)
                tr.Entity:EmitSound("npc/metropolice/vo/getoutofhere.wav", 50, 100)
 
                else
                        self.Owner:PrintMessage( HUD_PRINTCENTER, "Player isn't handcuffed." );
                        tr.Entity:PrintMessage(HUD_PRINTCENTER,"You Have Been Released.");
                       
                end
        end
end
end


But i’ve this error :



[ERROR] addons/handcuffs/lua/weapons/handcuffs/shared.lua:151: Tried to use a NULL entity!
  1. GetClass - [C]:-1
   2. unknown - addons/handcuffs/lua/weapons/handcuffs/shared.lua:151

Nah, I meant something more like this:


--Other SWEP stuff here

SWEP.IsHandcuffs = true

function SWEP:SetupDataTables( )
	self:NetworkVar( "Bool", 0, "ApplyToSelf" )
end

function SWEP:Deploy( )
	if self:GetApplyToSelf( ) then
		--Notify player that they have been cuffed?
	end
	
	return true
end

function SWEP:Holster( )
	if self:GetApplyToSelf( ) then
		return false
	end
	
	return true
end

function SWEP:PrimaryAttack( )
	if self:GetApplyToSelf( ) or CLIENT then
		return
	end
	
	local tr = { }
	tr.start = self.Owner:GetShootPos( )
	tr.endpos = tr.start + self.Owner:GetAimVector( ) * 95
	tr.filter = self.Owner
	
	local res = util.TraceLine( tr )
	
	if res.Entity:IsPlayer( ) then
		local wep = res.Entity:GetActiveWeapon( )
		
		if wep.IsHandcuffs and wep:GetApplyToSelf( ) then
			--Already handcuffed
			return
		end
		
		if not wep.IsHandcuffs then
			local w = ents.Create( self:GetClass( ) )
				w:SetApplyToSelf( true )
			w:Spawn( )
			res.Entity:SetActiveWeapon( w )
			
			--Maybe remove the weapon itself here if cops can only have a single set?
			return
		end
		
		if not wep:GetApplyToSelf( ) then
			--Lock the cuffs if other players have them equipped?
			--Might be grief-able, though
		end
	end
end

function SWEP:SecondaryAttack( )

end

The idea is fairly simple.

The handcuffs are a weapon with a single bool that it cares about. If this is true, they are cuffed to the owner. False, they are not.

If they are cuffed, they cannot swap away from this ( returning false in Holster blocks the swap ).

To check elsewhere if the player is cuffed, you can use this logic check:


wep.IsHandcuffs and wep:GetApplyToSelf( )

If the player doesn’t have a weapon, it won’t fail since NULL.IsHandcuffs should never be true ( you are doing something terribly satanic if it is ).

Then, you can do things like being able to give the unlocked handcuffs to other players if they release the player.

You can even do things like set the holdtype to the physgun one and position the world model to look like they are handcuffed if you so desire.

It is by no means complete code or even tested, but it should give you an idea of what I meant.

Waw ok i see what you want to make, but i’m not a very good coder… :confused:

Don’t work for me… Can someone help me please ? :frowning:

If you want someone to code it for you, I’d recommend trying out CoderHire.

What do you mean it doesn’t work? Show us your code and any errors you get