")
iLen += format(sBuffer[iLen], MAX_BUFFER_LENGTH - iLen, "%2s %-22.22s %6s %6s %6s %6s %4s %4s %4s^n", "#", "Nick", lKills, lDeaths, lHits, lShots, "HS", lEff, lAcc)
for (new i = 0; i < iMax && MAX_BUFFER_LENGTH - iLen > 0; i++)
{
get_stats(i, izStats, izBody, t_sName, MAX_NAME_LENGTH)
replace_all(t_sName, MAX_NAME_LENGTH, "<", "[")
replace_all(t_sName, MAX_NAME_LENGTH, ">", "]")
iLen += format(sBuffer[iLen], MAX_BUFFER_LENGTH - iLen, "%2d %-22.22s %6d %6d %6d %6d %4d %3.0f%% %3.0f%%^n", i + 1, t_sName, izStats[STATS_KILLS],
izStats[STATS_DEATHS], izStats[STATS_HITS], izStats[STATS_SHOTS], izStats[STATS_HS], effec(izStats), accuracy(izStats))
}
}
// Get and format rank stats.
format_rankstats(id, sBuffer[MAX_BUFFER_LENGTH + 1], iMyId = 0)
{
new izStats[8] = {0, ...}
new izBody[8]
new iRankPos, iLen
new lKills[16], lDeaths[16], lHits[16], lShots[16], lDamage[16], lEff[16], lAcc[16]
format(lKills, 15, "%L", id, "KILLS")
format(lDeaths, 15, "%L", id, "DEATHS")
format(lHits, 15, "%L", id, "HITS")
format(lShots, 15, "%L", id, "SHOTS")
format(lDamage, 15, "%L", id, "DAMAGE")
format(lEff, 15, "%L", id, "EFF")
format(lAcc, 15, "%L", id, "ACC")
ucfirst(lEff)
ucfirst(lAcc)
iRankPos = get_user_stats(id, izStats, izBody)
iLen = format(sBuffer, MAX_BUFFER_LENGTH, "")
iLen += format(sBuffer[iLen], MAX_BUFFER_LENGTH - iLen, "%L %L^n^n", id, (!iMyId || iMyId == id) ? "YOUR" : "PLAYERS", id, "RANK_IS", iRankPos, get_statsnum())
iLen += format(sBuffer[iLen], MAX_BUFFER_LENGTH - iLen, "%6s: %d (%d with hs)^n%6s: %d^n%6s: %d^n%6s: %d^n%6s: %d^n%6s: %0.2f%%^n%6s: %0.2f%%^n^n",
lKills, izStats[STATS_KILLS], izStats[STATS_HS], lDeaths, izStats[STATS_DEATHS], lHits, izStats[STATS_HITS], lShots, izStats[STATS_SHOTS],
lDamage, izStats[STATS_DAMAGE], lEff, effec(izStats), lAcc, accuracy(izStats))
new L_BODY_PART[8][32]
for (new i = 1; i < 8; i++)
{
format(L_BODY_PART[i], 31, "%L", id, BODY_PART[i])
}
iLen += format(sBuffer[iLen], MAX_BUFFER_LENGTH - iLen, "%10s:^n%10s: %d^n%10s: %d^n%10s: %d^n%10s: %d^n%10s: %d^n%10s: %d^n%10s: %d", "HITS",
L_BODY_PART[1], izBody[1], L_BODY_PART[2], izBody[2], L_BODY_PART[3], izBody[3], L_BODY_PART[4], izBody[4], L_BODY_PART[5],
izBody[5], L_BODY_PART[6], izBody[6], L_BODY_PART[7], izBody[7])
}
// Get and format stats.
format_stats(id, sBuffer[MAX_BUFFER_LENGTH + 1])
{
new izStats[8] = {0, ...}
new izBody[8]
new iWeapon, iLen
new lKills[16], lDeaths[16], lHits[16], lShots[16], lDamage[16], lEff[16], lAcc[16], lWeapon[16]
format(lKills, 15, "%L", id, "KILLS")
format(lDeaths, 15, "%L", id, "DEATHS")
format(lHits, 15, "%L", id, "HITS")
format(lShots, 15, "%L", id, "SHOTS")
format(lDamage, 15, "%L", id, "DAMAGE")
format(lEff, 15, "%L", id, "EFF")
format(lAcc, 15, "%L", id, "ACC")
format(lWeapon, 15, "%L", id, "WEAPON")
ucfirst(lEff)
ucfirst(lAcc)
get_user_wstats(id, 0, izStats, izBody)
iLen = format(sBuffer, MAX_BUFFER_LENGTH, "")
iLen += format(sBuffer[iLen], MAX_BUFFER_LENGTH - iLen, "%6s: %d (%d with hs)^n%6s: %d^n%6s: %d^n%6s: %d^n%6s: %d^n%6s: %0.2f%%^n%6s: %0.2f%%^n^n",
lKills, izStats[STATS_KILLS], izStats[STATS_HS], lDeaths, izStats[STATS_DEATHS], lHits, izStats[STATS_HITS], lShots, izStats[STATS_SHOTS],
lDamage, izStats[STATS_DAMAGE], lEff, effec(izStats), lAcc, accuracy(izStats))
iLen += format(sBuffer[iLen], MAX_BUFFER_LENGTH - iLen, "%-12.12s %6s %6s %6s %6s %6s %4s^n", lWeapon, lKills, lDeaths, lHits, lShots, lDamage, lAcc)
for (iWeapon = 1; iWeapon < xmod_get_maxweapons() && MAX_BUFFER_LENGTH - iLen > 0 ; iWeapon++)
{
if (get_user_wstats(id, iWeapon, izStats, izBody))
{
xmod_get_wpnname(iWeapon, t_sWpn, MAX_WEAPON_LENGTH)
iLen += format(sBuffer[iLen], MAX_BUFFER_LENGTH - iLen, "%-12.12s %6d %6d %6d %6d %6d %3.0f%%^n", t_sWpn, izStats[STATS_KILLS], izStats[STATS_DEATHS],
izStats[STATS_HITS], izStats[STATS_SHOTS], izStats[STATS_DAMAGE], accuracy(izStats))
}
}
}
// Show round end stats. If gametime is zero then use default duration time.
show_roundend_hudstats(id, Float:fGameTime)
{
// Bail out if there no HUD stats should be shown
// for this player or end round stats not created.
if (!g_izStatsSwitch[id]) return
if (!g_sAwardAndScore[0]) return
// If round end timer is zero clear round end stats.
if (g_fShowStatsTime == 0.0)
{
ClearSyncHud(id, g_HudSync_EndRound)
#if defined STATSX_DEBUG
log_amx("Clear round end HUD stats for #%d", id)
#endif
}
// Set HUD-duration to default or remaining time.
new Float:fDuration
if (fGameTime == 0.0)
fDuration = g_fHUDDuration
else
{
fDuration = g_fShowStatsTime + g_fHUDDuration - fGameTime
if (fDuration > g_fFreezeTime + g_fFreezeLimitTime)
fDuration = g_fFreezeTime + g_fFreezeLimitTime
}
// Show stats only if more time left than coded minimum.
if (fDuration >= HUD_MIN_DURATION)
{
set_hudtype_endround(fDuration)
ShowSyncHudMsg(id, g_HudSync_EndRound, "%s", g_sAwardAndScore)
#if defined STATSX_DEBUG
log_amx("Show %1.2fs round end HUD stats for #%d", fDuration, id)
#endif
}
}
// Show round end stats.
show_user_hudstats(id, Float:fGameTime)
{
// Bail out if there no HUD stats should be shown
// for this player or user stats timer is zero.
if (!g_izStatsSwitch[id]) return
if (g_fzShowUserStatsTime[id] == 0.0) return
// Set HUD-duration to default or remaining time.
new Float:fDuration
if (fGameTime == 0.0)
fDuration = g_fHUDDuration
else
{
fDuration = g_fzShowUserStatsTime[id] + g_fHUDDuration - fGameTime
if (fDuration > g_fFreezeTime + g_fFreezeLimitTime)
fDuration = g_fFreezeTime + g_fFreezeLimitTime
}
// Show stats only if more time left than coded minimum.
if (fDuration >= HUD_MIN_DURATION)
{
if (ShowKiller)
{
new iKiller
iKiller = g_izKilled[id][KILLED_KILLER_ID]
get_kill_info(id, iKiller, g_sBuffer)
add_attacker_hits(id, iKiller, g_sBuffer)
set_hudtype_killer(fDuration)
show_hudmessage(id, "%s", g_sBuffer)
#if defined STATSX_DEBUG
log_amx("Show %1.2fs %suser HUD k-stats for #%d", fDuration, g_sBuffer[0] ? "" : "no ", id)
#endif
}
if (ShowVictims)
{
get_victims(id, g_sBuffer)
set_hudtype_victim(fDuration)
show_hudmessage(id, "%s", g_sBuffer)
#if defined STATSX_DEBUG
log_amx("Show %1.2fs %suser HUD v-stats for #%d", fDuration, g_sBuffer[0] ? "" : "no ", id)
#endif
}
if (ShowAttackers)
{
get_attackers(id, g_sBuffer)
set_hudtype_attacker(fDuration)
show_hudmessage(id, "%s", g_sBuffer)
#if defined STATSX_DEBUG
log_amx("Show %1.2fs %suser HUD a-stats for #%d", fDuration, g_sBuffer[0] ? "" : "no ", id)
#endif
}
}
}
//------------------------------------------------------------
// Plugin commands
//------------------------------------------------------------
// Set or get plugin config flags.
public cmdPluginMode(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
if (read_argc() > 1)
read_argv(1, g_sBuffer, MAX_BUFFER_LENGTH)
else
g_sBuffer[0] = 0
set_plugin_mode(id, g_sBuffer)
return PLUGIN_HANDLED
}
// Display MOTD stats.
public cmdStatsMe(id)
{
if (!SayStatsMe)
{
client_print(id, print_chat, "%L", id, "DISABLED_MSG")
return PLUGIN_HANDLED
}
format_stats(id, g_sBuffer)
get_user_name(id, t_sName, MAX_NAME_LENGTH)
show_motd(id, g_sBuffer, t_sName)
return PLUGIN_CONTINUE
}
// Display MOTD rank.
public cmdRankStats(id)
{
if (!SayRankStats)
{
client_print(id, print_chat, "%L", id, "DISABLED_MSG")
return PLUGIN_HANDLED
}
format_rankstats(id, g_sBuffer)
get_user_name(id, t_sName, MAX_NAME_LENGTH)
show_motd(id, g_sBuffer, t_sName)
return PLUGIN_CONTINUE
}
// Display MOTD top15 ranked.
public cmdTop15(id)
{
if (!SayTop15)
{
client_print(id, print_chat, "%L", id, "DISABLED_MSG")
return PLUGIN_HANDLED
}
format_top15(g_sBuffer)
show_motd(id, g_sBuffer, "Top 15")
return PLUGIN_CONTINUE
}
// Display killer information.
public cmdHp(id)
{
if (!SayHP)
{
client_print(id, print_chat, "%L", id, "DISABLED_MSG")
return PLUGIN_HANDLED
}
new iKiller = g_izKilled[id][KILLED_KILLER_ID]
format_kill_ainfo(id, iKiller, g_sBuffer)
colorChat(id, CHATCOLOR_NORMAL, "* %s", g_sBuffer)
return PLUGIN_CONTINUE
}
// Display user stats.
public cmdMe(id)
{
if (!SayMe)
{
client_print(id, print_chat, "%L", id, "DISABLED_MSG")
return PLUGIN_HANDLED
}
format_kill_vinfo(id, 0, g_sBuffer)
colorChat(id, CHATCOLOR_NORMAL, "* %s", g_sBuffer)
return PLUGIN_CONTINUE
}
// Display user rank
public cmdRank(id)
{
if (!SayRank)
{
client_print(id, print_chat, "%L", id, "DISABLED_MSG")
return PLUGIN_HANDLED
}
new izStats[8], izBody[8]
new iRankPos, iRankMax
new Float:fEff, Float:fAcc
iRankPos = get_user_stats(id, izStats, izBody)
iRankMax = get_statsnum()
fEff = effec(izStats)
fAcc = accuracy(izStats)
colorChat(id, CHATCOLOR_NORMAL, "* %L", id, "YOUR_RANK_IS", iRankPos, iRankMax, izStats[STATS_KILLS], izStats[STATS_HITS], fEff, fAcc)
return PLUGIN_CONTINUE
}
// Report user weapon status to team.
public cmdReport(id)
{
if (!SayReport)
{
client_print(id, print_chat, "%L", id, "DISABLED_MSG")
return PLUGIN_HANDLED
}
new iWeapon, iClip, iAmmo, iHealth, iArmor
iWeapon = get_user_weapon(id, iClip, iAmmo)
if (iWeapon != 0)
xmod_get_wpnname(iWeapon, t_sWpn, MAX_WEAPON_LENGTH)
iHealth = get_user_health(id)
iArmor = get_user_armor(id)
new lWeapon[16]
format(lWeapon, 15, "%L", id, "WEAPON")
strtolower(lWeapon)
if (iClip >= 0)
{
format(g_sBuffer, MAX_BUFFER_LENGTH, "%s: %s, %L: %d/%d, %L: %d, %L: %d", lWeapon, t_sWpn, LANG_SERVER, "AMMO", iClip, iAmmo, LANG_SERVER, "HEALTH", iHealth, LANG_SERVER, "ARMOR", iArmor)
}
else
format(g_sBuffer, MAX_BUFFER_LENGTH, "%s: %s, %L: %d, %L: %d", lWeapon, t_sWpn[7], LANG_SERVER, "HEALTH", iHealth, LANG_SERVER, "ARMOR", iArmor)
engclient_cmd(id, "say_team", g_sBuffer)
return PLUGIN_CONTINUE
}
// Display team map score
public cmdScore(id)
{
if (!SayScore)
{
client_print(id, print_chat, "%L", id, "DISABLED_MSG")
return PLUGIN_HANDLED
}
client_print(id, print_chat, "%L: %s", id, "GAME_SCORE", g_sScore)
return PLUGIN_CONTINUE
}
// Client switch to enable or disable stats announcements.
public cmdSwitch(id)
{
g_izStatsSwitch[id] = (g_izStatsSwitch[id]) ? 0 : -1
num_to_str(g_izStatsSwitch[id], t_sText, MAX_TEXT_LENGTH)
client_cmd(id, "setinfo _amxstatsx %s", t_sText)
new lEnDis[32]
format(lEnDis, 31, "%L", id, g_izStatsSwitch[id] ? "ENABLED" : "DISABLED")
client_print(id, print_chat, "* %L", id, "STATS_ANNOUNCE", lEnDis)
return PLUGIN_CONTINUE
}
// Player stats menu.
public cmdStats(id)
{
if (!SayStatsAll)
{
client_print(id, print_chat, "%L", id, "DISABLED_MSG")
return PLUGIN_HANDLED
}
showStatsMenu(id, g_izUserMenuPosition[id] = 0)
return PLUGIN_CONTINUE
}
//--------------------------------
// Menu
//--------------------------------
public actionStatsMenu(id, key)
{
switch (key)
{
// Key '1' to '7', execute action on this option
case 0..6:
{
new iOption, iIndex
iOption = (g_izUserMenuPosition[id] * PPL_MENU_OPTIONS) + key
if (iOption >= 0 && iOption < 32)
{
iIndex = g_izUserMenuPlayers[id][iOption]
if (is_user_connected(iIndex))
{
switch (g_izUserMenuAction[id])
{
case 0: format_stats(iIndex, g_sBuffer)
case 1: format_rankstats(iIndex, g_sBuffer, id)
default: g_sBuffer[0] = 0
}
if (g_sBuffer[0])
{
get_user_name(iIndex, t_sName, MAX_NAME_LENGTH)
show_motd(id, g_sBuffer, t_sName)
}
}
}
showStatsMenu(id, g_izUserMenuPosition[id])
}
// Key '8', change action
case 7:
{
g_izUserMenuAction[id]++
if (g_izUserMenuAction[id] >= MAX_PPL_MENU_ACTIONS)
g_izUserMenuAction[id] = 0
showStatsMenu(id, g_izUserMenuPosition[id])
}
// Key '9', select next page of options
case 8: showStatsMenu(id, ++g_izUserMenuPosition[id])
// Key '10', cancel or go back to previous menu
case 9:
{
if (g_izUserMenuPosition[id] > 0)
showStatsMenu(id, --g_izUserMenuPosition[id])
}
}
return PLUGIN_HANDLED
}
new g_izUserMenuActionText[MAX_PPL_MENU_ACTIONS][] = {"Show stats", "Show rank stats"}
showStatsMenu(id, iMenuPos)
{
new iLen, iKeyMask, iPlayers
new iUserIndex, iMenuPosMax, iMenuOption, iMenuOptionMax
get_players(g_izUserMenuPlayers[id], iPlayers)
iMenuPosMax = ((iPlayers - 1) / PPL_MENU_OPTIONS) + 1
// If menu pos does not excist use last menu (if players has left)
if (iMenuPos >= iMenuPosMax)
iMenuPos = iMenuPosMax - 1
iUserIndex = iMenuPos * PPL_MENU_OPTIONS
iLen = format(g_sBuffer, MAX_BUFFER_LENGTH, "\y%L\R%d/%d^n\w^n", id, "SERVER_STATS", iMenuPos + 1, iMenuPosMax)
iMenuOptionMax = iPlayers - iUserIndex
if (iMenuOptionMax > PPL_MENU_OPTIONS)
iMenuOptionMax = PPL_MENU_OPTIONS
for (iMenuOption = 0; iMenuOption < iMenuOptionMax; iMenuOption++)
{
get_user_name(g_izUserMenuPlayers[id][iUserIndex++], t_sName, MAX_NAME_LENGTH)
iKeyMask |= (1< iUserIndex)
{
iLen += format(g_sBuffer[iLen], MAX_BUFFER_LENGTH - iLen, "^n9. %L...", id, "MORE")
iKeyMask |= MENU_KEY_9
}
if (iMenuPos > 0)
iLen += format(g_sBuffer[iLen], MAX_BUFFER_LENGTH - iLen, "^n0. %L", id, "BACK")
else
iLen += format(g_sBuffer[iLen], MAX_BUFFER_LENGTH - iLen, "^n0. %L", id, "EXIT")
show_menu(id, iKeyMask, g_sBuffer, -1, "Server Stats")
return PLUGIN_HANDLED
}
//------------------------------------------------------------
// Plugin events
//------------------------------------------------------------
// Reset game stats on game start and restart.
public eventStartGame()
{
read_data(2, t_sText, MAX_TEXT_LENGTH)
if (t_sText[6] == 'w')
{
read_data(3, t_sText, MAX_TEXT_LENGTH)
g_fStartGame = get_gametime() + float(str_to_num(t_sText))
}
else
g_fStartGame = get_gametime()
return PLUGIN_CONTINUE
}
// Round start
public eventStartRound()
{
new iTeam, id, i
new Float:roundtime = get_cvar_float("mp_roundtime");
if (read_data(1) >= floatround(roundtime * 60.0,floatround_floor) || (roundtime == 2.3 && read_data(1) == 137)) // these round too weird for it to work through pawn, have to add an exception for it
{
#if defined STATSX_DEBUG
log_amx("Reset round stats")
#endif
// Reset game stats on game start and restart.
if (g_fStartGame > 0.0 && g_fStartGame <= get_gametime())
{
#if defined STATSX_DEBUG
log_amx("Reset game stats")
#endif
g_fStartGame = 0.0
// Clear team and game stats.
for (iTeam = 0; iTeam < MAX_TEAMS; iTeam++)
{
g_izTeamEventScore[iTeam] = 0
for (i = 0; i < 8; i++)
g_izTeamGameStats[iTeam][i] = 0
}
// Clear game stats, incl '0' that is sum of all users.
for (id = 0; id < MAX_PLAYERS; id++)
{
for (i = 0; i < 8; i++)
g_izUserGameStats[id][i] = 0
}
}
// Update team score with "TeamScore" event values and
// clear team round stats.
for (iTeam = 0; iTeam < MAX_TEAMS; iTeam++)
{
g_izTeamScore[iTeam] = g_izTeamEventScore[iTeam]
for (i = 0; i < 8; i++)
g_izTeamRndStats[iTeam][i] = 0
}
// Clear user round stats, incl '0' that is sum of all users.
for (id = 0; id < MAX_PLAYERS; id++)
{
g_izUserRndName[id][0] = 0
for (i = 0; i < 8; i++)
g_izUserRndStats[id][i] = 0
g_fzShowUserStatsTime[id] = 0.0
}
// Allow end round stats and reset end round triggered indicator.
g_iRoundEndTriggered = 0
g_iRoundEndProcessed = 0
g_fShowStatsTime = 0.0
// Update local configuration vars with value in cvars.
get_config_cvars()
}
return PLUGIN_CONTINUE
}
// Reset killer info on round restart.
public eventResetHud(id)
{
new args[1]
args[0] = id
if (g_iPluginMode & MODE_HUD_DELAY)
set_task(0.01, "delay_resethud", 200 + id, args, 1)
else
delay_resethud(args)
return PLUGIN_CONTINUE
}
public delay_resethud(args[])
{
new id = args[0]
new Float:fGameTime
// Show user and score round stats after HUD-reset
#if defined STATSX_DEBUG
log_amx("Reset HUD for #%d", id)
#endif
fGameTime = get_gametime()
show_user_hudstats(id, fGameTime)
show_roundend_hudstats(id, fGameTime)
// Reset round stats
g_izKilled[id][KILLED_KILLER_ID] = 0
g_izKilled[id][KILLED_KILLER_STATSFIX] = 0
g_izShowStatsFlags[id] = -1 // Initialize flags
g_fzShowUserStatsTime[id] = 0.0
g_izUserAttackerDistance[id] = 0
for (new i = 0; i < MAX_PLAYERS; i++)
g_izUserVictimDistance[id][i] = 0
return PLUGIN_CONTINUE
}
// Save killer info on death.
public client_death(killer, victim, wpnindex, hitplace, TK)
{
// Bail out if no killer.
if (!killer)
return PLUGIN_CONTINUE
if (killer != victim)
{
new iaVOrigin[3], iaKOrigin[3]
new iDistance
get_user_origin(victim, iaVOrigin)
get_user_origin(killer, iaKOrigin)
g_izKilled[victim][KILLED_KILLER_ID] = killer
g_izKilled[victim][KILLED_KILLER_HEALTH] = get_user_health(killer)
g_izKilled[victim][KILLED_KILLER_ARMOUR] = get_user_armor(killer)
g_izKilled[victim][KILLED_KILLER_STATSFIX] = 0
iDistance = get_distance(iaVOrigin, iaKOrigin)
g_izUserAttackerDistance[victim] = iDistance
g_izUserVictimDistance[killer][victim] = iDistance
}
g_izKilled[victim][KILLED_TEAM] = get_user_team(victim)
g_izKilled[victim][KILLED_KILLER_STATSFIX] = 1
// Display kill stats for the player if round
// end stats was not processed.
if (!g_iRoundEndProcessed)
kill_stats(victim)
return PLUGIN_CONTINUE
}
// Display hudmessage stats on death.
// This will also update all round and game stats.
// Must be called at least once per round.
kill_stats(id)
{
// Bail out if user stats timer is non-zero,
// ie function already called.
if (g_fzShowUserStatsTime[id] > 0.0)
{
return
}
new team = get_user_team(id)
if (team < 1 || team > 2)
{
return
}
// Flag kill stats displayed for this player.
g_fzShowUserStatsTime[id] = get_gametime()
// Add user death stats to user round stats
new izStats[8], izBody[8]
new iTeam, i
new iKiller
iKiller = g_izKilled[id][KILLED_KILLER_ID]
// Get user's team (if dead use the saved team)
if (iKiller)
iTeam = g_izKilled[id][KILLED_TEAM] - 1
else
iTeam = get_user_team(id) - 1
get_user_name(id, g_izUserRndName[id], MAX_NAME_LENGTH)
if (get_user_rstats(id, izStats, izBody))
{
// Update user's team round stats
if (iTeam >= 0 && iTeam < MAX_TEAMS)
{
for (i = 0; i < 8; i++)
{
g_izTeamRndStats[iTeam][i] += izStats[i]
g_izTeamGameStats[iTeam][i] += izStats[i]
g_izUserRndStats[0][i] += izStats[i]
g_izUserGameStats[0][i] += izStats[i]
}
}
// Update user's round stats
if (g_izUserUserID[id] == get_user_userid(id))
{
for (i = 0; i < 8; i++)
{
g_izUserRndStats[id][i] += izStats[i]
g_izUserGameStats[id][i] += izStats[i]
}
} else {
g_izUserUserID[id] = get_user_userid(id)
for (i = 0; i < 8; i++)
{
g_izUserRndStats[id][i] = izStats[i]
g_izUserGameStats[id][i] = izStats[i]
}
}
} // endif (get_user_rstats())
// Report stats in the chat section, if player is killed.
if (KillerChat && iKiller && iKiller != id)
{
if (format_kill_ainfo(id, iKiller, g_sBuffer))
{
colorChat(id, CHATCOLOR_NORMAL, "* %s", g_sBuffer)
format_kill_vinfo(id, iKiller, g_sBuffer)
}
colorChat(id, CHATCOLOR_NORMAL, "* %s", g_sBuffer);
}
// Display player stats info.
#if defined STATSX_DEBUG
log_amx("Kill stats for #%d", id)
#endif
show_user_hudstats(id, 0.0)
}
public eventEndRound()
{
// Update local configuration vars with value in cvars.
get_config_cvars()
// If first end round event in the round, calculate team score.
if (!g_iRoundEndTriggered)
{
read_data(2, t_sText, MAX_TEXT_LENGTH)
if (t_sText[7] == 't') // Terrorist wins
g_izTeamScore[0]++
else if (t_sText[7] == 'c') // CT wins
g_izTeamScore[1]++
}
set_task(0.3, "ERTask", 997)
return PLUGIN_CONTINUE
}
public ERTask()
{
// Flag round end triggered.
g_iRoundEndTriggered = 1
// Display round end stats to all players.
endround_stats()
}
endround_stats()
{
// Bail out if end round stats has already been processed
// or round end not triggered.
if (g_iRoundEndProcessed || !g_iRoundEndTriggered)
return
new iaPlayers[32], iPlayer, iPlayers, id
get_players(iaPlayers, iPlayers)
// Display attacker & victim list for all living players.
// This will also update all round and game stats for all players
// not killed.
#if defined STATSX_DEBUG
log_amx("End round stats")
#endif
for (iPlayer = 0; iPlayer < iPlayers; iPlayer++)
{
id = iaPlayers[iPlayer]
if (g_fzShowUserStatsTime[id] == 0.0)
{
kill_stats(id)
}
}
g_sAwardAndScore[0] = 0
// Create round awards.
if (ShowMostDisruptive)
add_most_disruptive(g_sAwardAndScore)
if (ShowBestScore)
add_best_score(g_sAwardAndScore)
// Create round score.
// Compensate HUD message if awards are disabled.
if (ShowTeamScore || ShowTotalStats)
{
if (ShowMostDisruptive && ShowBestScore)
add(g_sAwardAndScore, MAX_BUFFER_LENGTH, "^n^n")
else if (ShowMostDisruptive || ShowBestScore)
add(g_sAwardAndScore, MAX_BUFFER_LENGTH, "^n^n^n^n")
else
add(g_sAwardAndScore, MAX_BUFFER_LENGTH, "^n^n^n^n^n^n")
if (ShowTeamScore)
add_team_score(g_sAwardAndScore)
if (ShowTotalStats)
add_total_stats(g_sAwardAndScore)
}
save_team_chatscore()
// Get and save round end stats time.
g_fShowStatsTime = get_gametime()
// Display round end stats to all players.
for (iPlayer = 0; iPlayer < iPlayers; iPlayer++)
{
id = iaPlayers[iPlayer]
show_roundend_hudstats(id, 0.0)
}
// Flag round end processed.
g_iRoundEndProcessed = 1
}
public eventTeamScore()
{
new sTeamID[1 + 1], iTeamScore
read_data(1, sTeamID, 1)
iTeamScore = read_data(2)
g_izTeamEventScore[(sTeamID[0] == 'C') ? 1 : 0] = iTeamScore
return PLUGIN_CONTINUE
}
public eventIntermission()
{
if (EndPlayer || EndTop15)
set_task(1.0, "end_game_stats", 900)
}
public end_game_stats()
{
new iaPlayers[32], iPlayer, iPlayers, id
if (EndPlayer)
{
get_players(iaPlayers, iPlayers)
for (iPlayer = 0; iPlayer < iPlayers; iPlayer++)
{
id = iaPlayers[iPlayer]
if (!g_izStatsSwitch[id])
continue // Do not show any stats
cmdStatsMe(iaPlayers[iPlayer])
}
}
else if (EndTop15)
{
get_players(iaPlayers, iPlayers)
format_top15(g_sBuffer)
for (iPlayer = 0; iPlayer < iPlayers; iPlayer++)
{
id = iaPlayers[iPlayer]
if (!g_izStatsSwitch[id])
continue // Do not show any stats
show_motd(iaPlayers[iPlayer], g_sBuffer, "Top 15")
}
}
return PLUGIN_CONTINUE
}
public eventSpecMode(id)
{
new sData[12]
read_data(2, sData, 11)
g_izSpecMode[id] = (sData[10] == '2')
return PLUGIN_CONTINUE
}
public eventShowRank(id)
{
if (SpecRankInfo && g_izSpecMode[id])
{
new iPlayer = read_data(2)
if (is_user_connected(iPlayer))
{
new izStats[8], izBody[8]
new iRankPos, iRankMax
get_user_name(iPlayer, t_sName, MAX_NAME_LENGTH)
iRankPos = get_user_stats(iPlayer, izStats, izBody)
iRankMax = get_statsnum()
set_hudtype_specmode()
ShowSyncHudMsg(id, g_HudSync_SpecInfo, "%L", id, "X_RANK_IS", t_sName, iRankPos, iRankMax)
}
}
return PLUGIN_CONTINUE
}
public client_connect(id)
{
if (ShowStats)
{
get_user_info(id, "_amxstatsx", t_sText, MAX_TEXT_LENGTH)
g_izStatsSwitch[id] = (t_sText[0]) ? str_to_num(t_sText) : -1
}
else
g_izStatsSwitch[id] = 0
g_izKilled[id][KILLED_KILLER_ID] = 0
g_izKilled[id][KILLED_KILLER_STATSFIX] = 0
g_izShowStatsFlags[id] = 0 // Clear all flags
g_fzShowUserStatsTime[id] = 0.0
return PLUGIN_CONTINUE
}
colorChat(id, ChatColor:color, const msg[], {Float,Sql,Result,_}:...)
{
new team, index, MSG_Type
new bool:teamChanged = false
static message[192]
switch(color)
{
case CHATCOLOR_NORMAL: // Normal
{
message[0] = 0x01;
}
case CHATCOLOR_GREEN: // Green
{
message[0] = 0x04;
}
default: // Grey, Red, Blue
{
message[0] = 0x03;
}
}
vformat(message[1], 190, msg, 4);
replace_all(message, 190, "$g", "^x04")
replace_all(message, 190, "$n", "^x01")
replace_all(message, 190, "$t", "^x03")
if(id == 0)
{
index = findAnyPlayer();
MSG_Type = MSG_ALL;
}
else
{
index = id;
MSG_Type = MSG_ONE;
}
if(index != 0)
{
team = get_user_team(index);
if(color == CHATCOLOR_RED && team != 1)
{
messageTeamInfo(index, MSG_Type, g_TeamName[1])
teamChanged = true
}
else
if(color == CHATCOLOR_BLUE && team != 2)
{
messageTeamInfo(index, MSG_Type, g_TeamName[2])
teamChanged = true
}
else
if(color == CHATCOLOR_GREY && team != 0)
{
messageTeamInfo(index, MSG_Type, g_TeamName[0])
teamChanged = true
}
messageSayText(index, MSG_Type, message);
if(teamChanged)
{
messageTeamInfo(index, MSG_Type, g_TeamName[team])
}
}
}
messageSayText(id, type, message[])
{
message_begin(type, g_msgSayText, _, id)
write_byte(id)
write_string(message)
message_end()
}
messageTeamInfo(id, type, team[])
{
message_begin(type, g_msgTeamInfo, _, id)
write_byte(id)
write_string(team)
message_end()
}
findAnyPlayer()
{
static players[32], inum, pid
get_players(players, inum, "ch")
for (new a = 0; a < inum; a++)
{
pid = players[a]
if(is_user_connected(pid))
return pid
}
return 0
}