I was searching the web for a base to write my plugin on and I found
this piece of code:
Code:
public Action OnPlayerDeath(Handle event, char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(GetEventInt(event, "attacker"));
int dead = GetClientOfUserId(GetEventInt(event, "userid"));
if (GetConVarBool(g_Cvar_HealthRegenEnabled))
{
if (HasClientFlag(client, ADMFLAG_RESERVATION))
{
int OldHealth = GetEntProp(client, Prop_Send, "m_iHealth", 4, 0);
if (dead != client)
{
if (GetClientTeam(client) > 1)
{
g_iHealthRegenedQuantity = GetConVarInt(g_Cvar_HealthRegenedQuantity);
g_iMaxHealth = GetConVarInt(g_Cvar_MaxHealthQuantity);
if (g_iHealthRegenedQuantity + OldHealth > g_iMaxHealth)
{
SetEntProp(client, Prop_Send, "m_iHealth", g_iMaxHealth, 4, 0);
}
else
{
SetEntProp(client, Prop_Send, "m_iHealth", OldHealth + g_iHealthRegenedQuantity, 4, 0);
}
}
}
}
}
}
After editing it to my needs, the code looked like this:
Code:
public Action OnPlayerDeath(Handle event, char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(GetEventInt(event, "attacker"));
int dead = GetClientOfUserId(GetEventInt(event, "userid"));
if (CheckCommandAccess(client, "", ADMFLAG_NEEDED, true))
{
int OldHealth = GetEntProp(client, Prop_Send, "m_iHealth", 4, 0);
if (dead != client)
{
if (GetClientTeam(client) > 1)
{
int g_iHealthRegenedQuantity = 10;
int g_iMaxHealth = 150;
if (g_iHealthRegenedQuantity + OldHealth > g_iMaxHealth)
{
SetEntProp(client, Prop_Send, "m_iHealth", g_iMaxHealth, 4, 0);
}
else
{
SetEntProp(client, Prop_Send, "m_iHealth", (OldHealth + g_iHealthRegenedQuantity), 4, 0);
}
}
}
}
}
My problem is that when someone is killed, the attacker does not get more 10 HP as intended.
Basically, this is the scheme:
- When someone is killed, the attacker gets +10 HP;
- The max health should be 150;
Can anyone explain what am I doing wrong?