Advertisement
xNos

Hp Regeneration

Feb 1st, 2013
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.67 KB | None | 0 0
  1. /* Plugin Template generated by Pawn Studio */
  2. /*
  3. 1.2:
  4. Added "AutoExecConfig"
  5. 1.0:
  6. This is original version of Hp Regeneration by xNos.
  7.  
  8.  
  9. ConVars:
  10. sm_regeneration_enabeld "1"     -   ( Default: 1    )       -   Enables Hp Regeneration
  11. sm_regeneration_timer   "1.0"   -   ( Default: 1.0  )       -   After how match sec the client get his regeneration
  12. sm_regeneration_maxhp   "100"   -   ( Default: 100  )       -   Whats the maximum hp the player can get
  13. sm_regeneration_amount  "10"    -   ( Default: 10   )       -   How match hp the player gets every regenerate
  14.  
  15. Credit to sNeeP for the "IsValidClient" Code.
  16. */
  17.  
  18.  
  19. #pragma semicolon 1
  20.  
  21. #include <sourcemod>
  22. #include <sdktools>
  23.  
  24. new Handle:g_rEnabled;
  25. new Handle:g_rTimer;
  26. new Handle:g_rMaxHp;
  27. new Handle:g_rAmount;
  28.  
  29. public Plugin:myinfo =
  30. {
  31.     name = "Hp Regeneration",
  32.     author = "xNos",
  33.     description = "Regeneration the player hp after getting hurt.",
  34.     version = "1.2",
  35.     url = "HL2.co.il"
  36. }
  37.  
  38. public OnPluginStart()
  39. {
  40.     g_rEnabled  =   CreateConVar( "sm_regeneration_enabeld", "1", "Enables Hp Regeneration" );                              //( Default: 1 )
  41.     g_rTimer    =   CreateConVar( "sm_regeneration_timer", "1.0", "After how match sec the client get his regeneration" )//( Default: 1.0 )
  42.     g_rMaxHp    =   CreateConVar( "sm_regeneration_maxhp", "100", "Whats the maximum hp the player can get" );              //( Default: 100 )
  43.     g_rAmount   =   CreateConVar( "sm_regeneration_amount", "10", "How match hp the player gets every regenerate" );        //( Default: 10 )
  44.    
  45.     CreateTimer( GetConVarFloat( g_rTimer ), HpRegeneration, _, TIMER_REPEAT );
  46.    
  47.     AutoExecConfig( true, "HpRegeneration" );
  48. }
  49. public Action:HpRegeneration( Handle:timer )
  50. {
  51.     for( new i; i <= MaxClients; i++ )
  52.     {
  53.         if( IsValidClient( i, true ) )
  54.         {
  55.             if( GetConVarInt( g_rEnabled ) )
  56.             {
  57.                 new ClientHealth = GetClientHealth( i );
  58.                
  59.                 if( ClientHealth > ( GetConVarInt( g_rMaxHp ) ) )
  60.                 {
  61.                     SetClientHealth( i, GetConVarInt( g_rMaxHp ) );
  62.                     return Plugin_Handled;
  63.                 }
  64.                
  65.                 if( ClientHealth < GetConVarInt( g_rMaxHp ) )
  66.                 {
  67.                     SetClientHealth( i, ClientHealth + GetConVarInt( g_rAmount ) );
  68.                     return Plugin_Handled;
  69.                 }
  70.                
  71.                 return Plugin_Handled;
  72.             }
  73.            
  74.             return Plugin_Handled;
  75.         }
  76.     }
  77.    
  78.     return Plugin_Handled;
  79. }
  80.  
  81. SetClientHealth( Client, amount )
  82. {
  83.     new HealthOffs = FindDataMapOffs( Client, "m_iHealth" );
  84.     SetEntData( Client, HealthOffs, amount, true );
  85. }
  86. stock bool:IsValidClient( Client, bool:bAlive = false )
  87. {
  88.     if( Client >= 1 && Client <= MaxClients && IsClientConnected( Client ) && IsClientInGame( Client ) && !IsFakeClient( Client ) && !IsClientSourceTV( Client ) && ( bAlive == false || IsPlayerAlive( Client ) ) )
  89.     {
  90.         return true;
  91.     }
  92.    
  93.     return false;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement