Raised This Month: $51 Target: $400
 12% 

Getting a name by frags


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
r14170
Veteran Member
Join Date: Dec 2009
Old 08-11-2011 , 18:32   Getting a name by frags
Reply With Quote #1

How do i get a name of the player who is with most frags?

EDIT: Move this to Scripting Help, my mistake.
r14170 is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 08-11-2011 , 18:51   Re: Getting a name by frags
Reply With Quote #2

Untested:
PHP Code:
GetHighestFraggerName(szName[], iLen)
{
    new 
iPlayers[32], iNumiPlayeriFragsiMostFragsiWinner;
    
get_players(iPlayersiNum);
    
    if(!
iNum)
        return 
0;
        
    for(new 
0iNumi++)
    {
        
iPlayer     iPlayers[i];
        
iFrags     get_user_frags(iPlayer);
        
        if(
iFrags iMostFrags)
        {
            
iMostFrags iFrags;
            
iWinner iPlayer;
        }
    }
    
    
get_user_name(iWinnerszNameiLen);
    return 
iWinner;

__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-11-2011 , 22:11   Re: Getting a name by frags
Reply With Quote #3

That code will work sometimes but if no one has yet scored you will get an error and if multiple players have the same score you will get an inaccurate result.

The below function will return accurate results based on all scenerios:
  • If one player has highest frags
  • If multiple players tied for having highest frags
  • If no one has any frags (frags > 0)
Results
Code:
bugsy has the most frags [ 1 frags ]

The following players tied for the most frags: bugsy,Kimbo Slice,Ricardo Almeida [ 1 frags ]

No players have any frags.
I made a little plugin to show how it works.
PHP Code:
#include <amxmodx>

new const Version[] = "0.1";

public 
plugin_init() 
{
    
register_plugin"Most Frags" Version "bugsy" );
    
    
register_clcmd"say /mostfrags" "MostFrags" );
}

public 
MostFragsid )
{
    new 
iPlayer iPlayers iFrags bool:bTie;
    
    if ( ( 
iPlayers GetMostFragsiPlayer iFrags bTie ) ) )
    {
        if ( 
bTie )
        {
            new 
szNames192 ] , iPos;
            for ( new 
id id <= 32 id++ )
            {
                if ( 
iPlayers & ( << ( id 31 ) ) )
                {
                    
iPos += get_user_nameid szNamesiPos ] , charsmaxszNames ) - iPos );
                    
szNamesiPos++ ] = ',';
                }
            }
            
szNamesiPos ] = EOS;
            
client_printid print_chat "The following players tied for the most frags: %s [ %d frags ]" szNames iFrags );
            
            return;
        }
        
        new 
szName33 ];
        
get_user_nameiPlayer szName charsmaxszName ) );
        
client_printid print_chat "%s has the most frags [ %d frags ]" szName iFrags );
    }
    else
    {
        
client_printid print_chat "No players have any frags." );
    }
}

GetMostFrags( &iPlayer , &iFrags , &bool:bTie )
{
    new 
iPlayers32 ] , iNum iCurPlayer iTie;
    new 
iCurFrags iMostFrags iMostFragsPlayer;
    
get_playersiPlayers iNum );
    
    for ( new 
iNum i++ )
    {
        
iCurPlayer iPlayers];
        
        if ( ( 
iCurFrags get_user_fragsiCurPlayer ) ) > iMostFrags )        
        {
            
iMostFragsPlayer iCurPlayer;
            
iMostFrags iCurFrags;
            
iTie 0;
        }
        else if ( 
iCurFrags == iMostFrags )
        {
            
iTie |= ( << ( iCurPlayer 31 ) );
            
iTie |= ( << ( iMostFragsPlayer 31 ) );
        }
    }

    if ( 
iMostFrags <= )
        return 
0;
        
    if ( 
iTie )
    {
        
iPlayer 0;
        
iFrags iMostFrags;
        
bTie true;
        
        return 
iTie;
    }

    
iPlayer iMostFragsPlayer;
    
iFrags iMostFrags;
    
    return 
1;

__________________

Last edited by Bugsy; 08-12-2011 at 00:09.
Bugsy is offline
r14170
Veteran Member
Join Date: Dec 2009
Old 08-12-2011 , 07:03   Re: Getting a name by frags
Reply With Quote #4

Bugsy, thanks!
r14170 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 07:30.


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