Raised This Month: $ Target: $400
 0% 

Show player rank while spectating


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
newb1e
Junior Member
Join Date: Feb 2016
Old 02-04-2016 , 14:25   Show player rank while spectating
Reply With Quote #1

hi. how can i add here a function that will show another player rank if you are spectating him?

PHP Code:
public Info() {
    for(new 
id 1id <= MaxPlayersid++)
    {
        if(
is_user_alive(id) && is_user_connected(id))
        {
            if(
PlayerLevel[id] <= 18)
            {
                
needXP[id] = LEVELS[PlayerLevel[id]] - PlayerXP[id];
                
set_hudmessage(1001001000.010.1501.01.0__, -1)
                static 
buffer[192], len;
                
len format(buffercharsmax(buffer), "%L",LANG_PLAYER,"RANK");
                
len += format(buffer[len], charsmax(buffer) - len" %L",LANG_PLAYER,RANKS[PlayerLevel[id]]);
                
len += format(buffer[len], charsmax(buffer) - len"^n%L %d",LANG_PLAYER,"PL_XP",PlayerXP[id]);
                
len += format(buffer[len], charsmax(buffer) - len"^n%L",LANG_PLAYER,"NEXT_LVL");
                
len += format(buffer[len], charsmax(buffer) - len" %d ",needXP[id]);
                
len += format(buffer[len], charsmax(buffer) - len"%L",LANG_PLAYER,"FRAGS");
                
ShowSyncHudMsg(idg_MsgHud"%s"buffer);
            } else {
                
set_hudmessage(1001001000.010.1301.01.0__, -1)
                static 
buffer[192], len;
                
len format(buffercharsmax(buffer), "%L",LANG_PLAYER,"RANK");
                
len += format(buffer[len], charsmax(buffer) - len" %L",LANG_PLAYER,RANKS[PlayerLevel[id]]);
                
len += format(buffer[len], charsmax(buffer) - len"^n%L",LANG_PLAYER,"PL_MAX");
                
ShowSyncHudMsg(idg_MsgHud"%s"buffer);
            }
        }
        
// if i'm dead, hide my rank
        
return PLUGIN_HANDLED
    
}
    return 
PLUGIN_CONTINUE


Last edited by newb1e; 02-04-2016 at 14:28.
newb1e is offline
Kakarot47
Senior Member
Join Date: May 2015
Location: Pakistan
Old 02-04-2016 , 16:49   Re: Show player rank while spectating
Reply With Quote #2

Show full code
__________________



AssasinSniperNightmare ModArmageddon ModApolacyps Mod
Kakarot47 is offline
Send a message via Skype™ to Kakarot47
Croxeye
Member
Join Date: Jul 2015
Old 02-04-2016 , 17:01   Re: Show player rank while spectating
Reply With Quote #3

Try this, not tested.

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <csstats>
#include <fakemeta>

#define PLUGIN "Spec Rank"
#define VERSION "1.0"
#define AUTHOR "Croxeye"

new g_SpecInfo

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)

    
set_task(1.0"SpecInfo"___"b")

    
g_SpecInfo CreateHudSyncObj()
}

public 
SpecInfo()
{
    new 
players[32], num 
    get_players
(playersnum"ch")
    
    new 
idtargetszTargetName[32]
    
    
target pev(idpev_iuser2)
    
    
set_hudmessage(085255, -1.00.7506.01.0)
    
    for(new 
inumi++)
    {
        
id players[i]
        
        if(!
is_user_alive(id))
        {
            
            if(!
target)
                continue
                
            if(
is_user_alive(target))
            {
                return 
PLUGIN_HANDLED;
            }
            
            
get_user_name(targetszTargetNamecharsmax(szTargetName))
            new 
stats[8], body[8]
            new 
rank_pos get_user_stats(targetstatsbody)
            new 
rank_max get_statsnum()
            
            
ShowSyncHudMsg(idg_SpecInfo"Spectating: %s ® Rank: %d of %d"szTargetNamerank_posrank_max)
        }
    }
    return 
PLUGIN_HANDLED;

Or just change this:

PHP Code:
len format(buffercharsmax(buffer), "%L",LANG_PLAYER,"RANK"); 
to this:

PHP Code:
len format(buffercharsmax(buffer), "%L %d",LANG_PLAYER,"RANK"rank_pos); 
and you need to define rank_pos

PHP Code:
new stats[8], body[8]
new 
rank_pos get_user_stats(idstatsbody

Last edited by Croxeye; 02-04-2016 at 17:12.
Croxeye is offline
newb1e
Junior Member
Join Date: Feb 2016
Old 02-04-2016 , 18:18   Re: Show player rank while spectating
Reply With Quote #4

Quote:
Originally Posted by Croxeye View Post
Try this, not tested.

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <csstats>
#include <fakemeta>

#define PLUGIN "Spec Rank"
#define VERSION "1.0"
#define AUTHOR "Croxeye"

new g_SpecInfo

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)

    
set_task(1.0"SpecInfo"___"b")

    
g_SpecInfo CreateHudSyncObj()
}

public 
SpecInfo()
{
    new 
players[32], num 
    get_players
(playersnum"ch")
    
    new 
idtargetszTargetName[32]
    
    
target pev(idpev_iuser2)
    
    
set_hudmessage(085255, -1.00.7506.01.0)
    
    for(new 
inumi++)
    {
        
id players[i]
        
        if(!
is_user_alive(id))
        {
            
            if(!
target)
                continue
                
            if(
is_user_alive(target))
            {
                return 
PLUGIN_HANDLED;
            }
            
            
get_user_name(targetszTargetNamecharsmax(szTargetName))
            new 
stats[8], body[8]
            new 
rank_pos get_user_stats(targetstatsbody)
            new 
rank_max get_statsnum()
            
            
ShowSyncHudMsg(idg_SpecInfo"Spectating: %s ® Rank: %d of %d"szTargetNamerank_posrank_max)
        }
    }
    return 
PLUGIN_HANDLED;

Or just change this:

PHP Code:
len format(buffercharsmax(buffer), "%L",LANG_PLAYER,"RANK"); 
to this:

PHP Code:
len format(buffercharsmax(buffer), "%L %d",LANG_PLAYER,"RANK"rank_pos); 
and you need to define rank_pos

PHP Code:
new stats[8], body[8]
new 
rank_pos get_user_stats(idstatsbody
not working mate
newb1e is offline
1ka
Senior Member
Join Date: Jun 2012
Old 10-22-2016 , 09:18   Re: Show player rank while spectating
Reply With Quote #5

i need
show player (kills deaths) while spectating
(not in map k.d., need full stats kills and deaths

i know i want
get_user_stats(id, stats, body);
stats[0]
stats[1]
but i cant write script
__________________
Sorry for my bad english.
1ka is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-22-2016 , 12:24   Re: Show player rank while spectating
Reply With Quote #6

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_stringiEntity EV_SZ_classname "SpecHUDEntity" );
    
register_think"SpecHUDEntity" "SpecHUDThink" );
    
entity_set_floatiEntity EV_FL_nextthink get_gametime() + fRefreshInterval );
    
    
g_HUDSyncObj CreateHudSyncObj();
}

public 
SpecHUDThinkiEntity )
{
    new 
iAlivePlayers32 ] , iDeadPlayers32 ] , iAliveNum iDeadNum iAlivePlayer iDeadPlayer;
    new 
iRank iStats] , iBodyHits] , szName32 ] , bool:bRetrievedData;
    
    
entity_set_floatiEntity EV_FL_nextthink get_gametime() + fRefreshInterval );
    
    
get_playersiAlivePlayers iAliveNum "a" );
    
    if( !
iAliveNum )
        return
    
    
get_playersiDeadPlayers iDeadNum "bch" );
    
    if( !
iDeadNum )
        return    
    
    for ( new 
iAlive iAlive iAliveNum iAlive++ )
    {
        
iAlivePlayer iAlivePlayersiAlive ];
        
        
bRetrievedData false;
        
        for( new 
iDead iDead iDeadNum iDead++ )
        {
            
iDeadPlayer iDeadPlayersiDead ];
            
            if ( 
entity_get_intiDeadPlayer EV_INT_iuser2 ) == iAlivePlayer && entity_get_intiDeadPlayer EV_INT_iuser1 ) == FirstPersonView )
            {
                if ( 
bRetrievedData == false )
                {
                    
get_user_nameiAlivePlayer szName charsmaxszName ) );
                    
iRank get_user_statsiAlivePlayer iStats iBodyHits );
                    
bRetrievedData true;
                }
                
                
ClearSyncHudiDeadPlayer g_HUDSyncObj );
                
set_hudmessage255 255 255 , -1.0 0.25 , .holdtime=0.5 , .channel=-);
                
ShowSyncHudMsgiDeadPlayer g_HUDSyncObj "%s^nRank: %d^nKills: %d^nDeaths: %d" szName iRank iStats] , iStats] );
            }
        }
    }

__________________

Last edited by Bugsy; 10-22-2016 at 22:46.
Bugsy is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 00:16.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode