• Been trying to fix this all day
    6 replies, posted
Well, so i got this problem with a swep I'm making. When i press MOUSE1, it attacks twice. I've been trying to figure out why it's happening, but nothing seems to have worked. Primary Attack code: [QUOTE] function SWEP:PrimaryAttack() if not self.Owner then return end local ply = self.Owner if not IsValid(ply) then return end self:StartShowing(ply:EntIndex()) local trace = self.Owner:GetEyeTrace() function PlsDelay() if trace.HitPos:Distance(self.Owner:GetShootPos()) <= 75 then self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER) 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 = 3 bullet.Damage = 30 self.Owner:FireBullets(bullet) self.Weapon:EmitSound("Weapon_Crowbar.Melee_Hit") else self.Weapon:EmitSound("Zombie.AttackMiss") self.Weapon:SendWeaponAnim(ACT_VM_MISSCENTER) end end timer.Simple(0.5,PlsDelay) end [/QUOTE]
Try this out. [b][url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index19b5.html]Weapon.SetNextPrimaryFire [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
[QUOTE=Karp;42563247]Try this out. [b][url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index19b5.html]Weapon.SetNextPrimaryFire [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b][/QUOTE] Thanks bunch for helping, but sadly it does not seem to have an effect.
Are you making sure to check if you can shoot before you can shoot, then setting the delay? This is from the tutorial explosion swep [CODE]function SWEP:PrimaryAttack() -- if our weapon cannot primary attack due to SetNextPrimaryFire, then return end if ( !self:CanPrimaryAttack() ) then return end --Do all the primary shooting stuff -- Set the next primary fire. This works in conjunction with " if ( !self:CanPrimaryAttack() ) then return end " self:SetNextPrimaryFire( CurTime() + self.Delay ) end [/CODE]
[QUOTE=Karp;42563390]Are you making sure to check if you can shoot before you can shoot, then setting the delay? This is from the tutorial explosion swep [CODE]function SWEP:PrimaryAttack() -- if our weapon cannot primary attack due to SetNextPrimaryFire, then return end if ( !self:CanPrimaryAttack() ) then return end --Do all the primary shooting stuff -- Set the next primary fire. This works in conjunction with " if ( !self:CanPrimaryAttack() ) then return end " self:SetNextPrimaryFire( CurTime() + self.Delay ) end [/CODE][/QUOTE] Thanks a bunch, this did the trick. I've also encountered another problem now. I've made this code that when i right click, it check's for both NPCs or players in a radius of 80, and then deals 1 damage to them. It works.. It deals the 1 damage, but i keep getting this error spammed: [ERROR] lua/weapons/pred_epicgun/shared.lua:305: attempt to call method 'TakeDamage' (a nil value) 1. unknown - lua/weapons/pred_epicgun/shared.lua:305 [QUOTE] local pos = self.Owner:GetPos() + Vector(0,0,32) for k,v in pairs(ents.FindInSphere( pos, 80 )) do if( v:IsValid() and ( v:IsPlayer() and v:Alive() or v:IsNPC() ) and v != self.Owner ) then local pos2 = v:GetPos() if( (pos.z-pos2.z) < 50 and (pos.z-pos2.z) > -50 ) then v:TakeDamage(1,self.Owner,self.Owner) end end end end [/QUOTE]
At the start of the function [LUA] if not IsFirstTimePredicted () then return end [/LUA]
That's it. Thanks a bunch. People are so helpful.
Sorry, you need to Log In to post a reply to this thread.