I'm making a ricochet shotgun and it only ricochets one 'shot'

It’s not really what’s stated in the title, but that’s basically it.

I’m making a shotgun which ricochets.

[lua]function SWEP:TertiaryAttack()
if self:CanSecondaryAttack() then
self:ShootRicochet(self.Secondary.Damage, self.Secondary.NumShots, self.Secondary.Cone)
self:ShootRicochet(self.Secondary.Damage, self.Secondary.NumShots, self.Secondary.Cone)
self:ShootRicochet(self.Secondary.Damage, self.Secondary.NumShots, self.Secondary.Cone)
self:ShootRicochet(self.Secondary.Damage, self.Secondary.NumShots, self.Secondary.Cone)
self:ShootRicochet(self.Secondary.Damage, self.Secondary.NumShots, self.Secondary.Cone)
self:ShootRicochet(self.Secondary.Damage, self.Secondary.NumShots, self.Secondary.Cone)
self:ShootRicochet(self.Secondary.Damage, self.Secondary.NumShots, self.Secondary.Cone)
self.Weapon:EmitSound(self.Primary.Sound,300,math.random(97,103))
self.Weapon:EmitSound(“Weapon_Mortar.Impact”,50,math.random(400,450)) --Weapon_Mortar.Impact
self:TakePrimaryAmmo(1)
self.Weapon:SetNextPrimaryFire(CurTime() + 2)
end

end

function SWEP:bounce(tr)
local ang = tr.Normal:Angle()
ang:RotateAroundAxis(tr.HitNormal,180)
return ang:Forward() * -1
//Credit to Lexic
end

function SWEP:ShootRicochet( damage, numbullets, aimcone )

local scale = 1
local canscale = true

local recoil = self.Weapon:GetRecoilRatio()
scale = aimcone

local bullet = {}
bullet.Num 		= numbullets
bullet.Src 		= self.Owner:GetShootPos()			
bullet.Dir 		= self.Owner:GetAimVector()			
bullet.Spread 	= Vector( scale, scale, 0 )		
bullet.Tracer	= 1	
bullet.Force	= math.Round(damage * 1.1)							
bullet.Damage	= math.Round(damage)
bullet.AmmoType = "Pistol"
bullet.Callback = function ( attacker, tr, dmginfo )
util.ParticleTracerEx(self.Secondary.Tracer, tr.StartPos, tr.HitPos, true, self.Weapon:EntIndex( ), self.Weapon:LookupAttachment( "muzzle" ))	
local reflectangle = self:bounce(tr)

	local bullet2 = {}
	bullet2.Num 		= numbullets
	bullet2.Src 		= tr.HitPos			
	bullet2.Dir 		= reflectangle			
	bullet2.Spread 	= Vector( scale, scale, 0 )		
	bullet2.Tracer	= 0
	bullet2.Force	= math.Round(damage * 1.1)							
	bullet2.Damage	= math.Round(damage*0.8)
	bullet2.AmmoType = "Pistol"
	bullet2.Callback = function ( attacker, tr2, dmginfo )
	ParticleEffect("gar_reflect", tr2.StartPos, reflectangle:Angle())
	end
	self.Owner:FireBullets( bullet2 )
		
end

self.Owner:FireBullets( bullet )

self.Weapon:SendWeaponAnim( ACT_VM_SECONDARYATTACK ) 		// View model animation
self.Owner:SetAnimation( PLAYER_ATTACK2 )			// 3rd Person Animation

end[/lua]

That’s the current code. As you can see I call ‘ShootRicochet’ 7 times, once for each pellet.
When I did this last time, I set it up so ShootRicochet fired 7 shots, but only one ricocheted, so this time I made it call it seperately 7 times, and now it fires 7 shots onto the same point and they all individually ricochet.

Halp?

I currently experience the same problem with The SWEP Bases Project, when attempting to create a custom callback with the swep_shotgun base. I believe this is an internal problem, however I could be mistaken, as multiple callbacks seem to work with the current GMDM shotgun.

I haven’t got Fretta installed and frankly I don’t feel like downloading the few hundred megabytes of the Gmod Beta for it.

Would you mind having a look at it for me?
Pwease? :ohdear:

I did some tweakage and got some kind of result.
It fires a spread, but they all come from one point, and the spread is always the same.

If you use FireBullets in a bullet callback, all other callbacks stop.
I seem to remember putting this on the wiki, but it looks like some idoit removed it.

THAT’S why in GMDM they call it back after an amount of time… I thought it was just idiotic to do that, considering I was able to do bullet penetration without timing the callback afterward, but now I understand. Thanks Lexic! :smile:

I’ve added a timer to the second firebullets function, now it’s reflecting off one hole 7 times into the same hole :[

[lua] local traces = {}
local bullet = {}
bullet.Num = self.PenetrateInfo.Num
bullet.Src = PlayerPos
bullet.Dir = self.PenetrateInfo.Dir – phoenix - PlayerAim
bullet.Spread = self.PenetrateInfo.Spread – phoenix - Vector(spread, spread, 0)
bullet.Force = self.PenetrateInfo.Force
bullet.Damage = self.PenetrateInfo.Damage
bullet.Tracer = self.PenetrateInfo.Tracer
bullet.Callback = function(atk,tr,dmgInfo)
table.insert(traces,tr)
debugoverlay.Line(tr.StartPos,tr.HitPos,10,Color(237,40,31,255),true)
–debugoverlay.Cross(tr.HitPos,10,5,color_white,true)
end
self.Owner:FireBullets( bullet )
for _,trace in ipairs(traces) do
self:PenetrateCallback(self.Owner, trace,self.PenetrateInfo.Damage,self.PenetrateInfo.Force)
end[/lua]
works fine here, no timers required.

I messed with it a bit to fit my own code and it works!

http://dl.dropbox.com/u/516743/reflectedrar.PNG