Advertisement
inkoalawetrust

Broken projectile deflection code.

Nov 7th, 2022
1,497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.01 KB | Fixit | 0 0
  1. //Custom projectile deflect function.
  2.     //Reflect a projectile, called in CanCollideWith(), returns false if it succeeds, meaning to ignore collision with the actor, otherwise returns true to collide normally.
  3.     Bool DoProjectileDeflection (Actor Projectile, Int DeflectChance, Double DamageReductionFactor, Double SlowDownFactor = 0, Vector2 RandomAngle = (0,0), Vector2 RandomPitch = (0,0))
  4.     {
  5.         If (!Projectile || Projectile && !Projectile.bMissile) Return True;
  6.        
  7.         If (Random (0,255) < DeflectChance) Return True; //Fission mailed
  8.        
  9.         Int Damage = Projectile.GetMissileDamage(7,1); //Get the projectiles' damage, be it a static number or a damage function.
  10.        
  11.         DamageMobj (Projectile,Projectile.Target,Damage*DamageReductionFactor,Projectile.DamageType); //Harm the caller with the projectile even when deflected.
  12.         console.printf ("the projectiles' velocity is %f %f %f",projectile.vel.x,projectile.vel.y,projectile.vel.z);
  13.         //Slow down the projectile randomly.
  14.         Projectile.Angle -= 180; //Turn projectile around.
  15.         Projectile.Vel *= -1; //Opposite day today
  16.         Projectile.Vel.X += FRandom (0,-Vel.X/5*SlowDownFactor);
  17.         Projectile.Vel.Y += FRandom (0,-Vel.Y/5*SlowDownFactor);
  18.         Projectile.Vel.Z += FRandom (0,-Vel.Z/5*SlowDownFactor);
  19.         console.printf ("and now it's %f %f %f",projectile.vel.x,projectile.vel.y,projectile.vel.z);
  20.         //Randomize the direction it'll fly to.
  21.         Projectile.Angle += FRandom (RandomAngle.X,RandomAngle.Y);
  22.         Projectile.Pitch += FRandom (RandomPitch.X,RandomPitch.Y);
  23.        
  24.         Return False;
  25.     }
  26.  
  27. //The CanCollideWith override in the actor meant to deflect certain projectiles.
  28.     Override Bool CanCollideWith (Actor Other, Bool Passive)
  29.     {
  30.         If (!Passive && Other && Other == Turret && ((MVP_BaseTurret(Turret).bFallOnDeath && !IsDead (Turret)) || !MVP_BaseTurret(Turret).bFallOnDeath))
  31.             Return False;
  32.         If (Passive)
  33.         {
  34.             If (Other Is "MVP_RifleBullet") {Return DoProjectileDeflection (Other,0,0.5,randomangle:(3,-3),randompitch:(3,-3));}
  35.         }
  36.         Return Super.CanCollideWith (Other, Passive);
  37.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement