Pushok

SourcePawn Medkit

Mar 7th, 2011
729
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.71 KB | None | 0 0
  1. #pragma semicolon 1
  2.  
  3. #include <sourcemod>
  4. #include <cstrike>
  5.  
  6. #define PLUGIN_VERSION "1.0"
  7. #define MSG "\x03[Medkits] \x01%t"
  8.  
  9.  public Plugin:myinfo =
  10. {
  11.     name = "Medkit",
  12.     author = "Push",
  13.     description = "Allow to use medkits",
  14.     version = PLUGIN_VERSION,
  15.     url = "http://css-quad.ru"
  16. };
  17.  
  18. new Handle:medkit_team = INVALID_HANDLE;
  19. new Handle:medkit_amount = INVALID_HANDLE;
  20. new Handle:medkit_health_ps = INVALID_HANDLE;
  21. new Handle:medkit_fullhealth = INVALID_HANDLE;
  22. new Handle:medkit_maxhealth = INVALID_HANDLE;
  23. new Handle:medkit_timer_tick = INVALID_HANDLE;
  24. new bool:bAlreadyUses[MAXPLAYERS+1];
  25. new Handle:hTimer[MAXPLAYERS+1] = INVALID_HANDLE;
  26. new iMedKits[MAXPLAYERS+1], iHPCount[MAXPLAYERS+1];
  27.  
  28. public OnPluginStart()
  29. {
  30.     LoadTranslations("medkit.phrases");
  31.    
  32.     medkit_team = CreateConVar("medkit_team","1","1 - all/2 - t/3 - ct");
  33.     medkit_amount = CreateConVar("medkit_amount","5","amount of medkits for player");
  34.     medkit_health_ps = CreateConVar("medkit_health_ps","5","health per secound");
  35.     medkit_fullhealth = CreateConVar("medkit_fullhealth","30","full health");
  36.     medkit_timer_tick = CreateConVar("medkit_timer_tick","0.5","timer ticks");
  37.     medkit_maxhealth = CreateConVar("medkit_maxhealth","101","maximum health");
  38.     HookEvent("round_start",OnRoundStart);
  39.     HookEvent("round_end",OnRoundEnded);
  40.     RegConsoleCmd("medkit",GiveMedKit);
  41. }
  42.  
  43. public OnRoundStart(Handle:event, const String:name[], bool:dontBroadcast)
  44. {
  45.     for(new i = 1; i < MaxClients; i++){
  46.         hTimer[i] = INVALID_HANDLE;
  47.         iMedKits[i] = GetConVarInt(medkit_amount);
  48.         bAlreadyUses[i] = false;
  49.         iHPCount[i] = 0;
  50.     }
  51. }
  52.  
  53. public OnRoundEnded(Handle:event, const String:name[], bool:dontBroadcast)
  54. {
  55.     for(new i=1;i<=MaxClients;i++)
  56.     {
  57.         if(bAlreadyUses[i] && hTimer[i] != INVALID_HANDLE)
  58.             KillTimer(hTimer[i]);
  59.     }
  60. }
  61.  
  62. public Action:GiveMedKit(client,args)
  63. {
  64.     if(args || bAlreadyUses[client]) return Plugin_Continue;
  65.     if(GetClientHealth(client) >= GetConVarInt(medkit_maxhealth))
  66.     {
  67.         PrintToChat(client,MSG,"You already have maximum health");
  68.         return Plugin_Continue;
  69.     }
  70.     bAlreadyUses[client] = true;
  71.     new cvTeam = GetConVarInt(medkit_team);
  72.     new iTeam = (cvTeam == 1 ? 0 : (cvTeam == 2 ? CS_TEAM_T : CS_TEAM_CT));
  73.     new Float:fTimerTicks = GetConVarFloat(medkit_timer_tick);
  74.     iMedKits[client]--;
  75.     if((!iTeam || GetClientTeam(client) == iTeam) && fTimerTicks && IsPlayerAlive(client))
  76.     {
  77.         if(iMedKits[client] == -1)
  78.         {
  79.             PrintToChat(client,MSG,"You have not more kits");
  80.             return Plugin_Continue;
  81.         }
  82.         PrintToChat(client,MSG,"Left",iMedKits[client]);
  83.         hTimer[client] = CreateTimer(fTimerTicks,GiveHealth,client,TIMER_REPEAT);
  84.     }
  85.     return Plugin_Continue;
  86. }
  87.  
  88. public Action:GiveHealth(Handle:timer,any:client)
  89. {
  90.     new MaxHealth = GetConVarInt(medkit_maxhealth), iHPFull = GetConVarInt(medkit_fullhealth), iAddiction;
  91.    
  92.     if(GetConVarInt(medkit_health_ps) > iHPFull)
  93.         SetConVarInt(medkit_health_ps,iHPFull);
  94.        
  95.     new iHPPSec = GetConVarInt(medkit_health_ps);
  96.    
  97.     if(GetClientHealth(client) > MaxHealth)
  98.         SetEntityHealth(client,MaxHealth);
  99.        
  100.     if(IsPlayerAlive(client) && (GetClientHealth(client) == MaxHealth || iHPCount[client] >= iHPFull))
  101.     {
  102.         iHPCount[client] = 0;
  103.         bAlreadyUses[client] = false;
  104.         PrintToChat(client,MSG,"You cant have more health");
  105.         KillTimer(timer);
  106.         return Plugin_Continue;
  107.     }
  108.    
  109.     iHPCount[client] += iHPPSec;
  110.    
  111.     if(iHPCount[client] <= iHPFull){
  112.         iAddiction = GetClientHealth(client) + iHPPSec;
  113.     }
  114.     else if(iHPCount[client] > iHPFull)
  115.     {
  116.         iAddiction = (GetClientHealth(client) + iHPPSec) - (iHPCount[client] - iHPFull);       
  117.         iHPCount[client] = iHPFull;
  118.     }
  119.    
  120.     SetEntityHealth(client, MaxHealth >= iAddiction ? iAddiction : iAddiction - (iAddiction - MaxHealth));
  121.    
  122.     return Plugin_Continue;
  123. }
Advertisement
Add Comment
Please, Sign In to add comment