One simple approach would be to iterate over all players, check if their active weapon has a healing target (and is a medigun), then add your condition:
Code:
public void OnGameFrame() {
// you could also add a frame skip e.g. if (GetGameTickCount() % 3) { return; }
for (int i = 1; i <= MaxClients; i++) {
if (!IsClientInGame(i) || !IsPlayerAlive(i)) {
// player isn't available
continue;
}
int activeWeapon = GetEntPropEnt(i, Prop_Send, "m_hActiveWeapon");
if (!IsValidEntity(activeWeapon) || !HasEntProp(activeWeapon, Prop_Send, "m_hHealingTarget")) {
// no weapon active or weapon isn't medigun
continue;
}
int healTarget = GetEntPropEnt(activeWeapon, Prop_Send, "m_hHealingTarget");
if (!IsValidEntity(healTarget) || healTarget < 1 || healTarget > MaxClients) {
// no heal target, or heal target isn't player
continue;
}
// player `i` is healing player `healTarget` with a medigun, do stuff here
}
}
Since that runs every frame, you can set a duration on
TF2_AddCondition that is long enough that the uber / kritz is still applied by the next time the check runs.
If anything's unclear, just ask.
----
Further advice / review:
- Your formatting style is fine.
- Replace Handle g_hEnabled; with ConVar g_hEnabled; -- this lets you use the ConVar methodmap, and you can then use g_hEnabled.BoolValue instead of GetConVarInt(g_hEnabled). You can also drop the == 1; all non-zero values are treated as "truthy", and will evaluate to true.
- Use the TFClass_Medic value instead of doing the lookup with TF2_GetClass("medic").
- For future event hooks, you can also remove patientId and healerId by inlining those operations like so:
Code:
int patient = GetClientOfUserId(event.GetInt("patient"));
__________________