• Bullet Penetration Help!!
    5 replies, posted
Hi there. I got intrested in LUA so I asked my friend to help me mod CS Realistic Base. He made some kind of bullet penetration code and some code that changes the ammotype from eg. Pulse Ammo to 7.62x39 Ammo. The problem is the bullet penetration script. It does not work and does not show any errors. The SWEP is self and the base works also. W/o an error, my friend can't fix it. So does anyone know what the problem might be???? A cl_init.lua for the ammotype script. [code]include('shared.lua') language.Add("airboatgun_ammo", "5.56.45MM Ammo") language.Add("gravity_ammo", "7.62x39MM Ammo") language.Add("alyxgun_ammo", "5.7x28MM Ammo") language.Add("battery_ammo", "9x19MM Ammo") language.Add("striderminigun_ammo", "7.62.51MM Ammo") language.Add("sniperpenetratedround_ammo", ".45 Ammo") language.Add("combinecannon_ammo", ".50 BMG Ammo") language.Add("thumper_ammo", "7.62x54R Ammo")[/code] The bullet penetration code from the shared.lua [code]function SWEP:BulletPenetrate(bouncenum, attacker, tr, dmginfo, isplayer) if (CLIENT) then return end local MaxPenetration if self.Primary.Ammo == "AirboatGun" then MaxPenetration = 14 elseif self.Primary.Ammo == "Gravity" then MaxPenetration = 16 elseif self.Primary.Ammo == "AlyxGun" then MaxPenetration = 13 elseif self.Primary.Ammo == "Battery" then MaxPenetration = 7 elseif self.Primary.Ammo == "StriderMinigun" then MaxPenetration = 18 elseif self.Primary.Ammo == "SniperPenetratedRound" then MaxPenetration = 10 elseif self.Primary.Ammo == "CombineCannon" then MaxPenetration = 24 elseif self.Primary.Ammo == "Thumper" then MaxPenetration = 20 else MaxPenetration = 24 end local DoDefaultEffect = true // Don't go through metal, sand or player if ((tr.MatType == (tr.MatType == MAT_SAND) or (tr.Entity:IsPlayer())) then return true end // Don't go through more than 3 times if (bouncenum > 3) then return false end // Direction (and length) that we are going to penetrate local PenetrationDirection = tr.Normal * MaxPenetration if (tr.MatType == MAT_GLASS or tr.MatType == MAT_PLASTIC or tr.MatType == MAT_WOOD or tr.MatType == MAT_FLESH or tr.MatType == MAT_ALIENFLESH) then PenetrationDirection = tr.Normal * (MaxPenetration * 2) end local trace = {} trace.endpos = tr.HitPos trace.start = tr.HitPos + PenetrationDirection trace.mask = MASK_SHOT trace.filter = {self.Owner} local trace = util.TraceLine(trace) // Bullet didn't penetrate. if (trace.StartSolid or trace.Fraction >= 1.0 or tr.Fraction <= 0.0) then return false end // Damage multiplier depending on surface local fDamageMulti = 0.5 if (tr.MatType == MAT_CONCRETE) then fDamageMulti = 0.3 elseif (tr.MatType == MAT_WOOD or tr.MatType == MAT_PLASTIC or tr.MatType == MAT_GLASS) then fDamageMulti = 0.8 elseif (tr.MatType == MAT_FLESH or tr.MatType == MAT_ALIENFLESH) then fDamageMulti = 0.9 end // Fire bullet from the exit point using the original trajectory local bullet = { Num = 1, Src = trace.HitPos, Dir = tr.Normal, Spread = Vector(0, 0, 0), Tracer = 1, TracerName = "AirBoatGunHeavyTracer", Force = 5, Damage = (dmginfo:GetDamage() * fDamageMulti), HullSize = 2 } bullet.Callback = function(a, b, c) if (self.Ricochet) then return self:RicochetCallback(bouncenum + 1, a, b, c) end end timer.Simple(0.05, function() if not IsFirstTimePredicted() then return end attacker.FireBullets(attacker, bullet, true) end) return true end /*--------------------------------------------------------- Name: SWEP:RicochetCallback() ---------------------------------------------------------*/ function SWEP:RicochetCallback(bouncenum, attacker, tr, dmginfo) if (CLIENT) then return end if (not self) then return end local DoDefaultEffect = true if (tr.HitSky) then return end // Can we go through whatever we hit? if (self.Penetration) and (self:BulletPenetrate(bouncenum, attacker, tr, dmginfo)) then return {damage = true, effects = DoDefaultEffect} end // Your screen will shake and you'll hear the savage hiss of an approaching bullet which passing if someone is shooting at you. if (tr.MatType != MAT_METAL) then if (SERVER) then util.ScreenShake(tr.HitPos, 5, 0.1, 0.5, 64) WorldSound("Bullets.DefaultNearmiss", tr.HitPos, 250, math.random(110, 180)) end if self.Tracer == 1 or self.Tracer == 2 then local effectdata = EffectData() effectdata:SetOrigin(tr.HitPos) effectdata:SetNormal(tr.HitNormal) effectdata:SetScale(20) util.Effect("AR2Impact", effectdata) elseif self.Tracer == 3 then local effectdata = EffectData() effectdata:SetOrigin(tr.HitPos) effectdata:SetNormal(tr.HitNormal) effectdata:SetScale(20) util.Effect("StunstickImpact", effectdata) end return end if (self.Ricochet == false) then return {damage = true, effects = DoDefaultEffect} end if (bouncenum > self.MaxRicochet) then return end // Bounce vector local trace = {} trace.start = tr.HitPos trace.endpos = trace.start + (tr.HitNormal * 16384) local trace = util.TraceLine(trace) local DotProduct = tr.HitNormal:Dot(tr.Normal * -1) local bullet = { Num = 1, Src = tr.HitPos + (tr.HitNormal * 5), Dir = ((2 * tr.HitNormal * DotProduct) + tr.Normal) + (VectorRand() * 0.05), Spread = Vector(0, 0, 0), Tracer = 1, TracerName = "effect_mad_ricochet_trace", Force = dmginfo:GetDamage() * 0.25, Damage = dmginfo:GetDamage() * 0.5, HullSize = 2 } // Added conditional to stop errors when bullets ricochet after weapon switch bullet.Callback = function(a, b, c) if (self.Ricochet) then return self:RicochetCallback(bouncenum + 1, a, b, c) end end timer.Simple(0.05, function() if not IsFirstTimePredicted() then return end attacker.FireBullets(attacker, bullet, true) end) return {damage = true, effects = DoDefaultEffect} end /*--------------------------------------------------------- Name: SWEP:RicochetCallback_Redirect() ---------------------------------------------------------*/ function SWEP:RicochetCallback_Redirect(a, b, c) return self:RicochetCallback(0, a, b, c) end [/code] P.S [lua] tags don't work on my webbrowser (IE8 I think) so it had to be a [code] tag. Sorry.
Are you just slapping this on the end of the SWEP script or something? From looking at the code it looks like you have to implement those in the SWEP's primary fire. As for how, I'm not sure. I can't see it just from having glanced over it.
[QUOTE=MegaJohnny;21266824]Are you just slapping this on the end of the SWEP script or something? From looking at the code it looks like you have to implement those in the SWEP's primary fire. As for how, I'm not sure. I can't see it just from having glanced over it.[/QUOTE] The penetration code is on the SWEP base after function SWEP:CSShootBullet(dmg, recoil, numbul, cone) ends. In the SWEP it self, my friend told me to add this: SWEP.Penetration = true SWEP.Ricochet = true SWEP.MaxRicochet = 0
You should ask the person that gave you that code to help you.
Here's the bullet penetration code from my AC-130 npc: [lua] function ENT:FireTurret( i ) if ( !self ) then // silly timer errors. return end local e = EffectData() e:SetStart( self:GetPos() + self:GetForward() * 90 ) e:SetEntity( self ) e:SetScale( math.Rand (1.5, 2.0 ) ) e:SetNormal( self:GetForward() ) util.Effect( "ac130_muzzle", e ) local bullet = {} bullet.Num = math.random(2,5) bullet.Src = self:GetPos() + self:GetForward() * 90 bullet.Dir = self:GetAngles():Forward() bullet.Spread = Vector( 0, 0, 0 ) bullet.Tracer = math.random( 1, 2 ) bullet.Force = 5 bullet.Damage = math.random( 20, 35 ) bullet.AmmoType = "Ar2" bullet.TracerName = "AirboatGunHeavyTracer" bullet.Callback = function ( a, b, c ) self:HackWall( a, b, c ) end self:FireBullets( bullet ) self:GetOwner():PlayWorldSound( self.Sound ) self:EmitSound( self.Sound, 511, math.random( 65, 71 ) ) local sm = EffectData() sm:SetStart( self:GetPos() + self:GetForward() * 90 ) sm:SetScale(0.8) util.Effect( "Launch2", sm ) if ( i >= self.BurstSize ) then if ( DEBUG ) then print("Attack Sequence Completed") end self.ShouldAttack = false end end function ENT:HackWall(a,b,c) local ang = ( self:GetPos() - b.HitPos ):Normalize() local bullet = {} bullet.Num = math.random(2,5) bullet.Src = b.HitPos + ang * -64 bullet.Dir = self:GetAngles():Forward() bullet.Spread = Vector( .5, .5, .5 ) bullet.Tracer = math.random( 1, 2 ) bullet.Force = 5 bullet.Damage = math.random( 20, 35 ) bullet.AmmoType = "Ar2" bullet.TracerName = "AirboatGunHeavyTracer" bullet.Callback = function ( a, b, c ) self:ExplosiveShellCallback( a, b, c ) end self:FireBullets( bullet ) return { damage = true, effects = DoDefaultEffect } end [/lua] Feel free to adapt it to suit your needs.
[QUOTE=MakeR;21266924]You should ask the person that gave you that code to help you.[/QUOTE] Well I asked him but he said that he does not know what the problem is because no error shows up.
Sorry, you need to Log In to post a reply to this thread.