I know this has been posted before by naris, but it had all these unnecessary files and stocks, so I made a shorter one a while back (just in case I'd ever need it), and now I'm posting it here
Code:
#include <sourcemod>
#include <sdktools>
new g_iHealth[MAXPLAYERS + 1];
new g_iMaxClients;
public OnPluginStart() {
HookEntityOutput("item_healthkit_small", "OnPlayerTouch", EntityOutput_SaveHealth);
HookEntityOutput("item_healthkit_medium", "OnPlayerTouch", EntityOutput_SaveHealth);
HookEntityOutput("item_healthkit_full", "OnPlayerTouch", EntityOutput_SaveHealth);
HookEntityOutput("prop_dynamic", "OnAnimationBegun", EntityOutput_SaveHealthAll);
HookEvent("player_hurt", Event_PlayerHurt);
HookEvent("player_spawn", Event_PlayerSpawn);
}
public OnMapStart() {
g_iMaxClients = GetMaxClients();
}
public EntityOutput_SaveHealth(const String:output[], caller, activator, Float:delay) {
g_iHealth[activator] = GetClientHealth(activator);
}
public EntityOutput_SaveHealthAll(const String:output[], caller, activator, Float:delay) {
for (new i = 1; i <= g_iMaxClients; i++) {
if (IsClientInGame(i) && !IsClientObserver(i)) {
g_iHealth[i] = GetClientHealth(i);
}
}
}
public Action:Event_PlayerHurt(Handle:event, const String:name[], bool:dontBroadcast) {
new iClient = GetClientOfUserId(GetEventInt(event, "userid")),
iHealth = GetEventInt(event, "health");
PrintToChat(iClient, "Damage: %d", g_iHealth[iClient] - iHealth);
g_iHealth[iClient] = iHealth;
}
public Action:Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast) {
CreateTimer(0.1, Timer_SaveHealth, GetClientOfUserId(GetEventInt(event, "userid")));
}
public Action:Timer_SaveHealth(Handle:timer, any:client) {
g_iHealth[client] = GetClientHealth(client);
}