16/07/2020, 11:03 PM (Última modificación: 16/07/2020, 11:09 PM por Boddah.. Edited 2 times in total.)
Hola a todos, les quiero pedir si me pueden agregar trofeos a los 3 primeros jugadores del top15 al lado de sus nombres. como se muestra en esta imagen:
/* AMX Mod X
* StatsX Plugin
*
* by the AMX Mod X Development Team
* originally developed by OLO
*
* This file is part of AMX Mod X.
*
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* In addition, as a special exception, the author gives permission to
* link the code of this program with the Half-Life Game Engine ("HL
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
* L.L.C ("Valve"). You must obey the GNU General Public License in all
* respects for all of the code used other than the HL Engine and MODs
* from Valve. If you modify this file, you may extend this exception
* to your version of the file, but you are not obligated to do so. If
* you do not wish to do so, delete this exception statement from your
* version.
*/
// HUD statistics stop relative freeze end in seconds.
// To stop before freeze end use a negative value.
#define HUD_FREEZE_LIMIT_CVAR "amx_statsx_freeze"
#define HUD_FREEZE_LIMIT "-2.0"
// HUD statistics minimum duration, in seconds, to trigger the display logic.
#define HUD_MIN_DURATION 0.2
// Config plugin constants.
#define MODE_HUD_DELAY 0 // Make a 0.01 sec delay on HUD reset process.
// You can also manualy enable or disable these options by setting them to 1
// For example:
// public ShowAttackers = 1
// However amx_statscfg command is recommended
public KillerChat = 0 // displays killer hp&ap to victim console
// and screen
public ShowAttackers = 0 // shows attackers
public ShowVictims = 0 // shows victims
public ShowKiller = 0 // shows killer
public ShowTeamScore = 0 // shows team score at round end
public ShowTotalStats = 0 // shows round total stats
public ShowBestScore = 0 // shows rounds best scored player
public ShowMostDisruptive = 0 // shows rounds most disruptive player
public EndPlayer = 0 // displays player stats at the end of map
public EndTop15 = 0 // displays top15 at the end of map
public SayHP = 0 // displays information about user killer
public SayStatsMe = 0 // displays user's stats and rank
public SayRankStats = 0 // displays user's rank stats
public SayMe = 0 // displays user's stats
public SayRank = 0 // displays user's rank
public SayReport = 0 // report user's weapon status to team
public SayScore = 0 // displays team's map score
public SayTop15 = 0 // displays first 15 players
public SayStatsAll = 0 // displays all players stats and rank
public ShowStats = 1 // set client HUD-stats switched off by default
public ShowDistHS = 0 // show distance and HS in attackers and
// victims HUD lists
public ShowFullStats = 0 // show full HUD stats (more than 78 chars)
public SpecRankInfo = 0 // displays rank info when spectating
// Global player flags.
new BODY_PART[8][] =
{
"WHOLEBODY",
"HEAD",
"CHEST",
"STOMACH",
"LEFTARM",
"RIGHTARM",
"LEFTLEG",
"RIGHTLEG"
}
// Killer information, save killer info at the time when player is killed.
#define KILLED_KILLER_ID 0 // Killer userindex/user-ID
#define KILLED_KILLER_HEALTH 1 // Killer's health
#define KILLED_KILLER_ARMOUR 2 // Killer's armour
#define KILLED_TEAM 3 // Killer's team
#define KILLED_KILLER_STATSFIX 4 // Fix to register the last hit/kill
new g_izKilled[MAX_PLAYERS][5]
// Menu variables and configuration
#define MAX_PPL_MENU_ACTIONS 2 // Number of player menu actions
#define PPL_MENU_OPTIONS 7 // Number of player options per displayed menu
new g_iPluginMode = 0
new g_izUserMenuPosition[MAX_PLAYERS] = {0, ...}
new g_izUserMenuAction[MAX_PLAYERS] = {0, ...}
new g_izUserMenuPlayers[MAX_PLAYERS][32]
new g_izSpecMode[MAX_PLAYERS] = {0, ...}
new g_izShowStatsFlags[MAX_PLAYERS] = {0, ...}
new g_izStatsSwitch[MAX_PLAYERS] = {0, ...}
new Float:g_fzShowUserStatsTime[MAX_PLAYERS] = {0.0, ...}
new Float:g_fShowStatsTime = 0.0
new Float:g_fFreezeTime = 0.0
new Float:g_fFreezeLimitTime = 0.0
new Float:g_fHUDDuration = 0.0
new g_iRoundEndTriggered = 0
new g_iRoundEndProcessed = 0
new Float:g_fStartGame = 0.0
new g_izTeamScore[MAX_TEAMS] = {0, ...}
new g_izTeamEventScore[MAX_TEAMS] = {0, ...}
new g_izTeamRndStats[MAX_TEAMS][8]
new g_izTeamGameStats[MAX_TEAMS][8]
new g_izUserUserID[MAX_PLAYERS] = {0, ...}
new g_izUserAttackerDistance[MAX_PLAYERS] = {0, ...}
new g_izUserVictimDistance[MAX_PLAYERS][MAX_PLAYERS]
new g_izUserRndName[MAX_PLAYERS][MAX_NAME_LENGTH + 1]
new g_izUserRndStats[MAX_PLAYERS][8]
new g_izUserGameStats[MAX_PLAYERS][8]
// Common buffer to improve performance, as Small always zero-initializes all vars
new g_sBuffer[MAX_BUFFER_LENGTH + 1] = ""
new g_sScore[MAX_TEXT_LENGTH + 1] = ""
new g_sAwardAndScore[MAX_BUFFER_LENGTH + 1] = ""
new t_sText[MAX_TEXT_LENGTH + 1] = ""
new t_sName[MAX_NAME_LENGTH + 1] = ""
new t_sWpn[MAX_WEAPON_LENGTH + 1] = ""
new g_HudSync_EndRound
new g_HudSync_SpecInfo
//--------------------------------
// Initialize
//--------------------------------
public plugin_init()
{
// Register plugin.
register_plugin("StatsX", AMXX_VERSION_STR, "AMXX Dev Team")
register_dictionary("statsx.txt")
// Get and format attackers header and list.
get_attackers(id, sBuffer[MAX_BUFFER_LENGTH + 1])
{
new izStats[8], izBody[8]
new iAttacker
new iFound, iLen
new iMaxPlayer = get_maxplayers()
iFound = 0
sBuffer[0] = 0
// Get and format header. Add killing attacker statistics if user is dead.
// Make sure shots is greater than zero or division by zero will occur.
// To print a '%', 4 of them must done in a row.
izStats[STATS_SHOTS] = 0
iAttacker = g_izKilled[id][KILLED_KILLER_ID]
if (iAttacker)
get_user_astats(id, iAttacker, izStats, izBody)
// Get and format victims header and list
get_victims(id, sBuffer[MAX_BUFFER_LENGTH + 1])
{
new izStats[8], izBody[8]
new iVictim
new iFound, iLen
new iMaxPlayer = get_maxplayers()
iFound = 0
sBuffer[0] = 0
// Get and format header.
// Make sure shots is greater than zero or division by zero will occur.
// To print a '%', 4 of them must done in a row.
izStats[STATS_SHOTS] = 0
get_user_vstats(id, 0, izStats, izBody)
// Get and format team score.
add_team_score(sBuffer[MAX_BUFFER_LENGTH + 1])
{
new Float:fzMapEff[MAX_TEAMS], Float:fzMapAcc[MAX_TEAMS], Float:fzRndAcc[MAX_TEAMS]
// Calculate team stats
for (new iTeam = 0; iTeam < MAX_TEAMS; iTeam++)
{
fzMapEff[iTeam] = effec(g_izTeamGameStats[iTeam])
fzMapAcc[iTeam] = accuracy(g_izTeamGameStats[iTeam])
fzRndAcc[iTeam] = accuracy(g_izTeamRndStats[iTeam])
}
// Get and format killed stats: hits, damage on killer.
format_kill_vinfo(id, iKiller, sBuffer[MAX_BUFFER_LENGTH + 1])
{
new iFound = 0
new izStats[8]
new izBody[8]
new iLen
// 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]
// 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]
// 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
// 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
// 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)
// 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 (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
// 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
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)
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
// 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
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))
{
client_print(id, print_chat, "* %s", g_sBuffer)
format_kill_vinfo(id, iKiller, g_sBuffer)
}
client_print(id, print_chat, "* %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
}
/* AMX Mod X
* StatsX Plugin
*
* by the AMX Mod X Development Team
* originally developed by OLO
*
* This file is part of AMX Mod X.
*
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* In addition, as a special exception, the author gives permission to
* link the code of this program with the Half-Life Game Engine ("HL
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
* L.L.C ("Valve"). You must obey the GNU General Public License in all
* respects for all of the code used other than the HL Engine and MODs
* from Valve. If you modify this file, you may extend this exception
* to your version of the file, but you are not obligated to do so. If
* you do not wish to do so, delete this exception statement from your
* version.
*/
// HUD statistics stop relative freeze end in seconds.
// To stop before freeze end use a negative value.
#define HUD_FREEZE_LIMIT_CVAR "amx_statsx_freeze"
#define HUD_FREEZE_LIMIT "-2.0"
// HUD statistics minimum duration, in seconds, to trigger the display logic.
#define HUD_MIN_DURATION 0.2
// Config plugin constants.
#define MODE_HUD_DELAY 0 // Make a 0.01 sec delay on HUD reset process.
// You can also manualy enable or disable these options by setting them to 1
// For example:
// public ShowAttackers = 1
// However amx_statscfg command is recommended
public KillerChat = 0 // displays killer hp&ap to victim console
// and screen
public ShowAttackers = 0 // shows attackers
public ShowVictims = 0 // shows victims
public ShowKiller = 0 // shows killer
public ShowTeamScore = 0 // shows team score at round end
public ShowTotalStats = 0 // shows round total stats
public ShowBestScore = 0 // shows rounds best scored player
public ShowMostDisruptive = 0 // shows rounds most disruptive player
public EndPlayer = 0 // displays player stats at the end of map
public EndTop15 = 0 // displays top15 at the end of map
public SayHP = 0 // displays information about user killer
public SayStatsMe = 0 // displays user's stats and rank
public SayRankStats = 0 // displays user's rank stats
public SayMe = 0 // displays user's stats
public SayRank = 0 // displays user's rank
public SayReport = 0 // report user's weapon status to team
public SayScore = 0 // displays team's map score
public SayTop15 = 0 // displays first 15 players
public SayStatsAll = 0 // displays all players stats and rank
public ShowStats = 1 // set client HUD-stats switched off by default
public ShowDistHS = 0 // show distance and HS in attackers and
// victims HUD lists
public ShowFullStats = 0 // show full HUD stats (more than 78 chars)
public SpecRankInfo = 0 // displays rank info when spectating
// Global player flags.
new BODY_PART[8][] =
{
"WHOLEBODY",
"HEAD",
"CHEST",
"STOMACH",
"LEFTARM",
"RIGHTARM",
"LEFTLEG",
"RIGHTLEG"
}
// Killer information, save killer info at the time when player is killed.
#define KILLED_KILLER_ID 0 // Killer userindex/user-ID
#define KILLED_KILLER_HEALTH 1 // Killer's health
#define KILLED_KILLER_ARMOUR 2 // Killer's armour
#define KILLED_TEAM 3 // Killer's team
#define KILLED_KILLER_STATSFIX 4 // Fix to register the last hit/kill
new g_izKilled[MAX_PLAYERS][5]
// Menu variables and configuration
#define MAX_PPL_MENU_ACTIONS 2 // Number of player menu actions
#define PPL_MENU_OPTIONS 7 // Number of player options per displayed menu
new g_iPluginMode = 0
new g_izUserMenuPosition[MAX_PLAYERS] = {0, ...}
new g_izUserMenuAction[MAX_PLAYERS] = {0, ...}
new g_izUserMenuPlayers[MAX_PLAYERS][32]
new g_izSpecMode[MAX_PLAYERS] = {0, ...}
new g_izShowStatsFlags[MAX_PLAYERS] = {0, ...}
new g_izStatsSwitch[MAX_PLAYERS] = {0, ...}
new Float:g_fzShowUserStatsTime[MAX_PLAYERS] = {0.0, ...}
new Float:g_fShowStatsTime = 0.0
new Float:g_fFreezeTime = 0.0
new Float:g_fFreezeLimitTime = 0.0
new Float:g_fHUDDuration = 0.0
new g_iRoundEndTriggered = 0
new g_iRoundEndProcessed = 0
new Float:g_fStartGame = 0.0
new g_izTeamScore[MAX_TEAMS] = {0, ...}
new g_izTeamEventScore[MAX_TEAMS] = {0, ...}
new g_izTeamRndStats[MAX_TEAMS][8]
new g_izTeamGameStats[MAX_TEAMS][8]
new g_izUserUserID[MAX_PLAYERS] = {0, ...}
new g_izUserAttackerDistance[MAX_PLAYERS] = {0, ...}
new g_izUserVictimDistance[MAX_PLAYERS][MAX_PLAYERS]
new g_izUserRndName[MAX_PLAYERS][MAX_NAME_LENGTH + 1]
new g_izUserRndStats[MAX_PLAYERS][8]
new g_izUserGameStats[MAX_PLAYERS][8]
// Common buffer to improve performance, as Small always zero-initializes all vars
new g_sBuffer[MAX_BUFFER_LENGTH + 1] = ""
new g_sScore[MAX_TEXT_LENGTH + 1] = ""
new g_sAwardAndScore[MAX_BUFFER_LENGTH + 1] = ""
new t_sText[MAX_TEXT_LENGTH + 1] = ""
new t_sName[MAX_NAME_LENGTH + 1] = ""
new t_sWpn[MAX_WEAPON_LENGTH + 1] = ""
new g_HudSync_EndRound
new g_HudSync_SpecInfo
//--------------------------------
// Initialize
//--------------------------------
public plugin_init()
{
// Register plugin.
register_plugin("StatsX", AMXX_VERSION_STR, "AMXX Dev Team")
register_dictionary("statsx.txt")
// Get and format attackers header and list.
get_attackers(id, sBuffer[MAX_BUFFER_LENGTH + 1])
{
new izStats[8], izBody[8]
new iAttacker
new iFound, iLen
new iMaxPlayer = get_maxplayers()
iFound = 0
sBuffer[0] = 0
// Get and format header. Add killing attacker statistics if user is dead.
// Make sure shots is greater than zero or division by zero will occur.
// To print a '%', 4 of them must done in a row.
izStats[STATS_SHOTS] = 0
iAttacker = g_izKilled[id][KILLED_KILLER_ID]
if (iAttacker)
get_user_astats(id, iAttacker, izStats, izBody)
// Get and format victims header and list
get_victims(id, sBuffer[MAX_BUFFER_LENGTH + 1])
{
new izStats[8], izBody[8]
new iVictim
new iFound, iLen
new iMaxPlayer = get_maxplayers()
iFound = 0
sBuffer[0] = 0
// Get and format header.
// Make sure shots is greater than zero or division by zero will occur.
// To print a '%', 4 of them must done in a row.
izStats[STATS_SHOTS] = 0
get_user_vstats(id, 0, izStats, izBody)
// Get and format team score.
add_team_score(sBuffer[MAX_BUFFER_LENGTH + 1])
{
new Float:fzMapEff[MAX_TEAMS], Float:fzMapAcc[MAX_TEAMS], Float:fzRndAcc[MAX_TEAMS]
// Calculate team stats
for (new iTeam = 0; iTeam < MAX_TEAMS; iTeam++)
{
fzMapEff[iTeam] = effec(g_izTeamGameStats[iTeam])
fzMapAcc[iTeam] = accuracy(g_izTeamGameStats[iTeam])
fzRndAcc[iTeam] = accuracy(g_izTeamRndStats[iTeam])
}
// Get and format killed stats: hits, damage on killer.
format_kill_vinfo(id, iKiller, sBuffer[MAX_BUFFER_LENGTH + 1])
{
new iFound = 0
new izStats[8]
new izBody[8]
new iLen
// 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]
// 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]
// 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
// 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
// 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)
// 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 (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
// 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
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)
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
// 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
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))
{
client_print(id, print_chat, "* %s", g_sBuffer)
format_kill_vinfo(id, iKiller, g_sBuffer)
}
client_print(id, print_chat, "* %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
}
(16/07/2020, 11:43 PM)Boddah. escribió: gracias amigo, pero podrias ponerle que los trofeos salgan al lado del numero?
No lo probé, pero creo que ahí te sirve.
Código PHP:
/* AMX Mod X * StatsX Plugin * * by the AMX Mod X Development Team * originally developed by OLO * * This file is part of AMX Mod X. * * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * In addition, as a special exception, the author gives permission to * link the code of this program with the Half-Life Game Engine ("HL * Engine") and Modified Game Libraries ("MODs") developed by Valve, * L.L.C ("Valve"). You must obey the GNU General Public License in all * respects for all of the code used other than the HL Engine and MODs * from Valve. If you modify this file, you may extend this exception * to your version of the file, but you are not obligated to do so. If * you do not wish to do so, delete this exception statement from your * version. */
// HUD statistics stop relative freeze end in seconds. // To stop before freeze end use a negative value. #define HUD_FREEZE_LIMIT_CVAR "amx_statsx_freeze" #define HUD_FREEZE_LIMIT "-2.0"
// HUD statistics minimum duration, in seconds, to trigger the display logic. #define HUD_MIN_DURATION 0.2
// Config plugin constants. #define MODE_HUD_DELAY 0 // Make a 0.01 sec delay on HUD reset process.
// You can also manualy enable or disable these options by setting them to 1 // For example: // public ShowAttackers = 1 // However amx_statscfg command is recommended
public KillerChat = 0 // displays killer hp&ap to victim console // and screen
public ShowAttackers = 0 // shows attackers public ShowVictims = 0 // shows victims public ShowKiller = 0 // shows killer public ShowTeamScore = 0 // shows team score at round end public ShowTotalStats = 0 // shows round total stats public ShowBestScore = 0 // shows rounds best scored player public ShowMostDisruptive = 0 // shows rounds most disruptive player
public EndPlayer = 0 // displays player stats at the end of map public EndTop15 = 0 // displays top15 at the end of map
public SayHP = 0 // displays information about user killer public SayStatsMe = 0 // displays user's stats and rank public SayRankStats = 0 // displays user's rank stats public SayMe = 0 // displays user's stats public SayRank = 0 // displays user's rank public SayReport = 0 // report user's weapon status to team public SayScore = 0 // displays team's map score public SayTop15 = 0 // displays first 15 players public SayStatsAll = 0 // displays all players stats and rank
public ShowStats = 1 // set client HUD-stats switched off by default public ShowDistHS = 0 // show distance and HS in attackers and // victims HUD lists public ShowFullStats = 0 // show full HUD stats (more than 78 chars)
public SpecRankInfo = 0 // displays rank info when spectating
// Global player flags. new BODY_PART[8][] = { "WHOLEBODY", "HEAD", "CHEST", "STOMACH", "LEFTARM", "RIGHTARM", "LEFTLEG", "RIGHTLEG" }
// Killer information, save killer info at the time when player is killed. #define KILLED_KILLER_ID 0 // Killer userindex/user-ID #define KILLED_KILLER_HEALTH 1 // Killer's health #define KILLED_KILLER_ARMOUR 2 // Killer's armour #define KILLED_TEAM 3 // Killer's team #define KILLED_KILLER_STATSFIX 4 // Fix to register the last hit/kill
new g_izKilled[MAX_PLAYERS][5]
// Menu variables and configuration #define MAX_PPL_MENU_ACTIONS 2 // Number of player menu actions #define PPL_MENU_OPTIONS 7 // Number of player options per displayed menu
new g_iPluginMode = 0
new g_izUserMenuPosition[MAX_PLAYERS] = {0, ...} new g_izUserMenuAction[MAX_PLAYERS] = {0, ...} new g_izUserMenuPlayers[MAX_PLAYERS][32]
new g_izSpecMode[MAX_PLAYERS] = {0, ...}
new g_izShowStatsFlags[MAX_PLAYERS] = {0, ...} new g_izStatsSwitch[MAX_PLAYERS] = {0, ...} new Float:g_fzShowUserStatsTime[MAX_PLAYERS] = {0.0, ...} new Float:g_fShowStatsTime = 0.0 new Float:g_fFreezeTime = 0.0 new Float:g_fFreezeLimitTime = 0.0 new Float:g_fHUDDuration = 0.0
new g_iRoundEndTriggered = 0 new g_iRoundEndProcessed = 0
new Float:g_fStartGame = 0.0 new g_izTeamScore[MAX_TEAMS] = {0, ...} new g_izTeamEventScore[MAX_TEAMS] = {0, ...} new g_izTeamRndStats[MAX_TEAMS][8] new g_izTeamGameStats[MAX_TEAMS][8] new g_izUserUserID[MAX_PLAYERS] = {0, ...} new g_izUserAttackerDistance[MAX_PLAYERS] = {0, ...} new g_izUserVictimDistance[MAX_PLAYERS][MAX_PLAYERS] new g_izUserRndName[MAX_PLAYERS][MAX_NAME_LENGTH + 1] new g_izUserRndStats[MAX_PLAYERS][8] new g_izUserGameStats[MAX_PLAYERS][8]
// Common buffer to improve performance, as Small always zero-initializes all vars new g_sBuffer[MAX_BUFFER_LENGTH + 1] = "" new g_sScore[MAX_TEXT_LENGTH + 1] = "" new g_sAwardAndScore[MAX_BUFFER_LENGTH + 1] = ""
new t_sText[MAX_TEXT_LENGTH + 1] = "" new t_sName[MAX_NAME_LENGTH + 1] = "" new t_sWpn[MAX_WEAPON_LENGTH + 1] = ""
new g_HudSync_EndRound new g_HudSync_SpecInfo
//-------------------------------- // Initialize //-------------------------------- public plugin_init() { // Register plugin. register_plugin("StatsX", AMXX_VERSION_STR, "AMXX Dev Team") register_dictionary("statsx.txt")
// Get and format attackers header and list. get_attackers(id, sBuffer[MAX_BUFFER_LENGTH + 1]) { new izStats[8], izBody[8] new iAttacker new iFound, iLen new iMaxPlayer = get_maxplayers()
iFound = 0 sBuffer[0] = 0
// Get and format header. Add killing attacker statistics if user is dead. // Make sure shots is greater than zero or division by zero will occur. // To print a '%', 4 of them must done in a row. izStats[STATS_SHOTS] = 0 iAttacker = g_izKilled[id][KILLED_KILLER_ID]
if (iAttacker) get_user_astats(id, iAttacker, izStats, izBody)
// Get and format victims header and list get_victims(id, sBuffer[MAX_BUFFER_LENGTH + 1]) { new izStats[8], izBody[8] new iVictim new iFound, iLen new iMaxPlayer = get_maxplayers()
iFound = 0 sBuffer[0] = 0
// Get and format header. // Make sure shots is greater than zero or division by zero will occur. // To print a '%', 4 of them must done in a row. izStats[STATS_SHOTS] = 0 get_user_vstats(id, 0, izStats, izBody)
// Get and format team score. add_team_score(sBuffer[MAX_BUFFER_LENGTH + 1]) { new Float:fzMapEff[MAX_TEAMS], Float:fzMapAcc[MAX_TEAMS], Float:fzRndAcc[MAX_TEAMS]
// Calculate team stats for (new iTeam = 0; iTeam < MAX_TEAMS; iTeam++) { fzMapEff[iTeam] = effec(g_izTeamGameStats[iTeam]) fzMapAcc[iTeam] = accuracy(g_izTeamGameStats[iTeam]) fzRndAcc[iTeam] = accuracy(g_izTeamRndStats[iTeam]) }
// Get and format killed stats: hits, damage on killer. format_kill_vinfo(id, iKiller, sBuffer[MAX_BUFFER_LENGTH + 1]) { new iFound = 0 new izStats[8] new izBody[8] new iLen
// 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]
// 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]
// 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
// 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
// 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)
// 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 (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
// 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
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)
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
// 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
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)) { client_print(id, print_chat, "* %s", g_sBuffer) format_kill_vinfo(id, iKiller, g_sBuffer) }
client_print(id, print_chat, "* %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 }
(17/07/2020, 01:07 AM)andres_1041 escribió: No lo probé, pero creo que ahí te sirve.
Código PHP:
/* AMX Mod X * StatsX Plugin * * by the AMX Mod X Development Team * originally developed by OLO * * This file is part of AMX Mod X. * * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * In addition, as a special exception, the author gives permission to * link the code of this program with the Half-Life Game Engine ("HL * Engine") and Modified Game Libraries ("MODs") developed by Valve, * L.L.C ("Valve"). You must obey the GNU General Public License in all * respects for all of the code used other than the HL Engine and MODs * from Valve. If you modify this file, you may extend this exception * to your version of the file, but you are not obligated to do so. If * you do not wish to do so, delete this exception statement from your * version. */
// HUD statistics stop relative freeze end in seconds. // To stop before freeze end use a negative value. #define HUD_FREEZE_LIMIT_CVAR "amx_statsx_freeze" #define HUD_FREEZE_LIMIT "-2.0"
// HUD statistics minimum duration, in seconds, to trigger the display logic. #define HUD_MIN_DURATION 0.2
// Config plugin constants. #define MODE_HUD_DELAY 0 // Make a 0.01 sec delay on HUD reset process.
// You can also manualy enable or disable these options by setting them to 1 // For example: // public ShowAttackers = 1 // However amx_statscfg command is recommended
public KillerChat = 0 // displays killer hp&ap to victim console // and screen
public ShowAttackers = 0 // shows attackers public ShowVictims = 0 // shows victims public ShowKiller = 0 // shows killer public ShowTeamScore = 0 // shows team score at round end public ShowTotalStats = 0 // shows round total stats public ShowBestScore = 0 // shows rounds best scored player public ShowMostDisruptive = 0 // shows rounds most disruptive player
public EndPlayer = 0 // displays player stats at the end of map public EndTop15 = 0 // displays top15 at the end of map
public SayHP = 0 // displays information about user killer public SayStatsMe = 0 // displays user's stats and rank public SayRankStats = 0 // displays user's rank stats public SayMe = 0 // displays user's stats public SayRank = 0 // displays user's rank public SayReport = 0 // report user's weapon status to team public SayScore = 0 // displays team's map score public SayTop15 = 0 // displays first 15 players public SayStatsAll = 0 // displays all players stats and rank
public ShowStats = 1 // set client HUD-stats switched off by default public ShowDistHS = 0 // show distance and HS in attackers and // victims HUD lists public ShowFullStats = 0 // show full HUD stats (more than 78 chars)
public SpecRankInfo = 0 // displays rank info when spectating
// Global player flags. new BODY_PART[8][] = { "WHOLEBODY", "HEAD", "CHEST", "STOMACH", "LEFTARM", "RIGHTARM", "LEFTLEG", "RIGHTLEG" }
// Killer information, save killer info at the time when player is killed. #define KILLED_KILLER_ID 0 // Killer userindex/user-ID #define KILLED_KILLER_HEALTH 1 // Killer's health #define KILLED_KILLER_ARMOUR 2 // Killer's armour #define KILLED_TEAM 3 // Killer's team #define KILLED_KILLER_STATSFIX 4 // Fix to register the last hit/kill
new g_izKilled[MAX_PLAYERS][5]
// Menu variables and configuration #define MAX_PPL_MENU_ACTIONS 2 // Number of player menu actions #define PPL_MENU_OPTIONS 7 // Number of player options per displayed menu
new g_iPluginMode = 0
new g_izUserMenuPosition[MAX_PLAYERS]= {0, ...} new g_izUserMenuAction[MAX_PLAYERS]= {0, ...} new g_izUserMenuPlayers[MAX_PLAYERS][32]
new g_izSpecMode[MAX_PLAYERS]= {0, ...}
new g_izShowStatsFlags[MAX_PLAYERS]= {0, ...} new g_izStatsSwitch[MAX_PLAYERS]= {0, ...} new Float:g_fzShowUserStatsTime[MAX_PLAYERS]= {0.0, ...} new Float:g_fShowStatsTime = 0.0 new Float:g_fFreezeTime = 0.0 new Float:g_fFreezeLimitTime = 0.0 new Float:g_fHUDDuration = 0.0
new g_iRoundEndTriggered = 0 new g_iRoundEndProcessed = 0
new Float:g_fStartGame = 0.0 new g_izTeamScore[MAX_TEAMS]= {0, ...} new g_izTeamEventScore[MAX_TEAMS]= {0, ...} new g_izTeamRndStats[MAX_TEAMS][8] new g_izTeamGameStats[MAX_TEAMS][8] new g_izUserUserID[MAX_PLAYERS]= {0, ...} new g_izUserAttackerDistance[MAX_PLAYERS]= {0, ...} new g_izUserVictimDistance[MAX_PLAYERS][MAX_PLAYERS] new g_izUserRndName[MAX_PLAYERS][MAX_NAME_LENGTH + 1] new g_izUserRndStats[MAX_PLAYERS][8] new g_izUserGameStats[MAX_PLAYERS][8]
// Common buffer to improve performance, as Small always zero-initializes all vars new g_sBuffer[MAX_BUFFER_LENGTH + 1]= "" new g_sScore[MAX_TEXT_LENGTH + 1]= "" new g_sAwardAndScore[MAX_BUFFER_LENGTH + 1]= ""
new t_sText[MAX_TEXT_LENGTH + 1]= "" new t_sName[MAX_NAME_LENGTH + 1]= "" new t_sWpn[MAX_WEAPON_LENGTH + 1]= ""
new g_HudSync_EndRound new g_HudSync_SpecInfo
//-------------------------------- // Initialize //-------------------------------- public plugin_init() { // Register plugin. register_plugin("StatsX", AMXX_VERSION_STR, "AMXX Dev Team") register_dictionary("statsx.txt")
// Get and format attackers header and list. get_attackers(id, sBuffer[MAX_BUFFER_LENGTH + 1]) { new izStats[8], izBody[8] new iAttacker new iFound, iLen new iMaxPlayer = get_maxplayers()
iFound = 0 sBuffer[0] = 0
// Get and format header. Add killing attacker statistics if user is dead. // Make sure shots is greater than zero or division by zero will occur. // To print a '%', 4 of them must done in a row. izStats[STATS_SHOTS] = 0 iAttacker = g_izKilled[id][KILLED_KILLER_ID] if (iAttacker) get_user_astats(id, iAttacker, izStats, izBody) if (izStats[STATS_SHOTS] && ShowFullStats) { get_user_name(iAttacker, t_sName, MAX_NAME_LENGTH) iLen = format(sBuffer, MAX_BUFFER_LENGTH, "%L -- %s -- %0.2f%% %L:^n", id, "ATTACKERS", t_sName, accuracy(izStats), id, "ACC") } else iLen = format(sBuffer, MAX_BUFFER_LENGTH, "%L:^n", id, "ATTACKERS")
// Get and format victims header and list get_victims(id, sBuffer[MAX_BUFFER_LENGTH + 1]) { new izStats[8], izBody[8] new iVictim new iFound, iLen new iMaxPlayer = get_maxplayers()
iFound = 0 sBuffer[0] = 0
// Get and format header. // Make sure shots is greater than zero or division by zero will occur. // To print a '%', 4 of them must done in a row. izStats[STATS_SHOTS] = 0 get_user_vstats(id, 0, izStats, izBody) if (izStats[STATS_SHOTS]) iLen = format(sBuffer, MAX_BUFFER_LENGTH, "%L -- %0.2f%% %L:^n", id, "VICTIMS", accuracy(izStats), id, "ACC") else iLen = format(sBuffer, MAX_BUFFER_LENGTH, "%L:^n", id, "VICTIMS")
// Get and format team score. add_team_score(sBuffer[MAX_BUFFER_LENGTH + 1]) { new Float:fzMapEff[MAX_TEAMS], Float:fzMapAcc[MAX_TEAMS], Float:fzRndAcc[MAX_TEAMS]
// Calculate team stats for (new iTeam = 0; iTeam < MAX_TEAMS; iTeam++) { fzMapEff[iTeam] = effec(g_izTeamGameStats[iTeam]) fzMapAcc[iTeam] = accuracy(g_izTeamGameStats[iTeam]) fzRndAcc[iTeam] = accuracy(g_izTeamRndStats[iTeam]) }
if (izStats[STATS_HITS]) { for (new i = 1; i < 8; i++) { if (!izBody[i]) continue iLen += format(sBuffer[iLen], MAX_BUFFER_LENGTH - iLen, " %L: %d", id, BODY_PART[i], izBody[i]) } } else iLen += format(sBuffer[iLen], MAX_BUFFER_LENGTH - iLen, " %L", id, "NO_HITS") } else format(sBuffer, MAX_BUFFER_LENGTH, "%L", id, "YOU_NO_KILLER") return iFound }
// Get and format killed stats: hits, damage on killer. format_kill_vinfo(id, iKiller, sBuffer[MAX_BUFFER_LENGTH + 1]) { new iFound = 0 new izStats[8] new izBody[8] new iLen
// 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 (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
// 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
// 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
// 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
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)
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
// 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
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)) { client_print(id, print_chat, "* %s", g_sBuffer) format_kill_vinfo(id, iKiller, g_sBuffer) } client_print(id, print_chat, "* %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]++ }
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 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
(16/07/2020, 11:43 PM)Boddah. escribió: gracias amigo, pero podrias ponerle que los trofeos salgan al lado del numero?
Código PHP:
/* AMX Mod X * StatsX Plugin * * by the AMX Mod X Development Team * originally developed by OLO * * This file is part of AMX Mod X. * * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * In addition, as a special exception, the author gives permission to * link the code of this program with the Half-Life Game Engine ("HL * Engine") and Modified Game Libraries ("MODs") developed by Valve, * L.L.C ("Valve"). You must obey the GNU General Public License in all * respects for all of the code used other than the HL Engine and MODs * from Valve. If you modify this file, you may extend this exception * to your version of the file, but you are not obligated to do so. If * you do not wish to do so, delete this exception statement from your * version. */
// HUD statistics stop relative freeze end in seconds. // To stop before freeze end use a negative value. #define HUD_FREEZE_LIMIT_CVAR "amx_statsx_freeze" #define HUD_FREEZE_LIMIT "-2.0"
// HUD statistics minimum duration, in seconds, to trigger the display logic. #define HUD_MIN_DURATION 0.2
// Config plugin constants. #define MODE_HUD_DELAY 0 // Make a 0.01 sec delay on HUD reset process.
// You can also manualy enable or disable these options by setting them to 1 // For example: // public ShowAttackers = 1 // However amx_statscfg command is recommended
public KillerChat = 0 // displays killer hp&ap to victim console // and screen
public ShowAttackers = 0 // shows attackers public ShowVictims = 0 // shows victims public ShowKiller = 0 // shows killer public ShowTeamScore = 0 // shows team score at round end public ShowTotalStats = 0 // shows round total stats public ShowBestScore = 0 // shows rounds best scored player public ShowMostDisruptive = 0 // shows rounds most disruptive player
public EndPlayer = 0 // displays player stats at the end of map public EndTop15 = 0 // displays top15 at the end of map
public SayHP = 0 // displays information about user killer public SayStatsMe = 0 // displays user's stats and rank public SayRankStats = 0 // displays user's rank stats public SayMe = 0 // displays user's stats public SayRank = 0 // displays user's rank public SayReport = 0 // report user's weapon status to team public SayScore = 0 // displays team's map score public SayTop15 = 0 // displays first 15 players public SayStatsAll = 0 // displays all players stats and rank
public ShowStats = 1 // set client HUD-stats switched off by default public ShowDistHS = 0 // show distance and HS in attackers and // victims HUD lists public ShowFullStats = 0 // show full HUD stats (more than 78 chars)
public SpecRankInfo = 0 // displays rank info when spectating
// Global player flags. new BODY_PART[8][] = { "WHOLEBODY", "HEAD", "CHEST", "STOMACH", "LEFTARM", "RIGHTARM", "LEFTLEG", "RIGHTLEG" }
// Killer information, save killer info at the time when player is killed. #define KILLED_KILLER_ID 0 // Killer userindex/user-ID #define KILLED_KILLER_HEALTH 1 // Killer's health #define KILLED_KILLER_ARMOUR 2 // Killer's armour #define KILLED_TEAM 3 // Killer's team #define KILLED_KILLER_STATSFIX 4 // Fix to register the last hit/kill
new g_izKilled[MAX_PLAYERS][5]
// Menu variables and configuration #define MAX_PPL_MENU_ACTIONS 2 // Number of player menu actions #define PPL_MENU_OPTIONS 7 // Number of player options per displayed menu
new g_iPluginMode = 0
new g_izUserMenuPosition[MAX_PLAYERS] = {0, ...} new g_izUserMenuAction[MAX_PLAYERS] = {0, ...} new g_izUserMenuPlayers[MAX_PLAYERS][32]
new g_izSpecMode[MAX_PLAYERS] = {0, ...}
new g_izShowStatsFlags[MAX_PLAYERS] = {0, ...} new g_izStatsSwitch[MAX_PLAYERS] = {0, ...} new Float:g_fzShowUserStatsTime[MAX_PLAYERS] = {0.0, ...} new Float:g_fShowStatsTime = 0.0 new Float:g_fFreezeTime = 0.0 new Float:g_fFreezeLimitTime = 0.0 new Float:g_fHUDDuration = 0.0
new g_iRoundEndTriggered = 0 new g_iRoundEndProcessed = 0
new Float:g_fStartGame = 0.0 new g_izTeamScore[MAX_TEAMS] = {0, ...} new g_izTeamEventScore[MAX_TEAMS] = {0, ...} new g_izTeamRndStats[MAX_TEAMS][8] new g_izTeamGameStats[MAX_TEAMS][8] new g_izUserUserID[MAX_PLAYERS] = {0, ...} new g_izUserAttackerDistance[MAX_PLAYERS] = {0, ...} new g_izUserVictimDistance[MAX_PLAYERS][MAX_PLAYERS] new g_izUserRndName[MAX_PLAYERS][MAX_NAME_LENGTH + 1] new g_izUserRndStats[MAX_PLAYERS][8] new g_izUserGameStats[MAX_PLAYERS][8]
// Common buffer to improve performance, as Small always zero-initializes all vars new g_sBuffer[MAX_BUFFER_LENGTH + 1] = "" new g_sScore[MAX_TEXT_LENGTH + 1] = "" new g_sAwardAndScore[MAX_BUFFER_LENGTH + 1] = ""
new t_sText[MAX_TEXT_LENGTH + 1] = "" new t_sName[MAX_NAME_LENGTH + 1] = "" new t_sWpn[MAX_WEAPON_LENGTH + 1] = ""
new g_HudSync_EndRound new g_HudSync_SpecInfo
//-------------------------------- // Initialize //-------------------------------- public plugin_init() { // Register plugin. register_plugin("StatsX", AMXX_VERSION_STR, "AMXX Dev Team") register_dictionary("statsx.txt")
// Get and format attackers header and list. get_attackers(id, sBuffer[MAX_BUFFER_LENGTH + 1]) { new izStats[8], izBody[8] new iAttacker new iFound, iLen new iMaxPlayer = get_maxplayers()
iFound = 0 sBuffer[0] = 0
// Get and format header. Add killing attacker statistics if user is dead. // Make sure shots is greater than zero or division by zero will occur. // To print a '%', 4 of them must done in a row. izStats[STATS_SHOTS] = 0 iAttacker = g_izKilled[id][KILLED_KILLER_ID]
if (iAttacker) get_user_astats(id, iAttacker, izStats, izBody)
// Get and format victims header and list get_victims(id, sBuffer[MAX_BUFFER_LENGTH + 1]) { new izStats[8], izBody[8] new iVictim new iFound, iLen new iMaxPlayer = get_maxplayers()
iFound = 0 sBuffer[0] = 0
// Get and format header. // Make sure shots is greater than zero or division by zero will occur. // To print a '%', 4 of them must done in a row. izStats[STATS_SHOTS] = 0 get_user_vstats(id, 0, izStats, izBody)
// Get and format team score. add_team_score(sBuffer[MAX_BUFFER_LENGTH + 1]) { new Float:fzMapEff[MAX_TEAMS], Float:fzMapAcc[MAX_TEAMS], Float:fzRndAcc[MAX_TEAMS]
// Calculate team stats for (new iTeam = 0; iTeam < MAX_TEAMS; iTeam++) { fzMapEff[iTeam] = effec(g_izTeamGameStats[iTeam]) fzMapAcc[iTeam] = accuracy(g_izTeamGameStats[iTeam]) fzRndAcc[iTeam] = accuracy(g_izTeamRndStats[iTeam]) }
// Get and format killed stats: hits, damage on killer. format_kill_vinfo(id, iKiller, sBuffer[MAX_BUFFER_LENGTH + 1]) { new iFound = 0 new izStats[8] new izBody[8] new iLen
// 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]
// 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]
// 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
// 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
// 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)
// 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 (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
// 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
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)
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
// 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
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)) { client_print(id, print_chat, "* %s", g_sBuffer) format_kill_vinfo(id, iKiller, g_sBuffer) }
client_print(id, print_chat, "* %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 }
17/07/2020, 01:38 PM (Última modificación: 17/07/2020, 02:00 PM por Boddah.. Edited 5 times in total.)
(17/07/2020, 11:12 AM)KardigaN escribió:
Código PHP:
/* AMX Mod X * StatsX Plugin * * by the AMX Mod X Development Team * originally developed by OLO * * This file is part of AMX Mod X. * * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * In addition, as a special exception, the author gives permission to * link the code of this program with the Half-Life Game Engine ("HL * Engine") and Modified Game Libraries ("MODs") developed by Valve, * L.L.C ("Valve"). You must obey the GNU General Public License in all * respects for all of the code used other than the HL Engine and MODs * from Valve. If you modify this file, you may extend this exception * to your version of the file, but you are not obligated to do so. If * you do not wish to do so, delete this exception statement from your * version. */
// HUD statistics stop relative freeze end in seconds. // To stop before freeze end use a negative value. #define HUD_FREEZE_LIMIT_CVAR "amx_statsx_freeze" #define HUD_FREEZE_LIMIT "-2.0"
// HUD statistics minimum duration, in seconds, to trigger the display logic. #define HUD_MIN_DURATION 0.2
// Config plugin constants. #define MODE_HUD_DELAY 0 // Make a 0.01 sec delay on HUD reset process.
// You can also manualy enable or disable these options by setting them to 1 // For example: // public ShowAttackers = 1 // However amx_statscfg command is recommended
public KillerChat = 0 // displays killer hp&ap to victim console // and screen
public ShowAttackers = 0 // shows attackers public ShowVictims = 0 // shows victims public ShowKiller = 0 // shows killer public ShowTeamScore = 0 // shows team score at round end public ShowTotalStats = 0 // shows round total stats public ShowBestScore = 0 // shows rounds best scored player public ShowMostDisruptive = 0 // shows rounds most disruptive player
public EndPlayer = 0 // displays player stats at the end of map public EndTop15 = 0 // displays top15 at the end of map
public SayHP = 0 // displays information about user killer public SayStatsMe = 0 // displays user's stats and rank public SayRankStats = 0 // displays user's rank stats public SayMe = 0 // displays user's stats public SayRank = 0 // displays user's rank public SayReport = 0 // report user's weapon status to team public SayScore = 0 // displays team's map score public SayTop15 = 0 // displays first 15 players public SayStatsAll = 0 // displays all players stats and rank
public ShowStats = 1 // set client HUD-stats switched off by default public ShowDistHS = 0 // show distance and HS in attackers and // victims HUD lists public ShowFullStats = 0 // show full HUD stats (more than 78 chars)
public SpecRankInfo = 0 // displays rank info when spectating
// Global player flags. new BODY_PART[8][] = { "WHOLEBODY", "HEAD", "CHEST", "STOMACH", "LEFTARM", "RIGHTARM", "LEFTLEG", "RIGHTLEG" }
// Killer information, save killer info at the time when player is killed. #define KILLED_KILLER_ID 0 // Killer userindex/user-ID #define KILLED_KILLER_HEALTH 1 // Killer's health #define KILLED_KILLER_ARMOUR 2 // Killer's armour #define KILLED_TEAM 3 // Killer's team #define KILLED_KILLER_STATSFIX 4 // Fix to register the last hit/kill
new g_izKilled[MAX_PLAYERS][5]
// Menu variables and configuration #define MAX_PPL_MENU_ACTIONS 2 // Number of player menu actions #define PPL_MENU_OPTIONS 7 // Number of player options per displayed menu
new g_iPluginMode = 0
new g_izUserMenuPosition[MAX_PLAYERS]= {0, ...} new g_izUserMenuAction[MAX_PLAYERS]= {0, ...} new g_izUserMenuPlayers[MAX_PLAYERS][32]
new g_izSpecMode[MAX_PLAYERS]= {0, ...}
new g_izShowStatsFlags[MAX_PLAYERS]= {0, ...} new g_izStatsSwitch[MAX_PLAYERS]= {0, ...} new Float:g_fzShowUserStatsTime[MAX_PLAYERS]= {0.0, ...} new Float:g_fShowStatsTime = 0.0 new Float:g_fFreezeTime = 0.0 new Float:g_fFreezeLimitTime = 0.0 new Float:g_fHUDDuration = 0.0
new g_iRoundEndTriggered = 0 new g_iRoundEndProcessed = 0
new Float:g_fStartGame = 0.0 new g_izTeamScore[MAX_TEAMS]= {0, ...} new g_izTeamEventScore[MAX_TEAMS]= {0, ...} new g_izTeamRndStats[MAX_TEAMS][8] new g_izTeamGameStats[MAX_TEAMS][8] new g_izUserUserID[MAX_PLAYERS]= {0, ...} new g_izUserAttackerDistance[MAX_PLAYERS]= {0, ...} new g_izUserVictimDistance[MAX_PLAYERS][MAX_PLAYERS] new g_izUserRndName[MAX_PLAYERS][MAX_NAME_LENGTH + 1] new g_izUserRndStats[MAX_PLAYERS][8] new g_izUserGameStats[MAX_PLAYERS][8]
// Common buffer to improve performance, as Small always zero-initializes all vars new g_sBuffer[MAX_BUFFER_LENGTH + 1]= "" new g_sScore[MAX_TEXT_LENGTH + 1]= "" new g_sAwardAndScore[MAX_BUFFER_LENGTH + 1]= ""
new t_sText[MAX_TEXT_LENGTH + 1]= "" new t_sName[MAX_NAME_LENGTH + 1]= "" new t_sWpn[MAX_WEAPON_LENGTH + 1]= ""
new g_HudSync_EndRound new g_HudSync_SpecInfo
//-------------------------------- // Initialize //-------------------------------- public plugin_init() { // Register plugin. register_plugin("StatsX", AMXX_VERSION_STR, "AMXX Dev Team") register_dictionary("statsx.txt")
// Get and format attackers header and list. get_attackers(id, sBuffer[MAX_BUFFER_LENGTH + 1]) { new izStats[8], izBody[8] new iAttacker new iFound, iLen new iMaxPlayer = get_maxplayers()
iFound = 0 sBuffer[0] = 0
// Get and format header. Add killing attacker statistics if user is dead. // Make sure shots is greater than zero or division by zero will occur. // To print a '%', 4 of them must done in a row. izStats[STATS_SHOTS] = 0 iAttacker = g_izKilled[id][KILLED_KILLER_ID] if (iAttacker) get_user_astats(id, iAttacker, izStats, izBody) if (izStats[STATS_SHOTS] && ShowFullStats) { get_user_name(iAttacker, t_sName, MAX_NAME_LENGTH) iLen = format(sBuffer, MAX_BUFFER_LENGTH, "%L -- %s -- %0.2f%% %L:^n", id, "ATTACKERS", t_sName, accuracy(izStats), id, "ACC") } else iLen = format(sBuffer, MAX_BUFFER_LENGTH, "%L:^n", id, "ATTACKERS")
// Get and format victims header and list get_victims(id, sBuffer[MAX_BUFFER_LENGTH + 1]) { new izStats[8], izBody[8] new iVictim new iFound, iLen new iMaxPlayer = get_maxplayers()
iFound = 0 sBuffer[0] = 0
// Get and format header. // Make sure shots is greater than zero or division by zero will occur. // To print a '%', 4 of them must done in a row. izStats[STATS_SHOTS] = 0 get_user_vstats(id, 0, izStats, izBody) if (izStats[STATS_SHOTS]) iLen = format(sBuffer, MAX_BUFFER_LENGTH, "%L -- %0.2f%% %L:^n", id, "VICTIMS", accuracy(izStats), id, "ACC") else iLen = format(sBuffer, MAX_BUFFER_LENGTH, "%L:^n", id, "VICTIMS")
// Get and format team score. add_team_score(sBuffer[MAX_BUFFER_LENGTH + 1]) { new Float:fzMapEff[MAX_TEAMS], Float:fzMapAcc[MAX_TEAMS], Float:fzRndAcc[MAX_TEAMS]
// Calculate team stats for (new iTeam = 0; iTeam < MAX_TEAMS; iTeam++) { fzMapEff[iTeam] = effec(g_izTeamGameStats[iTeam]) fzMapAcc[iTeam] = accuracy(g_izTeamGameStats[iTeam]) fzRndAcc[iTeam] = accuracy(g_izTeamRndStats[iTeam]) }
if (izStats[STATS_HITS]) { for (new i = 1; i < 8; i++) { if (!izBody[i]) continue iLen += format(sBuffer[iLen], MAX_BUFFER_LENGTH - iLen, " %L: %d", id, BODY_PART[i], izBody[i]) } } else iLen += format(sBuffer[iLen], MAX_BUFFER_LENGTH - iLen, " %L", id, "NO_HITS") } else format(sBuffer, MAX_BUFFER_LENGTH, "%L", id, "YOU_NO_KILLER") return iFound }
// Get and format killed stats: hits, damage on killer. format_kill_vinfo(id, iKiller, sBuffer[MAX_BUFFER_LENGTH + 1]) { new iFound = 0 new izStats[8] new izBody[8] new iLen
// 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 (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
// 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
// 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
// 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
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)
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
// 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
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)) { client_print(id, print_chat, "* %s", g_sBuffer) format_kill_vinfo(id, iKiller, g_sBuffer) } client_print(id, print_chat, "* %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]++ }
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 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
asi deberia quedar, donde sale marcado con rojo debajo del # deberian ir los trofeos y deben quedar todos los datos ordenados y centrados como los muestra la imagen. https://ibb.co/wRpZMg9