Deus Ex Clan [A]lpha
homeabout usprojectsmembersmatches
join uschallenge usdownloadsforum
Knowledge Base

Code explanation: training guns

home / Knowledge Base / Coding / Code explanation: training guns

The idea of so-called "training guns" seems to be flying around a lot lately among clans (perhaps because of the rift between skilled players, and average players?), and some strange solutions have been put forward. In this, I will show you the code needed to figure out what damage has been done to the player hit, as well as where it was done.

This code is for classes branching from WeaponRifle:

function ProcessTraceHit(Actor Other, Vector HitLocation, Vector HitNormal, Vector X, Vector Y, Vector Z)
{
   local int MPHitLoc; // used to reference where we last hit.
   local float Multuplier; // stuff for superclass code (Code from a previous classes version of the code)

   // COPIED FROM DeusExWeapon.uc, so we can see the damage modification amount.

   // AugCombat increases our damage if hand to hand
   Multuplier = 1.0;

   // skill also affects our damage
   // GetWeaponSkill returns 0.0 to -0.7 (max skill/aug)
   Multuplier += -2.0 * GetWeaponSkill();

   // END OF COPIED CODE

   Super.ProcessTraceHit(Other,Hitlocation,HitNormal,X,Y,Z); // Call all previous version of the code.

   if (DeusExPlayer(Other)!=None)
   {
      MPHitLoc = DeusExPlayer(Other).GetMPHitLocation(HitLocation);
      switch(MPHitLoc)
      {
         case 0:
            break;
         case 1:
            DeusExPlayer(Owner).ClientMessage("|cFF8000BOOM! HEADSHOT!!! 2x Damage!");
            If(!bZoomed)
               DeusExPlayer(Owner).ClientMessage("Damage="$HitDamage*Multuplier*2*mpNoScopeMult$"");
            else
               DeusExPlayer(Owner).ClientMessage("Damage="$HitDamage*Multuplier*2$"");
            break;
         case 2:
            DeusExPlayer(Owner).ClientMessage("Body Shot");
            If(!bZoomed)
               DeusExPlayer(Owner).ClientMessage("Damage="$HitDamage*Multuplier*mpNoScopeMult$"");
            else
               DeusExPlayer(Owner).ClientMessage("Damage="$HitDamage*Multuplier$"");
            break;
         case 3:
            DeusExPlayer(Owner).ClientMessage("Arm Shot(Left)");
            If(!bZoomed)
               DeusExPlayer(Owner).ClientMessage("Damage="$HitDamage*Multuplier*mpNoScopeMult$"");
            else
               DeusExPlayer(Owner).ClientMessage("Damage="$HitDamage*Multuplier$"");
            break;
         case 4:
            DeusExPlayer(Owner).ClientMessage("Arm Shot(Right)");
            If(!bZoomed)
               DeusExPlayer(Owner).ClientMessage("Damage="$HitDamage*Multuplier*mpNoScopeMult$"");
            else
               DeusExPlayer(Owner).ClientMessage("Damage="$HitDamage*Multuplier$"");
            break;
         case 5:
            DeusExPlayer(Owner).ClientMessage("Leg Shot(Left)");
            If(!bZoomed)
               DeusExPlayer(Owner).ClientMessage("Damage="$HitDamage*Multuplier*mpNoScopeMult$"");
            else
               DeusExPlayer(Owner).ClientMessage("Damage="$HitDamage*Multuplier$"");
            break;
         case 6:
            DeusExPlayer(Owner).ClientMessage("Leg Shot(Right)");
            If(!bZoomed)
               DeusExPlayer(Owner).ClientMessage("Damage="$HitDamage*Multuplier*mpNoScopeMult$"");
            else
               DeusExPlayer(Owner).ClientMessage("Damage="$HitDamage*Multuplier$"");
            break;
         default:
            break;
      }
   }
}

Right... some explanation to how this works:

   // AugCombat increases our damage if hand to hand
   Multuplier = 1.0;

   // skill also affects our damage
   // GetWeaponSkill returns 0.0 to -0.7 (max skill/aug)
   Multuplier += -2.0 * GetWeaponSkill();

