Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use game-provided flash-assist logic #611

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions scripting/get5.sp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ bool g_SetTeamClutching[4];
int g_RoundKills[MAXPLAYERS + 1]; // kills per round each client has gotten
int g_RoundClutchingEnemyCount[MAXPLAYERS +
1]; // number of enemies left alive when last alive on your team
int g_LastFlashBangThrower = -1; // last client to have a flashbang detonate
int g_RoundFlashedBy[MAXPLAYERS + 1];
bool g_TeamFirstKillDone[MATCHTEAM_COUNT];
bool g_TeamFirstDeathDone[MATCHTEAM_COUNT];
int g_PlayerKilledBy[MAXPLAYERS + 1];
Expand Down
8 changes: 4 additions & 4 deletions scripting/get5/eventlogger.sp
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,18 @@ public void EventLogger_GoingLive() {
}

public void EventLogger_PlayerDeath(int killer, int victim, bool headshot, int assister,
int flash_assister, const char[] weapon) {
bool flash_assist, const char[] weapon) {
EventLogger_StartEvent();
AddMapData(params);
AddPlayer(params, "attacker", killer);
AddPlayer(params, "victim", victim);
params.SetInt("headshot", headshot);
params.SetString("weapon", weapon);

if (assister > 0)
if (assister > 0) {
AddPlayer(params, "assister", assister);
if (flash_assister > 0)
AddPlayer(params, "flash_assister", flash_assister);
params.SetBool("flash_assist", flash_assist);
}

EventLogger_EndEvent("player_death");
}
Expand Down
78 changes: 19 additions & 59 deletions scripting/get5/stats.sp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ public void Stats_PluginStart() {
HookEvent("bomb_planted", Stats_BombPlantedEvent);
HookEvent("bomb_defused", Stats_BombDefusedEvent);
HookEvent("bomb_exploded", Stats_BombExplodedEvent);
HookEvent("flashbang_detonate", Stats_FlashbangDetonateEvent, EventHookMode_Pre);
HookEvent("player_blind", Stats_PlayerBlindEvent);
HookEvent("round_mvp", Stats_RoundMVPEvent);
}

Expand Down Expand Up @@ -44,7 +42,6 @@ public void Stats_ResetRoundValues() {
public void Stats_ResetClientRoundValues(int client) {
g_RoundKills[client] = 0;
g_RoundClutchingEnemyCount[client] = 0;
g_RoundFlashedBy[client] = 0;
g_PlayerKilledBy[client] = -1;
g_PlayerKilledByTime[client] = 0.0;
g_PlayerRoundKillOrAssistOrTradedDeath[client] = false;
Expand Down Expand Up @@ -188,6 +185,7 @@ public Action Stats_PlayerDeathEvent(Event event, const char[] name, bool dontBr
int attacker = GetClientOfUserId(event.GetInt("attacker"));
int assister = GetClientOfUserId(event.GetInt("assister"));
bool headshot = event.GetBool("headshot");
bool assistedFlash = event.GetBool("assistedflash");

char weapon[32];
event.GetString("weapon", weapon, sizeof(weapon));
Expand Down Expand Up @@ -230,18 +228,26 @@ public Action Stats_PlayerDeathEvent(Event event, const char[] name, bool dontBr
if (headshot)
IncrementPlayerStat(attacker, STAT_HEADSHOT_KILLS);

if (IsValidClient(assister)) {
IncrementPlayerStat(assister, STAT_ASSISTS);
g_PlayerRoundKillOrAssistOrTradedDeath[assister] = true;
}
// Assists should only count towards opposite team
if (HelpfulAttack(assister, victim)) {

int flasher = g_RoundFlashedBy[victim];
if (IsValidClient(flasher) && flasher != attacker)
IncrementPlayerStat(flasher, STAT_FLASHBANG_ASSISTS);
else
flasher = 0;
// You cannot flash-assist and regular-assist for the same kill.
if (assistedFlash) {
IncrementPlayerStat(assister, STAT_FLASHBANG_ASSISTS);
} else {
IncrementPlayerStat(assister, STAT_ASSISTS);
g_PlayerRoundKillOrAssistOrTradedDeath[assister] = true;
}

} else {

// Don't count friendly-fire assist at all.
assister = 0;
assistedFlash = false;

EventLogger_PlayerDeath(attacker, victim, headshot, assister, flasher, weapon);
}

EventLogger_PlayerDeath(attacker, victim, headshot, assister, assistedFlash, weapon);

} else {
if (attacker == victim)
Expand Down Expand Up @@ -359,40 +365,6 @@ public Action Stats_BombExplodedEvent(Event event, const char[] name, bool dontB
return Plugin_Continue;
}

public Action Stats_FlashbangDetonateEvent(Event event, const char[] name, bool dontBroadcast) {
if (g_GameState != Get5State_Live) {
return Plugin_Continue;
}

int userid = event.GetInt("userid");
int client = GetClientOfUserId(userid);

if (IsValidClient(client)) {
g_LastFlashBangThrower = client;
}

return Plugin_Continue;
}

public Action Timer_ResetFlashStatus(Handle timer, int serial) {
int client = GetClientFromSerial(serial);
if (IsValidClient(client)) {
g_RoundFlashedBy[client] = -1;
}
}

public Action Stats_PlayerBlindEvent(Event event, const char[] name, bool dontBroadcast) {
if (g_GameState != Get5State_Live) {
return Plugin_Continue;
}

int userid = event.GetInt("userid");
int client = GetClientOfUserId(userid);
RequestFrame(GetFlashInfo, GetClientSerial(client));

return Plugin_Continue;
}

public Action Stats_RoundMVPEvent(Event event, const char[] name, bool dontBroadcast) {
if (g_GameState != Get5State_Live) {
return Plugin_Continue;
Expand All @@ -408,18 +380,6 @@ public Action Stats_RoundMVPEvent(Event event, const char[] name, bool dontBroad
return Plugin_Continue;
}

public void GetFlashInfo(int serial) {
int client = GetClientFromSerial(serial);
if (IsValidClient(client)) {
float flashDuration =
GetEntDataFloat(client, FindSendPropInfo("CCSPlayer", "m_flFlashDuration"));
if (flashDuration >= 2.5) {
g_RoundFlashedBy[client] = g_LastFlashBangThrower;
}
CreateTimer(flashDuration, Timer_ResetFlashStatus, serial);
}
}

static int GetPlayerStat(int client, const char[] field) {
GoToPlayer(client);
int value = g_StatsKv.GetNum(field);
Expand Down