Thank you very much connorr!
(And thank you, Alka, and arkshine for helping out too!)
You should release that! I´m just off to test it
I made some modifications to the code though, to make it neater. Here it is:
Code:
/********************************************************
* *
* Health on Frag *
* By TheLinx ([email protected]) *
* *
* Credits: *
* connorr - Telling how to do all these FM thingys. *
* *
********************************************************/
#include <amxmodx>
#include <fakemeta>
#define PLUGIN "Health on Frag"
#define VERSION "1.0"
#define AUTHOR "TheLinx"
#define OFFSET_TEAM 114
#define user_team(%1) get_pdata_int(%1, OFFSET_TEAM)
/* Set PCVars */
new pcvar_enabled, pcvar_health, pcvar_health_max, pcvar_health_extra_hs, pcvar_givehp_tk
/* Other Variables */
new g_max_clients
public plugin_init
()
{ // Initiate the plugin.
register_plugin(PLUGIN, VERSION, AUTHOR
)
/* Define PCVars */
pcvar_enabled
= register_cvar("amx_hponfrag_enabled",
"1")
pcvar_health
= register_cvar("amx_hponfrag_health",
"25")
pcvar_health_max
= register_cvar("amx_hponfrag_health_max",
"175")
pcvar_health_extra_hs
= register_cvar("amx_hponfrag_health_extra_hs",
"25")
pcvar_givehp_tk
= register_cvar("amx_hponfrag_givehp_tk",
"1")
/* Events */
register_event("DeathMsg",
"event_death",
"a",
"1>0")
}
public plugin_cfg
()
{ // On plugin load
g_max_clients
= global_get
(glb_maxClients
)
}
public event_death
()
{ // On frag
if (!get_pcvar_num(pcvar_enabled
))
return // The plugin is disabled, cancel.
new id_killer
= read_data(1)
if (id_killer > g_max_clients
)
return // Killer is not a player, cancel.
new id_victim
= read_data(2)
if (!get_pcvar_num(pcvar_givehp_tk
))
{ // Ignoring giving HP if it was a TK is enabled.
if (user_team
(id_victim
) == user_team
(id_killer
))
return // It was a TK, cancel.
}
new var_headshot
= read_data(3) // Was it a HS?
new Float:var_hptogive
switch (var_headshot
)
{
case 0: var_hptogive
= get_pcvar_float(pcvar_health
)
case 1: var_hptogive
= get_pcvar_float(pcvar_health_extra_hs
)
}
if (!var_hptogive
)
return // Something went wrong, cancel.
new Float:id_killer_hp
pev
(id_killer, pev_health, id_killer_hp
)
new Float:var_maxhp
= get_pcvar_float(pcvar_health_max
)
if (id_killer_hp
== var_maxhp
)
return // The client have the maximum HP already, cancel.
if (var_maxhp
- var_hptogive > id_killer_hp
)
set_pev
(id_killer, pev_health, id_killer_hp
+ var_hptogive
)
else
set_pev
(id_killer, pev_health, var_maxhp
)
}
I also added an CVar to set if you should abort the giving HP if it was a TK, pretty useful if you, like me, are running an FFA server ;)