This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

ceskiHUDIRONSIGHTS

By: a guest on Apr 4th, 2012  |  syntax: None  |  size: 10.64 KB  |  views: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. //=============================================================================
  2. // ceskiHUDIronSights.
  3. //=============================================================================
  4. //
  5. //fake iron sights for WeaponSMG5
  6. //slightly modified by FGR with permission from Ceski
  7. //
  8. class ceskiHUDIronSights extends DeusExScopeView;
  9.  
  10. var float gunlagX, gunlagY;
  11. var float lastEye, curEye;
  12. var vector lastLoc, curLoc;
  13. var rotator lastRot, curRot;
  14. var vector lastVel, curVel;
  15. var float lastJump;
  16.  
  17. function PlaySwish(int swishNum)
  18. {
  19.         local Sound swishSound;
  20.  
  21.         if (swishNum == 1)
  22.                 swishSound = Sound'RifleSelect';
  23.         else
  24.                 swishSound = Sound'RifleSelect';
  25.  
  26.         Player.PlaySound(swishSound, SLOT_None);
  27. }
  28.  
  29. function ActivateView(int newFOV, bool bNewBinocs, bool bInstant)
  30. {
  31.         desiredFOV = Player.DefaultFOV - newFOV;
  32.  
  33.         if (Player != None)
  34.         {
  35.                 curEye = Player.EyeHeight;
  36.                 lastEye = Player.EyeHeight;
  37.                 curLoc = Player.Location;
  38.                 lastLoc = Player.Location;
  39.                 curRot = Player.ViewRotation;
  40.                 lastRot = Player.ViewRotation;
  41.                 curVel = Player.Velocity;
  42.                 lastVel = Player.Velocity;
  43.                 lastJump = 0;
  44.  
  45.                 PlaySwish(1);
  46.                 Player.bob = 0.008;
  47.                 Player.desiredFOV = desiredFOV;
  48.  
  49.                 bViewVisible = True;
  50.                 Show();
  51.         }
  52. }
  53.  
  54. function ShowView()
  55. {
  56.         if (bViewVisible)
  57.         {
  58.                 curEye = Player.EyeHeight;
  59.                 lastEye = Player.EyeHeight;
  60.                 curLoc = Player.Location;
  61.                 lastLoc = Player.Location;
  62.                 curRot = Player.ViewRotation;
  63.                 lastRot = Player.ViewRotation;
  64.                 curVel = Player.Velocity;
  65.                 lastVel = Player.Velocity;
  66.                 lastJump = 0;
  67.  
  68.                 PlaySwish(1);
  69.                 Player.bob = 0.008;
  70.                 Player.SetFOVAngle(desiredFOV);
  71.  
  72.                 Show();
  73.         }
  74. }
  75.  
  76. function DeactivateView()
  77. {
  78.         if (Player != None)
  79.         {
  80.                 PlaySwish(2);
  81.                 Player.bob = Player.Default.bob;
  82.                 Player.DesiredFOV = Player.Default.DefaultFOV;
  83.  
  84.                 bViewVisible = False;
  85.                 Hide();
  86.         }
  87. }
  88.  
  89. function HideView()
  90. {
  91.         if (bViewVisible)
  92.         {
  93.                 Hide();
  94.  
  95.                 PlaySwish(2);
  96.                 Player.bob = Player.Default.bob;
  97.                 Player.SetFOVAngle(Player.Default.DefaultFOV);
  98.         }
  99. }
  100.  
  101. event DrawWindow(GC gc)
  102. {
  103.         local float sightX, sightY, sightWidth, sightHeight;
  104.         local int toffset;
  105.         local float gunTest;
  106.         local float tempLag1,tempLag2;
  107.         local rotator tempRot1,tempRot2;
  108.         local float diffEye;
  109.         local vector diffLoc;
  110.         local rotator diffRot;
  111.         local vector diffVel;
  112.         local float centerDist;
  113.  
  114.         Super(window).DrawWindow(gc);
  115.  
  116.         if (GetRootWindow().parentPawn != None)
  117.         {
  118.                 if (Player.IsInState('Dying'))
  119.                         return;
  120.         }
  121.  
  122.         //--------------------------------------------
  123.         //gun lag stuff
  124.         //--------------------------------------------
  125.         //update variables
  126.         curEye = Player.EyeHeight;
  127.         curLoc = Player.Location;
  128.         curRot = Player.ViewRotation;
  129.         curVel = Player.Velocity;
  130.  
  131.         //update differences
  132.         diffEye = curEye - lastEye;
  133.         if (Abs(diffEye) > 8.0 || Abs(diffEye) < 0.01)
  134.                 diffEye = 0;
  135.  
  136.         diffLoc = curLoc - lastLoc;
  137.  
  138.         tempRot1 = curRot;
  139.         tempRot2 = lastRot;
  140.         if (tempRot1.Pitch >= 32768)
  141.                 tempRot1.Pitch = tempRot1.Pitch - 65536;
  142.         if (tempRot2.Pitch >= 32768)
  143.                 tempRot2.Pitch = tempRot2.Pitch - 65536;
  144.         diffRot = tempRot1 - tempRot2;
  145.         if (diffRot.Yaw >= 32768)
  146.                 diffRot.Yaw = diffRot.Yaw - 65536;
  147.         else if (diffRot.Yaw <= -32768)
  148.                 diffRot.Yaw = diffRot.Yaw + 65536;
  149.  
  150.         diffVel = curVel - lastVel;
  151.         if (Abs(diffVel.X) < 0.1)
  152.                 diffVel.X = 0;
  153.         if (Abs(diffVel.Y) < 0.1)
  154.                 diffVel.Y = 0;
  155.         if (Abs(diffVel.Z) < 0.1)
  156.                 diffVel.Z = 0;
  157.  
  158.         //return to center lag
  159.         if (abs(gunlagX) > 0)
  160.                 gunlagX = gunlagX * 0.5;
  161.         if (abs(gunlagX) < 0.1)
  162.                 gunlagX = 0;
  163.         if (abs(gunlagY) > 0)
  164.                 gunlagY = gunlagY * 0.5;
  165.         if (abs(gunlagY) < 0.1)
  166.                 gunlagY = 0;
  167.  
  168.         //jump lag
  169.         if ((lastJump == 1) && (Player.Physics == PHYS_Falling))
  170.         {
  171.                 gunlagY += 16;
  172.                 lastJump = 0;
  173.         }
  174.         if ((lastVel.Z == 0) && (curVel.Z > 0) && (Player.Physics == PHYS_Falling))
  175.         {
  176.                 gunlagY += 6;
  177.                 lastJump = 1;
  178.         }
  179.  
  180.         //land lag
  181.         if ((lastJump <= -Player.JumpZ) && (Player.Physics == PHYS_Walking))
  182.         {
  183.                 gunlagY += 16;
  184.                 lastJump = 0;
  185.         }
  186.         if ((lastVel.Z <= -Player.JumpZ) && (Player.Physics == PHYS_Walking))
  187.         {
  188.                 gunlagY += 6;
  189.                 lastJump = lastVel.Z;
  190.         }
  191.  
  192.         //look lag
  193.         if (diffRot != rot(0,0,0))
  194.         {
  195.                 tempLag1 = -FClamp(diffRot.Yaw,-3000,3000)/3000*32;
  196.                 tempLag2 = FClamp(diffRot.Pitch,-3000,3000)/3000*32;
  197.                 if (abs(tempLag1) > 1)
  198.                         gunlagX += tempLag1;
  199.                 if (abs(tempLag2) > 1)
  200.                         gunlagY += tempLag2;
  201.         }
  202.  
  203.         //crouch lag
  204.         if (diffEye != 0)
  205.                 gunlagY += FClamp(diffEye,-10,10)/10*8;
  206.  
  207.         //movement lag
  208.         if (diffVel != vect(0,0,0))
  209.         {
  210.                 //forward and back
  211.                 gunTest = normal(vector(lastRot)) dot (diffLoc*vect(1,1,0));
  212.                 if (gunTest > 0.01)
  213.                         gunlagY += FClamp((vsize(curVel)-vsize(lastVel)),-1.6,1.6)/1.6*2;
  214.                 if (gunTest < -0.01)
  215.                         gunlagY -= FClamp((vsize(curVel)-vsize(lastVel)),-1.6,1.6)/1.6*2;
  216.  
  217.                 //left and right
  218.                 gunTest = normal(vector(lastRot+rot(0,-16384,0))) dot (diffLoc*vect(1,1,0));
  219.                 if (gunTest > 0.01)
  220.                         gunlagX += FClamp((vsize(curVel)-vsize(lastVel)),-1.6,1.6)/1.6*2;
  221.                 if (gunTest < -0.01)
  222.                         gunlagX -= FClamp((vsize(curVel)-vsize(lastVel)),-1.6,1.6)/1.6*2;
  223.         }
  224.  
  225.         //update variables
  226.         lastEye = Player.EyeHeight;
  227.         lastLoc = Player.Location;
  228.         lastRot = Player.ViewRotation;
  229.         lastVel = Player.Velocity;
  230.  
  231.         //move in sync with Player bob
  232.         if (abs(Player.WalkBob.X) > 0)
  233.                 gunlagX += Player.WalkBob.X*4;
  234.         if (abs(Player.WalkBob.Z) > 0)
  235.                 gunlagY += Player.WalkBob.Z*4;
  236.  
  237.         //make sure we stay in reticle
  238.         gunlagX = FClamp(gunlagX,-32,32);
  239.         gunlagY = FClamp(gunlagY,-32,32);
  240.  
  241.  
  242.         //--------------------------------------------
  243.         //draw ironsights
  244.         //--------------------------------------------
  245.         sightWidth   = 256;
  246.         sightHeight  = 256;
  247.         sightX = (width-sightWidth)*0.5;
  248.         sightY = (height-sightHeight)*0.5;
  249.  
  250.         //timing for shooting animation
  251.         toffset = 26.0 * (Player.Level.TimeSeconds % 0.2);
  252.  
  253.         //some day...
  254.         //if (WeaponPistolY(Player.inHand) != None)
  255.         //{
  256.         //}
  257.  
  258.  
  259.         if (WeaponSMG5(Player.inHand) != None)
  260.         {
  261.                 //draw that annoying vignetting crap that every single game has these days
  262.                 gc.SetStyle(DSTY_Modulated);
  263.                 gc.DrawPattern(0,        0,          width, 128,    4,  128, Texture'HUDGradient1');
  264.                 gc.DrawPattern(0,        height-128, width, 128,    4,  128, Texture'HUDGradient2');
  265.                 gc.DrawPattern(0,        0,          64,    height, 64, 4,   Texture'HUDGradient3');
  266.                 gc.DrawPattern(width-64, 0,          64,    height, 64, 4,   Texture'HUDGradient4');
  267.  
  268.                 //if we're shooting, cycle through muzzleflashes and both ironsight sizes
  269.                 if (WeaponSMG5(Player.inHand).bFiring && WeaponSMG5(Player.inHand).IsAnimating() && (WeaponSMG5(Player.inHand).AnimSequence == 'Shoot'))
  270.                 {
  271.                         if (toffset == 0)
  272.                         {
  273.                                 gc.SetStyle(DSTY_Modulated);
  274.                                 gc.DrawTexture(sightX+gunlagX, sightY+gunlagY-24, sightWidth, sightHeight, 0, 0, Texture'HUDIronSights1b');
  275.                                 gc.DrawTexture(sightX+gunlagX, sightY+256+gunlagY-24, sightWidth, sightHeight, 0, 0, Texture'HUDIronSights2b');
  276.                                 gc.DrawPattern(sightX+gunlagX, sightY+512+gunlagY-24, sightWidth, sightY, 0, 0, Texture'HUDIronSights3b');
  277.                                 gc.DrawPattern(sightX+gunlagX, height-64, sightWidth, sightY, 0, 0, Texture'HUDIronSights4b');
  278.                                 gc.SetStyle(DSTY_Translucent);
  279.                                 gc.DrawTexture(sightX+gunlagX, sightY+72+gunlagY-24, 256, 256, 0, 0, Texture'HUDMuzzleFlash1');
  280.                         }
  281.                         else if (toffset == 1)
  282.                         {
  283.                                 gc.SetStyle(DSTY_Modulated);
  284.                                 gc.DrawTexture(sightX+gunlagX, sightY+gunlagY-16, sightWidth, sightHeight, 0, 0, Texture'HUDIronSights1b');
  285.                                 gc.DrawTexture(sightX+gunlagX, sightY+256+gunlagY-16, sightWidth, sightHeight, 0, 0, Texture'HUDIronSights2b');
  286.                                 gc.DrawPattern(sightX+gunlagX, sightY+512+gunlagY-16, sightWidth, sightY, 0, 0, Texture'HUDIronSights3b');
  287.                                 gc.DrawPattern(sightX+gunlagX, height-64, sightWidth, sightY, 0, 0, Texture'HUDIronSights4b');
  288.                                 gc.SetStyle(DSTY_Translucent);
  289.                                 gc.DrawTexture(sightX+gunlagX, sightY+72+gunlagY-16, 256, 256, 0, 0, Texture'HUDMuzzleFlash2');
  290.                         }
  291.                         else if (toffset == 3)
  292.                         {
  293.                                 gc.SetStyle(DSTY_Modulated);
  294.                                 gc.DrawTexture(sightX+gunlagX, sightY+gunlagY-24, sightWidth, sightHeight, 0, 0, Texture'HUDIronSights1b');
  295.                                 gc.DrawTexture(sightX+gunlagX, sightY+256+gunlagY-24, sightWidth, sightHeight, 0, 0, Texture'HUDIronSights2b');
  296.                                 gc.DrawPattern(sightX+gunlagX, sightY+512+gunlagY-24, sightWidth, sightY, 0, 0, Texture'HUDIronSights3b');
  297.                                 gc.DrawPattern(sightX+gunlagX, height-64, sightWidth, sightY, 0, 0, Texture'HUDIronSights4b');
  298.                                 gc.SetStyle(DSTY_Translucent);
  299.                                 gc.DrawTexture(sightX+gunlagX, sightY+72+gunlagY-24, 256, 256, 0, 0, Texture'HUDMuzzleFlash3');
  300.                         }
  301.                         else if (toffset == 4)
  302.                         {
  303.                                 gc.SetStyle(DSTY_Modulated);
  304.                                 gc.DrawTexture(sightX+gunlagX, sightY+gunlagY-16, sightWidth, sightHeight, 0, 0, Texture'HUDIronSights1b');
  305.                                 gc.DrawTexture(sightX+gunlagX, sightY+256+gunlagY-16, sightWidth, sightHeight, 0, 0, Texture'HUDIronSights2b');
  306.                                 gc.DrawPattern(sightX+gunlagX, sightY+512+gunlagY-16, sightWidth, sightY, 0, 0, Texture'HUDIronSights3b');
  307.                                 gc.DrawPattern(sightX+gunlagX, height-64, sightWidth, sightY, 0, 0, Texture'HUDIronSights4b');
  308.                                 gc.SetStyle(DSTY_Translucent);
  309.                                 gc.DrawTexture(sightX+gunlagX, sightY+72+gunlagY-16, 256, 256, 0, 0, Texture'HUDMuzzleFlash4');
  310.                         }
  311.                         else
  312.                         {
  313.                                 gc.SetStyle(DSTY_Modulated);
  314.                                 gc.DrawTexture(sightX+gunlagX, sightY+gunlagY-8, sightWidth, sightHeight, 0, 0, Texture'HUDIronSights1a');
  315.                                 gc.DrawTexture(sightX+gunlagX, sightY+256+gunlagY-8, sightWidth, sightHeight, 0, 0, Texture'HUDIronSights2a');
  316.                                 gc.DrawPattern(sightX+gunlagX, sightY+512+gunlagY-8, sightWidth, sightY, 0, 0, Texture'HUDIronSights3a');
  317.                                 gc.DrawPattern(sightX+gunlagX, height-64, sightWidth, sightY, 0, 0, Texture'HUDIronSights4a');
  318.                         }
  319.                 }
  320.                 else
  321.                 {
  322.                         //if we're crouching, use the large ironsights
  323.                         if (Player.bForceDuck || Player.bIsCrouching)
  324.                         {
  325.                                 gc.SetStyle(DSTY_Modulated);
  326.                                 gc.DrawTexture(sightX+gunlagX, sightY+gunlagY-22, sightWidth, sightHeight, 0, 0, Texture'HUDIronSights1b');
  327.                                 gc.DrawTexture(sightX+gunlagX, sightY+256+gunlagY-22, sightWidth, sightHeight, 0, 0, Texture'HUDIronSights2b');
  328.                                 gc.DrawPattern(sightX+gunlagX, sightY+512+gunlagY-22, sightWidth, sightY, 0, 0, Texture'HUDIronSights3b');
  329.                                 gc.DrawPattern(sightX+gunlagX, height-64, sightWidth, sightY, 0, 0, Texture'HUDIronSights4b');
  330.                         }
  331.                         //use the basic ironsights
  332.                         else
  333.                         {
  334.                                 gc.SetStyle(DSTY_Modulated);
  335.                                 gc.DrawTexture(sightX+gunlagX, sightY+gunlagY, sightWidth, sightHeight, 0, 0, Texture'HUDIronSights1a');
  336.                                 gc.DrawTexture(sightX+gunlagX, sightY+256+gunlagY, sightWidth, sightHeight, 0, 0, Texture'HUDIronSights2a');
  337.                                 gc.DrawPattern(sightX+gunlagX, sightY+512+gunlagY, sightWidth, sightY, 0, 0, Texture'HUDIronSights3a');
  338.                                 gc.DrawPattern(sightX+gunlagX, height-64, sightWidth, sightY, 0, 0, Texture'HUDIronSights4a');
  339.                         }
  340.                 }      
  341.         }
  342. }
clone this paste RAW Paste Data