Attempted to create unknown entity?

Hey Facepunch, i currently have a problem with my “cider_hands”. What i try to do is, giving my hands 4 “options”
so you can do PrimaryAttack, SecondaryAttack and so you can hold shift down and do PrimaryAttack, SecondaryAttack, it to do something else.

Here is a couple of examples:

PrimaryAttack does: So you Attack with hands
SecondaryAttack does: Can hold props/Entities when you right click like the gravity gun

Shift+PrimaryAttack does: Lock (Doors, Vehicle)
Shift+SecondaryAttack does: Unlock (Doors, Vehicles)

I’ve tried a couple of things sort of
**[Input.IsKeyDown **

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Input.IsKeyDown)
**[Gamemode.KeyPress

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Gamemode.KeyPress)**

But without luck didn’t find a answer. The console Error is [lua][gamemodes\cider\entities\weapons\cider_hands\shared.lua:121] function arguments expected near ‘=’[/lua]
And it also tells with Red signs “Attempted to create unknown entity type cider_hands!”

Here is my Shared.lua;

[lua]–[[
Name: “shared.lua”.
Product: “Cider (Roleplay)”.
–]]

if (SERVER) then
AddCSLuaFile(“shared.lua”);

-- Add the resource files for the fists.
resource.AddFile("models/weapons/w_fists.dx80.vtx");
resource.AddFile("models/weapons/w_fists.dx90.vtx");
resource.AddFile("models/weapons/w_fists.mdl");
resource.AddFile("models/weapons/w_fists.phy");
resource.AddFile("models/weapons/w_fists.sw.vtx");
resource.AddFile("models/weapons/w_fists.vvd");
resource.AddFile("models/weapons/v_fists.dx80.vtx");
resource.AddFile("models/weapons/v_fists.dx90.vtx");
resource.AddFile("models/weapons/v_fists.mdl");
resource.AddFile("models/weapons/v_fists.sw.vtx");
resource.AddFile("models/weapons/v_fists.vvd");
resource.AddFile("materials/models/weapons/v_models/brass_knuckles/map.vtf");
resource.AddFile("materials/models/weapons/v_models/brass_knuckles/main.vmt");

end;

– Check if we’re running on the client.
if (CLIENT) then
SWEP.PrintName = “Hands”;
SWEP.Slot = 1;
SWEP.SlotPos = 1;
SWEP.DrawAmmo = false;
SWEP.DrawCrosshair = true;
end

– Define some shared variables.
SWEP.Author = “";
SWEP.Instructions = “Primary Fire: Punch.
Secondary Fire: Knock.”;
SWEP.Contact = "http://
.com/forums/.”;
SWEP.Purpose = “Punching people and knocking on doors.”;

– Set the view model and the world model to nil.
SWEP.ViewModel = “models/weapons/v_fists.mdl”;
SWEP.WorldModel = “models/weapons/w_fists.mdl”;

– Set the animation prefix and some other settings.
SWEP.AnimPrefix = “admire”;
SWEP.Spawnable = false;
SWEP.AdminSpawnable = false;

– Set the primary fire settings.
SWEP.Primary.Damage = 7.5;
SWEP.Primary.ClipSize = -1;
SWEP.Primary.DefaultClip = 0;
SWEP.Primary.Automatic = false;
SWEP.Primary.Ammo = “”;

– Set the secondary fire settings.
SWEP.Secondary.ClipSize = -1;
SWEP.Secondary.DefaultClip = 0;
SWEP.Secondary.Automatic = false;
SWEP.Secondary.Ammo = “”;

– Set the iron sight positions (pointless here).
SWEP.IronSightPos = Vector(0, 0, 0);
SWEP.IronSightAng = Vector(0, 0, 0);
SWEP.NoIronSightFovChange = true;
SWEP.NoIronSightAttack = true;

– Called when the SWEP is initialized.
function SWEP:Initialize()
if (SERVER) then self:SetWeaponHoldType(“normal”); end;
end;

– 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;

function KeyPressed()
if input.IsKeyDown( KEY_LSHIFT ) then

SWEP:SecondaryAttack = {

function SWEP:PrimaryAttack()
self.Weapon:SetNextPrimaryFire(CurTime() + 0.25);

local trace = self.Owner:GetEyeTrace();

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;}

if input.IsKeyDown( KEY_LSHIFT ) then
SWEP:PrimaryAttack = {

function SWEP:PrimaryAttack()
self.Weapon:SetNextPrimaryFire(CurTime() + 1);
.
if (CLIENT) then return; end;

local trace = self.Owner:GetEyeTrace();

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);
			
			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;}
hook.Add( “KeyPress”, “KeyPressedHook”, KeyPressed )
[/lua]

Thank you guy’s in advance! :slight_smile:

:f5: Urgh, help please :f5:

[lua] SWEP:SecondaryAttack() = {[/lua]

What i try to do is Combine the “cider_keys” and “cider_hands” in one.

  • Instead of you have to change your “swep”, “weapon” for locking up and unlocking you can do it on hands
    by holding “shift” down but. I’m totally lost i’v tried 100 of way’s… So here i am. :saddowns:

:siren: Bump, bump :siren:

Try putting both functions in the SWEP:PrimaryAttack, and then in there check if the shift key is pressed, also what king was referring to is to set a function it would be SWEP.PrimaryAttack = without the { and . instead of :, I wouldn’t do it that way though, just check for shift in primary attack. so like
[lua]
– psuedo code
function SWEP:PrimaryAttack()
if input.IsKeyDown(KEY_LSHIFT) then
–Do lock/unlock stuff
else
–Do punchy stuff
end
end
[/lua]

Also the unknown_entity is from not being able to load the entity due to the code error

[lua]
SWEP:SecondaryAttack = {

function SWEP:PrimaryAttack()
self.Weapon:SetNextPrimaryFire(CurTime() + 0.25);

local trace = self.Owner:GetEyeTrace();

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;}
[/lua]

Why in the world would you do that?