All pastes #573201 Raw Edit

Ricochet

public text v1 · immutable
·published 2007-06-18 01:08 UTC
rendered paste body

function GAMEMODE:MVRicochetCallback( bouncenum, attacker, tr, dmginfo, bulletdmg, bulletforce, tracerfreq, tracer, hiteffect, ricodmgmod, ricoforcemod, ricospread, entity )

	local DoDefaultEffect = false;
	if ( !tr.HitWorld ) then DoDefaultEffect = true end
	if ( tr.MatType != MAT_METAL && tr.MatType != MAT_CONCRETE && tr.MatType != MAT_VENT && tr.MatType != MAT_TILE && tr.MatType != MAT_COMPUTER) then
		if ( !tr.HitSky && tr.MatType != MAT_FLESH ) then
			local effectdata = EffectData()
				effectdata:SetOrigin( tr.HitPos )
				effectdata:SetNormal( tr.HitNormal )

			if hiteffect != nil and hiteffect != "" then
				util.Effect( hiteffect, effectdata )
			else
				util.Effect( "MVhitsmoke", effectdata, true )
			end
		end
	return end

	if ( CLIENT ) then return end
	if ( bouncenum > 7 ) then return end
	local RicoChance = 1
	if ( tr.MatType == MAT_METAL ) then
		RicoChance = 1		//100% chance of ricochet
	end
	if ( tr.MatType == MAT_CONCRETE ) then
		RicoChance = 3		//33% chance
	end
	if ( tr.MatType == MAT_VENT ) then
		RicoChance = 2		//50% chance
	end
	if ( tr.MatType == MAT_TILE ) then
		RicoChance = 4		//25% chance
	end
	if ( tr.MatType == MAT_COMPUTER ) then
		RicoChance = 2		//50% chance
	end

	local DoRicochet = math.floor( math.Rand( 1, RicoChance+1 ) )
	if ( DoRicochet != 1 ) then
		if ( !tr.HitSky && tr.MatType != MAT_FLESH ) then
			local effectdata = EffectData()
				effectdata:SetOrigin( tr.HitPos )
				effectdata:SetNormal( tr.HitNormal )

			if hiteffect != nil and hiteffect != "" then
				util.Effect( hiteffect, effectdata )
			else
				util.Effect( "MVhitsmoke", effectdata, true )
			end
		end
	return end
	local DotProduct = tr.HitNormal:Dot( tr.Normal * -1 )
	local bullet =
	{
		Num 		= 1,
		Src 		= tr.HitPos,
		Dir 		= ( 2 * tr.HitNormal * DotProduct ) + tr.Normal,
		Spread 		= Vector( 0, 0, 0 ), //Vector( 0.05, 0.05, 0 )
		Tracer		= 1,
		TracerName 	= "MVricochet_"..tracer,
		Force		= bulletforce * ricoforcemod,
		Damage		= bulletdmg * ricodmgmod,
		AmmoType 	= "Pistol"
	}

	// Continue bouncing on the server only
	if entity != nil then
		bullet.Callback	= function ( a, b, c ) GAMEMODE:MVRicochetCallback( bouncenum+1, a, b, c, bulletdmg, bulletforce, tracerfreq, tracer, hiteffect, ricodmgmod, ricoforcemod, ricospread, entity ) end
	else
		bullet.Callback	= function ( a, b, c ) GAMEMODE:MVRicochetCallback( bouncenum+1, a, b, c, bulletdmg, bulletforce, tracerfreq, tracer, hiteffect, ricodmgmod, ricoforcemod, ricospread ) end
	end
	timer.Simple( 0.08 * bouncenum, attacker.FireBullets, attacker, bullet )

	// If you don't want to do default damage or
	// effects you can return false here
	return { damage = true, effects = DoDefaultEffect }

end