AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Show player rank while spectating (https://forums.alliedmods.net/showthread.php?t=278625)

newb1e 02-04-2016 14:25

Show player rank while spectating
 
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



Kakarot47 02-04-2016 16:49

Re: Show player rank while spectating
 
Show full code

Croxeye 02-04-2016 17:01

Re: Show player rank while spectating
 
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


newb1e 02-04-2016 18:18

Re: Show player rank while spectating
 
Quote:

Originally Posted by Croxeye (Post 2390130)
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

1ka 10-22-2016 09:18

Re: Show player rank while spectating
 
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

Bugsy 10-22-2016 12:24

Re: Show player rank while spectating
 
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] );
            }
        }
    }




All times are GMT -4. The time now is 09:29.

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