KeyPress issues.


function SWEP:Think()
self:Stuff()
 if self.Owner:GetAmmoCount("ammo_flameammo") > 200 then
self.Owner:SetAmmo(200, "ammo_flameammo")
if self.Owner:KeyPressed(IN_ATTACK) then

		self:PrimaryAttack()
				self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
	
		end
		if self.Owner:KeyReleased(IN_ATTACK) then
		self.Weapon:SendWeaponAnim(ACT_VM_SECONDARYATTACK)
		if SERVER then self.Owner:EmitSound(Sound("v_flamegun/flameend.wav")) end
		self.Weapon:SetNextPrimaryFire( CurTime() + 0.5 )
end
end
end

Sounds don’t play and animations don’t play for some reason. How can I fix this?

Ah you again, posting partial scripts as usual.

Why would I post huge script? But, whatever:


SWEP.AdminSpawnable = true
SWEP.ViewModelFOV = 90
SWEP.ViewModel = "models/weapons/v_flamgun.mdl"
SWEP.WorldModel = "models/w_flamgun.mdl"
SWEP.AutoSwitchTo = true
SWEP.Slot = 4
SWEP.HoldType = "physgun"
SWEP.PrintName = "FlameGun"
SWEP.Author = ""
SWEP.Spawnable = true
SWEP.AutoSwitchFrom = true
SWEP.FiresUnderwater = false
SWEP.Weight = 5
SWEP.DrawCrosshair = true
SWEP.Category = "Kingpin"
SWEP.SlotPos = 2
SWEP.DrawCrosshair = false
SWEP.Instructions = ""
SWEP.Contact = ""
SWEP.Purpose = ""
SWEP.Base = "kingpin_base"

SWEP.Primary.Sound = ("Postal2/pistol_fire.wav")
SWEP.Primary.Damage = 5
SWEP.Primary.TakeAmmo = 2
SWEP.Primary.ClipSize = -1
SWEP.Primary.Ammo = "ammo_flameammo"
SWEP.Secondary.Ammo = "none"
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Spread = 0.1
SWEP.Primary.NumberoFShots = 1
SWEP.Primary.Automatic = true
SWEP.Primary.Recoil = 0.1
SWEP.Primary.Delay = 0.09
SWEP.Primary.Force = 20

game.AddAmmoType( {
 name = "ammo_flameammo",
 dmgtype = DMG_BULLET,
 tracer = TRACER_LINE,
 plydmg = 0,
 npcdmg = 0,
 force = 2000,
 minsplash = 10,
 maxsplash = 5
} )


//SWEP:Initialize()\\
function SWEP:Initialize()
        self:SetWeaponHoldType( self.HoldType )
end
//SWEP:Initialize()\\

function SWEP:Deploy()
	self.Weapon:SetNextPrimaryFire(CurTime() +.5)
	self.Weapon:SendWeaponAnim(ACT_VM_DRAW)
	if ( SERVER ) then
	self.idlesound = CreateSound(self.Weapon, "v_flamegun/flamepilot.wav")
	self.idlesound:Play()
	end
	return true
end
		
function SWEP:Holster()
	if ( SERVER ) then
		if self.idlesound then self.idlesound:Stop() end
		return true
	end
end
function SWEP:Equip()
	if SERVER then
		if self.Owner:IsPlayer() then 
			self.Owner:GiveAmmo(200, self.Primary.Ammo)
		end
	end
end
		

//SWEP:PrimaryFire()\\
function SWEP:PrimaryAttack()
if self.Owner:GetAmmoCount("ammo_flameammo") == 0 then
return 
end
local 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 = 25
		bullet.Damage = 5
		
		local ang = self.Owner:GetAimVector()
		local spos = self.Owner:GetShootPos()
		local trace = {}
		trace.start = spos
		trace.endpos = spos + (ang * 75)
		trace.filter = self.Owner
		local tr = util.TraceLine(trace)
			self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
			if SERVER then self.Owner:EmitSound(Sound("v_flamegun/flame"..math.random(1,3)..".wav")) end
	self:TakePrimaryAmmo(self.Primary.TakeAmmo)
			
end
//SWEP:PrimaryFire()\\

function SWEP:SecondaryAttack()
end
function SWEP:Think()
self:Stuff()
 if self.Owner:GetAmmoCount("ammo_flameammo") > 200 then
self.Owner:SetAmmo(200, "ammo_flameammo")
if self.Owner:KeyPressed(IN_ATTACK) then

		self:PrimaryAttack()
				self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
	
		end
		if self.Owner:KeyReleased(IN_ATTACK) then
		self.Weapon:SendWeaponAnim(ACT_VM_SECONDARYATTACK)
		if SERVER then self.Owner:EmitSound(Sound("v_flamegun/flameend.wav")) end
		self.Weapon:SetNextPrimaryFire( CurTime() + 0.5 )
end
end
end

/*---------------------------------------------------------
Reload
---------------------------------------------------------*/
function SWEP:Reload()
end

We ask for the actual code because for the obvious reason - We can’t tell what you are doing wrong with just a snippet :slight_smile:

I have no intentions to help you since you’re a constant dick to me whenever I do try, but that same rule applies to what you did anyway in your OP; just a little common sense goes a long way.

I’ve fixed the code by putting it in PrimaryAttack, but this:



	if self.Owner:KeyReleased(IN_ATTACK) then
		self.Weapon:SendWeaponAnim(ACT_VM_SECONDARYATTACK)
		if SERVER then self.Owner:EmitSound(Sound("v_flamegun/flameend.wav")) end
		self.Weapon:SetNextPrimaryFire( CurTime() + 0.5 )
end


Doesn’t work.

If that snippet you posted is in the PrimaryAttack hook, ( which is impossible to tell because as usual you’re posting partial out of context snippets again ) then why do you need to check for player:KeyReleased(IN_ATTACK), obviously he just has released the key because you’re in the PrimaryAttack hook.

Because fire animation is a loop and it needs to be stopped.

[editline]19th January 2014[/editline]

Here’s the PrimaryAttack code specially for Matt:


function SWEP:PrimaryAttack()
if self.Owner:GetAmmoCount("ammo_flameammo") == 0 then
return 
end
local 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 = 25
		bullet.Damage = 5
		
		local ang = self.Owner:GetAimVector()
		local spos = self.Owner:GetShootPos()
		local trace = {}
		trace.start = spos
		trace.endpos = spos + (ang * 75)
		trace.filter = self.Owner
		local tr = util.TraceLine(trace)
			self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
			if SERVER then self.Owner:EmitSound(Sound("v_flamegun/flame"..math.random(1,3)..".wav")) end
	self:TakePrimaryAmmo(self.Primary.TakeAmmo)
	if self.Owner:KeyPressed(IN_ATTACK) then

				self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
	
		end
		if self.Owner:KeyReleased(IN_ATTACK) then
		self.Weapon:SendWeaponAnim(ACT_VM_SECONDARYATTACK)
		if SERVER then self.Owner:EmitSound(Sound("v_flamegun/flameend.wav")) end
		self.Weapon:SetNextPrimaryFire( CurTime() + 0.5 )
end
			
end

Atleast this should help… The reason why the sound atleast doesnt play is because you are running it serverside… Other players are still able to hear it but the client doesnt…
Get rid of the “if SERVER then” filter to fix the sound atleast

But the animation doesn’t play either.

Print self.Owner:KeyReleased(IN_ATTACK) in the primary attack hook, if it doesn’t return true, there’s your problem.

It prints false, how can I fix this?

remove the if statement

edit: holy shit, you’re the one asking for help, you can’t disagree with me.