• Melee Weapons Ejecting Bullets?
    4 replies, posted
I've been working on some new weapons for Garry's Mod, and have a few melee weapons in them. But in thirdperson, the melee weapons eject bullets, why so? I have never had this happen, and noticed it recently. I would supply the code if I knew what to give. Any ideas? :v:
It'd be within your weapon-base or weapon code. Show us your PrimaryAttack function, along with ShootEffects / ShootBullet or other functions which are called by PrimaryAttack. Chances are you're either using a base with it in there; or with your melee weapon you're calling it in PrimaryAttack or a function called by it.
Primary Attack [code] function SWEP:PrimaryAttack() local CritMath = math.random(0,4) if CritMath == 3 then self.Weapon:SetNWBool("Critical", true) end if self.Weapon:GetNWBool("Critical") then self.Weapon:SendWeaponAnim(ACT_VM_SWINGHARD) self.Weapon:EmitSound("Weapon_Wrench.MissCrit") else self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER) self.Weapon:EmitSound("Weapon_Wrench.Miss") end self.Owner:SetAnimation(PLAYER_ATTACK1) self.DoMelee = CurTime() + 0.2 self.Weapon:SetNextPrimaryFire(CurTime() + self.Primary.Delay) self.Idle = CurTime() + self.Owner:GetViewModel():SequenceDuration() if ((game.SinglePlayer() and SERVER) or CLIENT) then self.Weapon:SetNetworkedFloat("LastShootTime", CurTime()) end end [/code] And for Swep:Melee [code] function SWEP:Melee() self.DoMelee = nil local tr = {} tr.start = self.Owner:GetShootPos() tr.endpos = self.Owner:GetShootPos() + ( self.Owner:GetAimVector() * 80 ) tr.filter = self.Owner tr.mask = MASK_SHOT local trace = util.TraceLine( tr ) if ( trace.Hit ) then 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 = 1 if self.Weapon:GetNWBool("Critical") then bullet.Damage = 90 trace.Entity:EmitSound("TFPlayer.CritHit") else bullet.Damage = math.random(29,34) end if trace.Entity:IsPlayer() or string.find(trace.Entity:GetClass(),"npc") or string.find(trace.Entity:GetClass(),"prop_ragdoll") then self.Weapon:EmitSound("Weapon_Wrench.HitFlesh") else self.Weapon:EmitSound("Weapon_Wrench.HitWorld") end self.Owner:FireBullets(bullet) end self.Weapon:SetNWBool("Critical", false) end [/code] And yes, I am using a base, thanks for the reply.
Which weapon base are you using, what game-mode? Nothing stands out to me from that really except a core function: FireBullets... You can actually replace the bullet system with a different system for handling melee as it may be causing the headache. Try commenting out that line, remove the weapons from your person, respawn them ( if you auto-refresh ) and try again. If no shells are coming out, I'd recommend looking into PLAYER:TakeDamageInfo( ) -- you can create a new DamageInfo( ) and setup the attacker = self.Owner, inflictor = self, Min/Max Damage, Damage Type ( probably DAMAGE_BLUNT ), etc...
Based on his uploads I'd wager he's just using good ol' weapon_base... not sure what could cause shell ejections like this, but I highly doubt FireBullet is the culprit. Are you using SCK, Errol? And very important, what is the worldmodel of your SWEP? [editline]7th March 2014[/editline] Although TakeDamage/TakeDamageInfo are much better than bullets, that's for sure.
Sorry, you need to Log In to post a reply to this thread.