added interval
This commit is contained in:
parent
a6bb1c8c4a
commit
13ad96c36f
@ -295,6 +295,7 @@ List& MainList() {
|
||||
"spyalert_warning"
|
||||
"spyalert_backstab"
|
||||
"spyalert_sound"
|
||||
"spyalert_interval"
|
||||
]
|
||||
|
||||
"Miscellaneous" [
|
||||
|
@ -16,15 +16,20 @@ CatVar enabled(CV_SWITCH, "spyalert_enabled", "0", "Enable", "Master SpyAlert sw
|
||||
CatVar distance_warning(CV_FLOAT, "spyalert_warning", "500.0", "Warning distance", "Distance where yellow warning shows");
|
||||
CatVar distance_backstab(CV_FLOAT, "spyalert_backstab", "200.0", "Backstab distance", "Distance where red warning shows");
|
||||
CatVar sound_alerts(CV_SWITCH, "spyalert_sound", "1", "Sound Alerts", "???");
|
||||
CatVar sound_alert_interval(CV_FLOAT, "spyalert_interval", "3", "Alert Interval", "Sound alert interval");
|
||||
|
||||
bool warning_triggered = false;
|
||||
bool backstab_triggered = false;
|
||||
float last_say = 0.0f;
|
||||
|
||||
|
||||
|
||||
void Draw() {
|
||||
if (!enabled) return;
|
||||
CachedEntity* closest_spy = nullptr;
|
||||
float closest_spy_distance = 0.0f;
|
||||
int spy_count = 0;
|
||||
if (last_say > g_GlobalVars->curtime) last_say = 0;
|
||||
for (int i = 0; i < HIGHEST_ENTITY && i < 64; i++) {
|
||||
CachedEntity* ent = ENTITY(i);
|
||||
if (CE_BAD(ent)) continue;
|
||||
@ -43,14 +48,20 @@ void Draw() {
|
||||
if (closest_spy && closest_spy_distance < (float)distance_warning) {
|
||||
if (closest_spy_distance < (float)distance_backstab) {
|
||||
if (!backstab_triggered) {
|
||||
if (sound_alerts) g_ISurface->PlaySound("vo/demoman_cloakedspy03.mp3");
|
||||
if (sound_alerts && (g_GlobalVars->curtime - last_say) > (float)sound_alert_interval) {
|
||||
g_ISurface->PlaySound("vo/demoman_cloakedspy03.mp3");
|
||||
last_say = g_GlobalVars->curtime;
|
||||
}
|
||||
backstab_triggered = true;
|
||||
}
|
||||
AddCenterString(format("BACKSTAB WARNING! ", (int)(closest_spy_distance / 64 * 1.22f), "m (", spy_count, ")"), colors::red);
|
||||
} else if (closest_spy_distance < (float)distance_warning) {
|
||||
backstab_triggered = false;
|
||||
if (!warning_triggered) {
|
||||
if (sound_alerts) g_ISurface->PlaySound("vo/demoman_cloakedspy01.mp3");
|
||||
if (sound_alerts && (g_GlobalVars->curtime - last_say) > (float)sound_alert_interval) {
|
||||
g_ISurface->PlaySound("vo/demoman_cloakedspy01.mp3");
|
||||
last_say = g_GlobalVars->curtime;
|
||||
}
|
||||
warning_triggered = true;
|
||||
}
|
||||
AddCenterString(format("Incoming spy! ", (int)(closest_spy_distance / 64 * 1.22f), "m (", spy_count, ")"), colors::yellow);
|
||||
|
Reference in New Issue
Block a user