This is code to modify the amount of damage finally dealt. The proper version of this, that is used for damage modification is called in the Super.whatever call.

MPHitLoc = DeusExPlayer(Other).GetMPHitLocation(HitLocation);

This code checks if the actor referenced as "Other" (this is what you end up hitting with the weapon shot in this case) is a DeusExPlayer, and if it is, runs the function GetMPHitLocation from the player that you hit. This then sets the variable MPHitLoc at a certain value (1 to 6, 0 for special damage types (i.e.: PoisonEffect (lingering poison from darts, TearGas, etc) and EMP, and NanoVirus, even though it has no effect on humans)), where it is then used in a "Switch".

switch(MPHitLoc)

This runs through all the posibilities that you code into this section when it is called. If the value in the brackets of the switch (in this case, MPHitLoc) matches any of the coded values, something happens, based on what you coded, e.g.:

         case 4:
            DeusExPlayer(Owner).ClientMessage("Arm Shot(Right)");
            If(!bZoomed)
               DeusExPlayer(Owner).ClientMessage("Damage="$HitDamage*Multuplier*mpNoScopeMult$"");
            else
               DeusExPlayer(Owner).ClientMessage("Damage="$HitDamage*Multuplier$"");
            break;

If the value MPHitLoc was 4, you would see a message saying you hit the player in their right arm. Then, you would be told how much damage you dealt. The formula is (if you're not scoped) — HitDamage(25)*Skill(0 to 3.4)*mpNoScopeMult(0.35)=Damage(?) However, if this is not to be used on a class branching off of WeaponRifle, you must use this code:

function ProcessTraceHit(Actor Other, Vector HitLocation, Vector HitNormal, Vector X, Vector Y, Vector Z)
{
   local int MPHitLoc; // used to reference where we last hit.
   local float Multuplier; // stuff for superclass code (Code from a previous classes version of the code)

   // COPIED FROM DeusExWeapon.uc, so we can see the damage modification amount.

   // AugCombat increases our damage if hand to hand
   Multuplier = 1.0;

   // skill also affects our damage
   // GetWeaponSkill returns 0.0 to -0.7 (max skill/aug)
   Multuplier += -2.0 * GetWeaponSkill();

   // END OF COPIED CODE

   Super.ProcessTraceHit(Other,Hitlocation,HitNormal,X,Y,Z); // Call all previous version of the code.

   if (DeusExPlayer(Other)!=None)
   {
      MPHitLoc = DeusExPlayer(Other).GetMPHitLocation(HitLocation);
      switch(MPHitLoc)
      {
         case 0:
            break;
         case 1:
            DeusExPlayer(Owner).ClientMessage("|cFF8000BOOM! HEADSHOT!!! 2x Damage!");
            DeusExPlayer(Owner).ClientMessage("Damage="$HitDamage*Multuplier*2$"");
            break;
         case 2:
            DeusExPlayer(Owner).ClientMessage("Body Shot");
            DeusExPlayer(Owner).ClientMessage("Damage="$HitDamage*Multuplier$"");
            break;
         case 3:
            DeusExPlayer(Owner).ClientMessage("Arm Shot(Left)");
            DeusExPlayer(Owner).ClientMessage("Damage="$HitDamage*Multuplier$"");
            break;
         case 4:
            DeusExPlayer(Owner).ClientMessage("Arm Shot(Right)");
            DeusExPlayer(Owner).ClientMessage("Damage="$HitDamage*Multuplier$"");
            break;
         case 5:
            DeusExPlayer(Owner).ClientMessage("Leg Shot(Left)");
            DeusExPlayer(Owner).ClientMessage("Damage="$HitDamage*Multuplier$"");
            break;
         case 6:
            DeusExPlayer(Owner).ClientMessage("Leg Shot(Right)");
            DeusExPlayer(Owner).ClientMessage("Damage="$HitDamage*Multuplier$"");
            break;
         default:
            break;
      }
   }
}

The difference in this code is, that there is no reference to mpNoScopeMult, as WeaponRifle is the only class to use it. That should be all for training guns.

Peace!

Written by Allan.


← previousindexnext →

Powered by [A]