I'm not sure how much this will affect server performance, you may see impacts if your csstats.dat file is large. I couldn't test this because I have only bots to work with and they are not ranked in my test configuration.
I used ConnorMcLeod's
Spectator Hud Information as a base and made some modifications.
PHP Code:
//Used ConnorMcLeods plugin as base: https://forums.alliedmods.net/showthread.php?p=1469706
#include <amxmodx>
#include <engine>
#include <csx>
new const Version[] = "0.1";
const FirstPersonView = 4;
const Float:fRefreshInterval = 0.25;
new g_HUDSyncObj;
public plugin_init()
{
register_plugin( "Spec Rank Info" , Version , "bugsy" );
new iEntity = create_entity( "info_target" );
entity_set_string( iEntity , EV_SZ_classname , "SpecHUDEntity" );
register_think( "SpecHUDEntity" , "SpecHUDThink" );
entity_set_float( iEntity , EV_FL_nextthink , get_gametime() + fRefreshInterval );
g_HUDSyncObj = CreateHudSyncObj();
}
public SpecHUDThink( iEntity )
{
new iAlivePlayers[ 32 ] , iDeadPlayers[ 32 ] , iAliveNum , iDeadNum , iAlivePlayer , iDeadPlayer;
new iRank , iStats[ 8 ] , iBodyHits[ 8 ] , szName[ 32 ] , bool:bRetrievedData;
entity_set_float( iEntity , EV_FL_nextthink , get_gametime() + fRefreshInterval );
get_players( iAlivePlayers , iAliveNum , "a" );
if( !iAliveNum )
return
get_players( iDeadPlayers , iDeadNum , "bch" );
if( !iDeadNum )
return
for ( new iAlive = 0 ; iAlive < iAliveNum ; iAlive++ )
{
iAlivePlayer = iAlivePlayers[ iAlive ];
bRetrievedData = false;
for( new iDead = 0 ; iDead < iDeadNum ; iDead++ )
{
iDeadPlayer = iDeadPlayers[ iDead ];
if ( entity_get_int( iDeadPlayer , EV_INT_iuser2 ) == iAlivePlayer && entity_get_int( iDeadPlayer , EV_INT_iuser1 ) == FirstPersonView )
{
if ( bRetrievedData == false )
{
get_user_name( iAlivePlayer , szName , charsmax( szName ) );
iRank = get_user_stats( iAlivePlayer , iStats , iBodyHits );
bRetrievedData = true;
}
ClearSyncHud( iDeadPlayer , g_HUDSyncObj );
set_hudmessage( 255 , 255 , 255 , -1.0 , 0.25 , .holdtime=0.5 , .channel=-1 );
ShowSyncHudMsg( iDeadPlayer , g_HUDSyncObj , "%s^nRank: %d^nKills: %d^nDeaths: %d" , szName , iRank , iStats[ 0 ] , iStats[ 1 ] );
}
}
}
}
__________________