Cider Hands

I’m trying to make the cider gamemodes hands to work like when you use primary fire it punches, secondary fire is knock if looked at door, and shift + primary fire locks a door, shift + secondary fire unlocks the door.

Everything else seems to be right, but how can I add shift required for locking and unlocking? Because if I just do it as that, when someone wants to knock a door it tries to unlock it too.

So heres the code I’m trying to make to unlock a door:

-- Called when the player attempts to shift + secondary fire.
function SWEP:SecondaryAttack()
	self.Weapon:SetNextSecondaryFire(CurTime() + 1);
	
	-- Check if we're on the client.
	if (CLIENT) then return; end;
	
	-- Get an eye trace from the owner.
	local trace = self.Owner:GetEyeTrace();
	
	-- Check the hit position of the trace to see if it's close to us.
	if (self.Owner:GetPos():Distance( trace.HitPos ) <= 128) then
		if ( ValidEntity(trace.Entity) and ( cider.entity.isDoor(trace.Entity) ) ) then
			if ( cider.player.hasDoorAccess(self.Owner, trace.Entity) ) then
				trace.Entity:Fire("lock", "", 0);
				
				-- Set the animation of the weapon and play the sound.
				self.Owner:EmitSound("doors/door_latch3.wav");
				self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER);
			else
				cider.player.notify(self.Owner, "You do not have access to this door!", 1);
			end;
		end;
	end;
end;

if self.Owner:KeyDown(IN_SPEED) then
	--stuff
end

[Player.KeyDown

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?search=Player.KeyDown)
[IN_KEYS

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?search=IN_KEYS)
:eng101:

I tried to add this to the hands.lua file.

-- Called when the player attempts to shift + primary fire.
if self.Owner:KeyDown(KEY_LSHIFT) then
function SWEP:PrimaryAttack()
	self.Weapon:SetNextPrimaryFire(CurTime() + 1);
	
	-- Check if we're on the client.
	if (CLIENT) then return; end;
	
	-- Get an eye trace from the owner.
	local trace = self.Owner:GetEyeTrace();
	
	-- Check the hit position of the trace to see if it's close to us.
	if (self.Owner:GetPos():Distance( trace.HitPos ) <= 128) then
		if ( ValidEntity(trace.Entity) and ( cider.entity.isDoor(trace.Entity) ) ) then
			if ( cider.player.hasDoorAccess(self.Owner, trace.Entity) ) then
				trace.Entity:Fire("lock", "", 0);
				
				-- Set the animation of the weapon and play the sound.
				self.Owner:EmitSound("doors/door_latch3.wav");
				self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER);
			else
				cider.player.notify(self.Owner, "You do not have access to this door!", 1);
			end;
		end;
	end;
end;

-- Called when the player attempts to shift + secondary fire.
if self.Owner:KeyDown(KEY_LSHIFT) then
function SWEP:SecondaryAttack()
	self.Weapon:SetNextSecondaryFire(CurTime() + 1);
	
	-- Check if we're on the client.
	if (CLIENT) then return; end;
	
	-- Get an eye trace from the owner.
	local trace = self.Owner:GetEyeTrace();
	
	-- Check the hit position of the trace to see if it's close to us.
	if (self.Owner:GetPos():Distance( trace.HitPos ) <= 128) then
		if ( ValidEntity(trace.Entity) and ( cider.entity.isDoor(trace.Entity) ) ) then
			if ( cider.player.hasDoorAccess(self.Owner, trace.Entity) ) then
				trace.Entity:Fire("unlock", "", 0);
				
				-- Set the animation of the weapon and play the sound.
				self.Owner:EmitSound("doors/door_latch3.wav");
				self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER);
			else
				cider.player.notify(self.Owner, "You do not have access to this door!", 1);
			end;
		end;
	end;
end;

Now it just doesn’t give me the hands at the start at all, so I guess theres something wrong with the script, but what is it?

Heres the whole script:

-- Called when the player attempts to primary fire.
function SWEP:PrimaryAttack()
	self.Weapon:SetNextPrimaryFire(CurTime() + 1);
	
	-- Set the animation of the weapon and play the sound.
	self.Weapon:EmitSound("npc/vort/claw_swing2.wav");
	self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER);
	
	-- Get an eye trace from the owner.
	local trace = self.Owner:GetEyeTrace();
	
	-- Check the hit position of the trace to see if it's close to us.
	if (self.Owner:GetPos():Distance(trace.HitPos) <= 128) then
		if ( ValidEntity(trace.Entity)
		and (trace.Entity:IsPlayer() or trace.Entity:IsNPC() or trace.Entity:GetClass() == "prop_ragdoll") ) then
			if (trace.Entity:IsPlayer() and trace.Entity:Health() - self.Primary.Damage <= 15) then
				if (SERVER) then
					cider.player.knockOut(trace.Entity, true, cider.configuration["Knock Out Time"] / 2);
				end;
			else
				local bullet = {};
				
				-- Set some information for the bullet.
				bullet.Num = 1;
				bullet.Src = self.Owner:GetShootPos();
				bullet.Dir = self.Owner:GetAimVector();
				bullet.Spread = Vector(0, 0, 0);
				bullet.Tracer = 0;
				bullet.Force = 5;
				bullet.Damage = self.Primary.Damage;
				
				-- Fire bullets from the owner which will hit the trace entity.
				self.Owner:FireBullets(bullet);
			end;
		elseif ( ValidEntity(trace.Entity) ) then
			if ( ValidEntity( trace.Entity:GetPhysicsObject() ) ) then
				trace.Entity:GetPhysicsObject():ApplyForceOffset(self.Owner:GetAimVector() * 250, trace.HitPos);
			end;
		end;
		
		-- Check if the trace hit an entity or the world.
		if (trace.Hit or trace.HitWorld) then self.Weapon:EmitSound("weapons/crossbow/hitbod2.wav"); end;
	end;
end;

-- Called when the player attempts to secondary fire.
function SWEP:SecondaryAttack()
	self.Weapon:SetNextPrimaryFire(CurTime() + 0.25);
	
	-- Get a trace from the owner's eyes.
	local trace = self.Owner:GetEyeTrace();
	
	-- Check to see if the trace entity is valid and that it's a door.
	if (ValidEntity(trace.Entity) and (cider.entity.isDoor(trace.Entity) or trace.Entity:GetClass() == "prop_dynamic") ) then
		if (self.Owner:GetPos():Distance(trace.HitPos) <= 128) then
			self.Weapon:EmitSound("physics/wood/wood_crate_impact_hard2.wav");
			self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER);
		end;
	end;
end;

-- Called when the player attempts to shift + primary fire.
if self.Owner:KeyDown(KEY_LSHIFT) then
function SWEP:PrimaryAttack()
	self.Weapon:SetNextPrimaryFire(CurTime() + 1);
	
	-- Check if we're on the client.
	if (CLIENT) then return; end;
	
	-- Get an eye trace from the owner.
	local trace = self.Owner:GetEyeTrace();
	
	-- Check the hit position of the trace to see if it's close to us.
	if (self.Owner:GetPos():Distance( trace.HitPos ) <= 128) then
		if ( ValidEntity(trace.Entity) and ( cider.entity.isDoor(trace.Entity) ) ) then
			if ( cider.player.hasDoorAccess(self.Owner, trace.Entity) ) then
				trace.Entity:Fire("lock", "", 0);
				
				-- Set the animation of the weapon and play the sound.
				self.Owner:EmitSound("doors/door_latch3.wav");
				self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER);
			else
				cider.player.notify(self.Owner, "You do not have access to this door!", 1);
			end;
		end;
	end;
end;

-- Called when the player attempts to shift + secondary fire.
if self.Owner:KeyDown(KEY_LSHIFT) then
function SWEP:SecondaryAttack()
	self.Weapon:SetNextSecondaryFire(CurTime() + 1);
	
	-- Check if we're on the client.
	if (CLIENT) then return; end;
	
	-- Get an eye trace from the owner.
	local trace = self.Owner:GetEyeTrace();
	
	-- Check the hit position of the trace to see if it's close to us.
	if (self.Owner:GetPos():Distance( trace.HitPos ) <= 128) then
		if ( ValidEntity(trace.Entity) and ( cider.entity.isDoor(trace.Entity) ) ) then
			if ( cider.player.hasDoorAccess(self.Owner, trace.Entity) ) then
				trace.Entity:Fire("unlock", "", 0);
				
				-- Set the animation of the weapon and play the sound.
				self.Owner:EmitSound("doors/door_latch3.wav");
				self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER);
			else
				cider.player.notify(self.Owner, "You do not have access to this door!", 1);
			end;
		end;
	end;
end;

Or not actually the ‘whole’, just the part which should do the thing.

Well for starters you forgot 2 end (one for each condition you added), which caused errors and stopped the weapon from getting registered.

Then, you’re doing this entirely wrong. The way your code is structured you will override the SWEP:PrimaryFire() function when loading the swep if it has an owner that is running (which it doesn’t : Another error ).

What you need to do is check inside the Primary and Secondary fire functions whether or not the player has shift down, and then act accordingly.

As my English ain’t that good, I didn’t understand much about what you were saying, but anyway, I did something.
As you said at the start, I forgot to end it, so I added another end; after the lock and unlock.
I changed SWEP:PrimaryFire() and SWEP:SecondaryFire() to SWEP:LockDoor() and SWEP:UnlockDoor()
Or did you mean that I have to remove the SWEP:PrimaryFire() and etc?
And about making it to check if the key is down, so would this work?

if self.Owner:KeyDown(IN_SPEED) then
code so it does nothing
else
code here

So this is how the code looks now, and it still doesn’t work. (The lock and unlock part)

-- Called when the player attempts to shift + primary fire.
if self.Owner:KeyDown(KEY_LSHIFT) then
function SWEP:LockDoorAttack()
	self.Weapon:SetNextPrimaryFire(CurTime() + 1);
	
	-- Check if we're on the client.
	if (CLIENT) then return; end;
	
	-- Get an eye trace from the owner.
	local trace = self.Owner:GetEyeTrace();
	
	-- Check the hit position of the trace to see if it's close to us.
	if (self.Owner:GetPos():Distance( trace.HitPos ) <= 128) then
		if ( ValidEntity(trace.Entity) and ( cider.entity.isDoor(trace.Entity) ) ) then
			if ( cider.player.hasDoorAccess(self.Owner, trace.Entity) ) then
				trace.Entity:Fire("lock", "", 0);
				
				-- Set the animation of the weapon and play the sound.
				self.Owner:EmitSound("doors/door_latch3.wav");
				self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER);
			else
				cider.player.notify(self.Owner, "You do not have access to this door!", 1);
			end;
		end;
	end;
end;
end;

-- Called when the player attempts to shift + secondary fire.
if self.Owner:KeyDown(KEY_LSHIFT) then
function SWEP:UnlockDoorAttack()
	self.Weapon:SetNextSecondaryFire(CurTime() + 1);
	
	-- Check if we're on the client.
	if (CLIENT) then return; end;
	
	-- Get an eye trace from the owner.
	local trace = self.Owner:GetEyeTrace();
	
	-- Check the hit position of the trace to see if it's close to us.
	if (self.Owner:GetPos():Distance( trace.HitPos ) <= 128) then
		if ( ValidEntity(trace.Entity) and ( cider.entity.isDoor(trace.Entity) ) ) then
			if ( cider.player.hasDoorAccess(self.Owner, trace.Entity) ) then
				trace.Entity:Fire("unlock", "", 0);
				
				-- Set the animation of the weapon and play the sound.
				self.Owner:EmitSound("doors/door_latch3.wav");
				self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER);
			else
				cider.player.notify(self.Owner, "You do not have access to this door!", 1);
			end;
		end;
	end;
end;
end;

Sorry for double post, but I really need to get this to work.

i have theese hands, if you want them contact me in a PM.