Advertisement
Shepard62700FR

MP5 - Basic logic of overheating system

Jan 29th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. void CMP5::Spawn( )
  2. {
  3.     // Spawn code here
  4.     m_iHeat = 0; // Shepard : By default our weapon hasn't heated
  5. }
  6.  
  7. void CMP5::PrimaryAttack()
  8. {
  9.     // Shepard : Cool down our weapon if we can't fire
  10.     Cooldown();
  11.  
  12.     // Check if firing underwater and gun is empty code here
  13.  
  14.     // Shepard : deny weapon firing if weapon has overheated
  15.     if ( m_iHeat >= 100 )
  16.     {
  17.         PlayEmptySound();
  18.         m_flNextPrimaryAttack = 0.15f;
  19.         return;
  20.     }
  21.  
  22.     // Shepard : Increment heating (and prevent to go higher than 100%)
  23.     m_iHeat += 5;
  24.     if ( m_iHeat > 100 )
  25.         m_iHeat = 100;
  26.  
  27.     // Effects, event, firing, accuracy code here
  28.  
  29. #ifndef CLIENT_DLL
  30.     m_flCooldownTime = gpGlobals->time + 3.0f; // Shepard : This forces the player to wait 3 seconds for the weapon to cool down
  31. #endif
  32. }
  33.  
  34. void CMP5::WeaponIdle( void )
  35. {
  36.     // Shepard : Cool down the weapon (if we can)
  37.     Cooldown();
  38.  
  39.     // Idle animation code here
  40. }
  41.  
  42. // Shepard : Cool down the weapon
  43. void CMP5::Cooldown( void )
  44. {
  45.     // For debugging purposes, you can remove that and replace by your HUD update code
  46. #ifndef CLIENT_DLL
  47.     ALERT( at_console, "Heat = %d - Game time = %f - Cool down time = %2f\n", m_iHeat, gpGlobals->time, m_flCooldownTime );
  48. #endif
  49.  
  50.     // Disallow negative values
  51.     if ( m_iHeat <= 0 )
  52.     {
  53.         //m_iHeat = 0; // If you decrement by 1%, that line is NOT needed, otherwise you'll need it (you don't want to have -1%)
  54.         return;
  55.     }
  56.  
  57.     // Perform the real cool down
  58.     while ( m_iHeat > 0 && m_flCooldownTime < gpGlobals->time)
  59.     {
  60.         m_iHeat--;
  61.         m_flCooldownTime += 0.5f;
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement