Announcement

Collapse
No announcement yet.

Reflective Weapons Mutator: Script Help!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Reflective Weapons Mutator: Script Help!

    I"m in the process of making a reflective weapons mutator, that is that some weapons will have beams and projectiles that can reflect off walls, like a laser does to a mirror.

    So far the shock beam and shock projectile are done, Rocket launcher is done, and lightning gun is buggy in 3rd person view.

    There is a script called SniperAttachment, that I think is the culprit to my problem, but first, take alook at my problem:

    Here is the Reflective Lightning gun working correctly in first person view mode.
    Http://www.freewebs.com/bluecorona/LookAtThis1.JPG

    and here is the Reflective lightning gun displaying the lightning incorrectly in 3rd person view mode. This also applies to bots and other players.

    Http://www.freewebs.com/bluecorona/LookAtThis2.JPG

    Notice how the reflection points are shown correctly, but the lightning is being drawn from the gun to each point of reflection instead of from the gun to the first point of reflection to the next point to the next point, etc.

    I've been looking at the the 3rdPersonEffects function of the SniperAttachment class. And i think i know a way to solve the problem, However, In order for it to work, I would need access to the variables in my ReflectiveSniperFire class.

    I also have a similar variable access problem with my Mutator settings, I want to create a configureable boolean variable that appears in the mutator settings window, which can be accessed in my weapons fire classes.

    Can anyone help me with either of these problems?

    #2
    post some code?

    Comment


      #3
      Here is the Lightning gun fire class. It works correctly in first person view.

      Code:
      //==========================================================================
      // ReflectiveSniperFire
      // This is the Fire class
      //==========================================================================
      
      class ReflectiveSniperFire extends SniperFire;
      
      function DoTrace(Vector Start, Rotator Dir)
      {
          local Vector X,Y,Z, End, HitLocation, HitNormal, RefNormal;
          local Actor Other, mainArcHitTarget;
          local int Damage, ReflectNum, arcsRemaining;
          local int ReflectMaxNum;
          local bool bDoReflect, bReflectedYet;
          local xEmitter hitEmitter;
          local class<Actor> tmpHitEmitClass;
          local float tmpTraceRange;
          local vector arcEnd, mainArcHit;
          local Pawn HeadShotPawn;
          local vector EffectOffset;
      
          //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          //  Assigning Beam Starting Point Offset to ArcEnd
          //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      	if ( class'PlayerController'.Default.bSmallWeapons )
      		EffectOffset = Weapon.SmallEffectOffset;
      	else
      		EffectOffset = Weapon.EffectOffset;
      
          Weapon.GetViewAxes(X, Y, Z);
          if ( Weapon.WeaponCentered() )
              arcEnd = (Instigator.Location +
      			EffectOffset.X * X +
      			1.5 * EffectOffset.Z * Z);
      	else if ( Weapon.Hand == 0 )
      	{
      		if ( class'PlayerController'.Default.bSmallWeapons )
      			arcEnd = (Instigator.Location +
      				EffectOffset.X * X);
      		else
      			arcEnd = (Instigator.Location +
      				EffectOffset.X * X
      				- 0.5 * EffectOffset.Z * Z);
      	}
      	else
              arcEnd = (Instigator.Location +
      			Instigator.CalcDrawOffset(Weapon) +
      			EffectOffset.X * X +
      			Weapon.Hand * EffectOffset.Y * Y +
      			EffectOffset.Z * Z);
      
          //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          //  Priming a few variables
          //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      
          //tmpHitEmitClass = HitEmitterClass;
          tmpTraceRange = TraceRange;
      
          ReflectNum = 0;
          ReflectMaxNum = 7;      // Control Max number of Reflections here
          bDoReflect = True;
          bReflectedYet = False;
      
          //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          //  Calculating Bolt path and Damage
          //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          while (true)
          {
              X = Vector(Dir);
              End = Start + tmpTraceRange * X;
              Other = Weapon.Trace(HitLocation, HitNormal, End, Start, true);
              tmpHitEmitClass = HitEmitterClass;
      
              if ( Other != None && (Other != Instigator || ReflectNum > 0) )
              {
                  if ( Other != mainArcHitTarget )
                  {
                      if ( !Other.bWorldGeometry )
                      {
                          //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                          //  Checking Hit for Headshot, and Applying Damage
                          //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                          Damage = (DamageMin + Rand(DamageMax - DamageMin)) * DamageAtten;
      
                          if (Vehicle(Other) != None)
                              HeadShotPawn = Vehicle(Other).CheckForHeadShot(HitLocation, X, 1.0);
                          if (HeadShotPawn != None)
                          {
                              HeadShotPawn.TakeDamage(Damage * HeadShotDamageMult, Instigator, HitLocation, Momentum*X, DamageTypeHeadShot);
                          }
      		    else if ( (Pawn(Other) != None) && (arcsRemaining == NumArcs) && Pawn(Other).IsHeadShot(HitLocation, X, 1.0) )
                          {
                              Other.TakeDamage(Damage * HeadShotDamageMult, Instigator, HitLocation, Momentum*X, DamageTypeHeadShot);
                          }
                          else
                          {
                              Other.TakeDamage(Damage, Instigator, HitLocation, Momentum*X, DamageType);
                          }
                          /* These two statements tie up loose ends, the final bolt will be drawn to the target
                             that it hit from the most recent bolt starting point, and bDoReflect set to false
                             to prevent the bolt from reflecting again further down in the code.*/
                          hitEmitter = xEmitter(Weapon.Spawn(tmpHitEmitClass,,, start, Rotator(HitNormal)));
                          bDoReflect = False;
                      }
                      else
                          // This code was in the SniperFire Class and I don't know if it's neccessary.
      		    HitLocation = HitLocation + 2.0 * HitNormal;
      	     }
              }
              else
              {
                  // Assigning Values to Hitlocation and Hitnormal
                  HitLocation = End;
                  HitNormal = Normal(Start - End);
              }
              //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              //  Performing Neccessary checks and stuff.
              //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              
              // can't fire if weapon not equipped!
              if ( Weapon == None )
      		return;
              /* This Checks to see if the beam has reflected off a surface yet, This xEmmitter will
                 draw the bolt from ArcEnd, where the beam was appropriately offset to show the player
                 from the weapon.  bReflectedYet prevents it from drawing the bolt from the gun again. */
              If ( bReflectedYet == false )
              {
                      hitEmitter = xEmitter(Weapon.Spawn(tmpHitEmitClass,,, arcEnd, Rotator(HitNormal)));
                      bReflectedYet = True;
              }
              // Assigning vector member the HitLocation Value
              if ( hitEmitter != None )
      		hitEmitter.mSpawnVecA = HitLocation;
      	if ( HitScanBlockingVolume(Other) != None )
      		return;
      
              //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              //  Performing New Bolt Reflections
              //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              if (bDoReflect && ++ReflectNum <= ReflectMaxNum)
              {
                  // start beam from last hitlocation
                  Start = HitLocation;
                  // Turning bolt appropriatley based on surface it hit.
                  Dir = Rotator(MirrorVectorByNormal(Vector(Dir), HitNormal));
                  // Make bolt effect
                  hitEmitter = xEmitter(Weapon.Spawn(tmpHitEmitClass,,, start, Rotator(HitNormal)));
                  // make spark effects at point of impact
                  Weapon.Spawn(SecHitEmitterClass,,, Start, Rotator(HitNormal));
                  // I don't know.
                  arcEnd = mainArcHit;
              }
              else
              {
                  break;
              }
          }
      }
      
      defaultproperties
      {
      //NumArcs = 0;
      }
      This is the Mutator.uc It just replaces the weapons in game with my reflective weapons, and gives the user an option to enable/disable certain weapons. That works because the boolean variable is within the mutator class. How would i put a boolean variable in this class that could be accessed in a weapon fire kind of class? Let's say i want to give the user the option of enabling/disabling the gravity feature I have on the reflective rockets with use of a boolean variable, that can be changed in the mutator config menu?

      Code:
      //======================================================
      // Mutator 
      //======================================================
      class ReflectiveWeaponMutator extends Mutator;
      
      var config bool bEnableLightningGun;
      var config bool bEnableShockRifle;
      var config bool bEnableRocketLauncher;
      var localized string LightningGunDisplayText, LightningGunDescText;
      var localized string ShockRifleDisplayText, ShockRifleDescText;
      var localized string RocketLauncherDisplayText, RocketLauncherDescText; 
      
      //============================================
      //WEAPON REPLACEMENT PROCESS
      //============================================
      function bool CheckReplacement (Actor Other, out byte bSuperRelevant)
      {
          local int i;
          local WeaponLocker L;
      
          if (xWeaponBase(other) != None)  // don't want to access non-weapons bases
          {
              if (xWeaponBase(other).weaponType == class'ShockRifle' && bEnableShockRifle == true)
                   xWeaponBase(other).WeaponType = class'ReflectiveShockRifle';
              else if (xWeaponBase(other).weaponType == class'SniperRifle' && bEnableLightningGun == true)
                   xWeaponBase(other).WeaponType = class'ReflectiveSniperRifle';
              else if (xWeaponBase(other).weaponType == class'RocketLauncher' && bEnableRocketLauncher == true)
                   xWeaponBase(other).WeaponType = class'ReflectiveRocketLauncher';
              else
                  return true;
          }
          else if (WeaponPickup(other) != None)
          {
              if (string(other.class) == "xWeapons.ShockRiflePickup" && bEnableShockRifle == true)
                  ReplaceWith(Other, "ReflectiveWeapons.ReflectiveShockRiflePickup");
              else if (string(other.class) == "xWeapons.SniperRiflePickup" && bEnableLightningGun == true)
                  ReplaceWith(Other, "ReflectiveWeapons.ReflectiveSniperRiflePickup");
              else if (string(other.class) == "xWeapons.RocketLauncherPickup" && bEnableRocketLauncher == true)
                  ReplaceWith(Other, "ReflectiveWeapons.ReflectiveRocketLauncherPickup");
              else
                  return true;
          }
          else if ( WeaponLocker(Other) != None )
          {
      	L = WeaponLocker(Other);
      	for (i = 0; i < L.Weapons.Length; i++)
      		if (L.Weapons[i].WeaponClass == class'ShockRifle' && bEnableShockRifle == true)
      			L.Weapons[i].WeaponClass = class'ReflectiveShockRifle';
      		else if (L.Weapons[i].WeaponClass == class'SniperRifle' && bEnableLightningGun == true)
                              L.Weapons[i].WeaponClass = class'ReflectiveSniperRifle';
      		else if (L.Weapons[i].WeaponClass == class'RocketLauncher' && bEnableRocketLauncher == true)
                              L.Weapons[i].WeaponClass = class'ReflectiveRocketLauncher';
      
      	return true;
          }
          else
              return true;
      
          return false;
      }
      
      //============================================
      //ADDING MUTATOR-CONFIGUREABLE PROPERTIES
      //============================================
      static function FillPlayInfo(PlayInfo PlayInfo)
      {
      	Super.FillPlayInfo(PlayInfo);
      
      	PlayInfo.AddSetting(default.RulesGroup, "bEnableLightningGun", default.LightningGunDisplayText, 0, 1, "Check");
      	PlayInfo.AddSetting(default.RulesGroup, "bEnableShockRifle", default.ShockRifleDisplayText, 0, 1, "Check");
      	PlayInfo.AddSetting(default.RulesGroup, "bEnableRocketLauncher", default.RocketLauncherDisplayText, 0, 1, "Check");
      
      }
      
      //============================================
      //TOOLTIPS
      //============================================
      static event string GetDescriptionText(string PropName)
      {
      	switch (PropName)
      	{
      		case "bEnableLightningGun":	return default.LightningGunDescText;   // Lightning Gun
      		case "bEnableShockRifle":	return default.ShockRifleDescText;     // Shock Rifle
      		case "bEnableRocketLauncher":	return default.RocketLauncherDescText; // Rocket Launcher
      	}
      
      	return Super.GetDescriptionText(PropName);
      }
      
      //============================================
      //DEFAULT PROPERTIES
      //============================================
      defaultProperties
      {
          ShockRifleDisplayText="Reflective Shock Rifle"
          LightningGunDisplayText="Reflective Lightning Gun"
          RocketLauncherDisplayText="Reflective Rocket Launcher"
      
          ShockRifleDescText="Replace Shock Rifle with Reflective Shock Rifle"
          LightningGunDescText="Replace Lightning Gun with Reflective Lightning Gun"
          RocketLauncherDescText="Replace Rocket Launcher with Reflective Rocket Launcher"
      
          bEnableLightningGun=True
          bEnableShockRifle=True
          bEnableRocketLauncher=True
      
          Description = "Replaces some weapons with reflective weapons!"
          FriendlyName= "Reflective Weapons"
      }
      This is the Reflective Rocket projectile class in which i want to use a boolean variable that can be changed in mutator config properties window during gameplay, The rocket works correctly.

      Code:
      //=============================================================================
      // Written By: dstoddar
      // Based On: RocketProj and FlakChunk
      //=============================================================================
      class ReflectiveRocketProj extends RocketProj;
      
      var byte Bounces;
      var byte FlockIndex;
      var bool bCurl;
      
      replication
      {
          reliable if ( bNetInitial && (Role == ROLE_Authority) )
              FlockIndex, bCurl, Bounces;
      }
      
      //------------------------------------------------------------
      // Note: Does not explode when it hits the wall
      //       Until the last bounce
      //------------------------------------------------------------
      simulated function HitWall( vector HitNormal, actor Wall )
      {
          if ( !Wall.bStatic && !Wall.bWorldGeometry
      		&& ((Mover(Wall) == None) || Mover(Wall).bDamageTriggered) )
          {
              if ( Level.NetMode != NM_Client )
      		{
      		     if ( Instigator == None || Instigator.Controller == None )
      				Wall.SetDelayedDamageInstigatorController( InstigatorController );
                           Wall.TakeDamage( Damage, instigator, Location, MomentumTransfer * Normal(Velocity), MyDamageType);
      		}
              Destroy();
              return;
          }
          /* this is the place that gravity is implemented in the rocket's reflection path
             taking this line out will make the rocket bounce perfectly in straight lines
             off the walls, I want to use a boolean variable here, that can be changed via
             checkmark in the Mutator configuration properties window that appears during
             gameplay setup,  I will use a simple if statement that checks the value of 
             the boolean to see whether it should apply gravity to the rocket or not. */
          SetPhysics(PHYS_Falling);
      
          if (Bounces > 0)
          {
      	Playsound(SoundGroup'WeaponSounds.FlakCannon.FlakCannonFire');
              Velocity = 1 * (Velocity - 2.0*HitNormal*(Velocity dot HitNormal));
              Bounces= Bounces - 1;
              return;
          }
          if (Bounces == 0)
          {
      	bBounce = false;
      	Explode(Location,HitNormal);
          }
      }
      defaultproperties
      {
           bBounce=True
           Bounces=7
      }

      Comment

      Working...
      X