Hp change detection, + 0HP bug fix (only need if players can have more than 255HP).
I use this method because i figured out that Health message is not sent all time for reasons i don't understand.
PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <fun>
#define m_iClientHealth 359
new g_iClientHealth[MAX_PLAYERS+1]
new gmsgHealth
public plugin_init()
{
register_plugin( PLUGIN, VERSION, AUTHOR )
register_forward(FM_UpdateClientData, "UpdateClientData")
gmsgHealth = get_user_msgid("Health")
}
public UpdateClientDatar(id)
{
new iHealth = get_user_health(id)
if( g_iClientHealth[id] != iHealth )
{
// player hp has changed
g_iClientHealth[id] = iHealth
// 0 HP bug fix
if( iHealth && iHealth % 256 == 0 )
{
iHealth -= 1
set_pdata_int(id, m_iClientHealth, iHealth)
set_user_health(id, iHealth)
message_begin(MSG_ONE, gmsgHealth, _, id)
write_byte(iHealth)
message_end()
return FMRES_HANDLED
}
}
return FMRES_IGNORED
}
__________________