// PsychoDamage, Copyright 2002, PsychoGuard. No warranties.
// Props to OLO for all the great Metamod plugins he developed.
//
// Mirror team attack damage during round start. Victims are not harmed.
//
// Cvars:
//   pd_tdsafety     Time in seconds during which team attacks are
//                   mirrored after round start. Default: 10 seconds.


#include <amxmod>

// Indicates when (in terms of get_gametime()) the safety against team
// attacks ends.
new Float:td_safety = 0.0;

public damage_event() {
    new dmg = read_data(2);

    if (td_safety > get_gametime()) {
        new victim = read_data(0);
        new weapon;
        new attacker = get_user_attacker(victim, weapon);

        if (attacker != victim && get_user_team(victim) == get_user_team(attacker)) {
            set_user_health(victim, get_user_health(victim) + dmg);
            set_user_health(attacker, get_user_health(attacker) - dmg);

            set_user_rendering(attacker,kRenderFxGlowShell,128,0,0,kRenderNormal,16);
            client_cmd(attacker, "spk barney/donthurtem");
        }
    }

    return PLUGIN_CONTINUE;
}

public roundtime(id) {
    new remaining = read_data(1);

    if (remaining == get_cvar_float("mp_roundtime") * 60) {
        td_safety = get_gametime() + get_cvar_float("pd_tdsafety");
    }

    return PLUGIN_CONTINUE;
}

public reset_hud(id) {
    set_user_rendering(id);
}

public plugin_init() {
    register_plugin("PsychoDamage", "0.8.4", "PsychoGuard");

    register_event("RoundTime", "roundtime", "bc");
    register_event("Damage", "damage_event", "b", "2!0");
    register_event("ResetHUD", "reset_hud", "b");

    register_cvar("pd_tdsafety", "10.0");

    return PLUGIN_CONTINUE;
}
