#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#define CVAR_FLAGS FCVAR_NOTIFY
ConVar z_difficulty, EasyTankHP, MediumTankHp, HardTankHP, ImpossibleTankHP;
static float TankBurnIndex;
int iEasyTankHP, iMediumTankHp, iHardTankHP, iImpossibleTankHP;
public void OnPluginStart()
{
EasyTankHP = CreateConVar("EasyTankHP", "2000", "Tank hp on per client on easy difficulty", CVAR_FLAGS);
MediumTankHp = CreateConVar("MediumTankHp", "4000", "Tank hp on per client on Medium difficulty", CVAR_FLAGS);
HardTankHP = CreateConVar("HardTankHP", "6000", "Tank hp on per client on Hard difficulty", CVAR_FLAGS);
ImpossibleTankHP = CreateConVar("ImpossibleTankHP", "8000", "Tank hp on per client on Impossible difficulty", CVAR_FLAGS);
iEasyTankHP = EasyTankHP.IntValue;
EasyTankHP.AddChangeHook(CvarsChanged);
iMediumTankHp = MediumTankHp.IntValue;
MediumTankHp.AddChangeHook(CvarsChanged);
iHardTankHP = HardTankHP.IntValue;
HardTankHP.AddChangeHook(CvarsChanged);
iImpossibleTankHP = ImpossibleTankHP.IntValue;
ImpossibleTankHP.AddChangeHook(CvarsChanged);
z_difficulty = FindConVar("z_difficulty");
z_difficulty.AddChangeHook(OnCVarChange);
AutoExecConfig(true, "tank_hp_control");
HookEvent("tank_spawn", OnTankSpawn);
}
public void OnConfigsExecuted()
{
OnCvarChange();
}
void OnCVarChange(ConVar hCvar, const char[] sOldValue, const char[] sNewValue)
{
OnCvarChange();
}
void OnCvarChange()
{
static char sBuffer[64];
z_difficulty.GetString( sBuffer, sizeof( sBuffer ) );
if ( strncmp( sBuffer, "Easy", sizeof( sBuffer ), false ) == 0 ) TankBurnIndex = 0.011666;
else if ( strncmp( sBuffer, "Hard", sizeof( sBuffer ), false ) == 0 ) TankBurnIndex = 0.013333;
else if ( strncmp( sBuffer, "Impossible", sizeof( sBuffer ), false ) == 0 ) TankBurnIndex = 0.014166;
else TankBurnIndex = 0.0125;
}
void CvarsChanged(ConVar hCvar, const char[] sOldValue, const char[] sNewValue )
{
Cvars();
}
void Cvars()
{
iEasyTankHP = EasyTankHP.IntValue;
iMediumTankHp = MediumTankHp.IntValue;
iHardTankHP = HardTankHP.IntValue;
iImpossibleTankHP = ImpossibleTankHP.IntValue;
}
int GetTankHP()
{
int TankHP = 4000, count = 0;
for (int i = 1; i <= MaxClients; i++)
{
if (IsClientConnected(i))
{
if (IsClientInGame(i))
{
if(GetClientTeam(i) == 2)
{
if(!IsFakeClient(i))
{
count++;
}
}
}
}
}
char sGameDifficulty[16];
z_difficulty.GetString(sGameDifficulty, sizeof(sGameDifficulty));
float TankBurnTime = float( TankHP ) * TankBurnIndex;
int TankBurnHP = RoundToCeil( TankBurnTime );
if (StrEqual(sGameDifficulty, "Easy", false))
{
TankHP = iEasyTankHP * count;
FindConVar("tank_burn_duration").IntValue = TankBurnHP;
}
else if (StrEqual(sGameDifficulty, "Medium", false))
{
TankHP = iMediumTankHp * count;
FindConVar("tank_burn_duration").IntValue = TankBurnHP;
}
else if (StrEqual(sGameDifficulty, "Hard", false))
{
TankHP = iHardTankHP * count;
FindConVar("tank_burn_duration_hard").IntValue = TankBurnHP;
}
else if (StrEqual(sGameDifficulty, "Impossible", false))
{
TankHP = iImpossibleTankHP * count;
FindConVar("tank_burn_duration_expert").IntValue = TankBurnHP;
}
return TankHP;
}
public Action OnTankSpawn(Event event, const char[] name, bool dontBroadcast)
{
int tank = GetClientOfUserId(event.GetInt("userid"));
if(tank && IsClientInGame(tank))
{
int HP = GetTankHP();
SetEntProp(tank, Prop_Data, "m_iMaxHealth", HP);
SetEntProp(tank, Prop_Data, "m_iHealth", HP);
}
}