View Single Post
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-31-2016 , 23:42   Re: Compensation [v0.1]
Reply With Quote #2

See my comments and spoiler below.
PHP Code:
public GiveCompensationiDeadPlayer 

    
//This should be placed on top of Event_DeathMsg and client_disconnect(). This would result in only 1 native call
    //if it was disabled instead of 2 (disconnect) to 4 (deathmsg) the way you have it now. 
    
if ( !get_pcvar_numg_pPluginEnable ) )
        return 
PLUGIN_HANDLED

    
new iPlayers32 ] , iNumPlayers iRandom iMoneyBonus 
    
new szCompensateName32 ] , szDeadName32 ] , iCompensatePlayer 
    
    
//Better off passing the opposite team in get_players(). It will save you multiple cs_get_user_team() native calls.
    //In addition, you can eliminate other condition checking (see below).
    
get_playersiPlayers iNumPlayers "h" 
    
    
//This is not needed since it was my assumption that the money was for iDeadPlayers teammates. This is why
    //it checks for > 1 since there must be a player on his team besides himself. This can be changed to > 0.
    
if ( iNumPlayers 
    {     
        
//This loop is not needed since random() will always get a compensate player. Previously, I thought it was to 
        //compensate teammates so it needed to check randoms until it found one that was != dead player.
        
for ( new iNumPlayers i++ ) 
        { 
            
//With get_players() using opposite team, you can set the player id directly here: iCompensate = ...
            
iRandom iPlayersrandomiNumPlayers ) ] 
            
            
//With get_players() using opposite team, you do not need to check if random != dead player and you do 
            //not need any team checking.
            
if ( ( iRandom != iDeadPlayer ) && ( cs_get_user_teamiRandom ) != cs_get_user_teamiDeadPlayer ) ) )
            { 
                if ( 
HaveAnTeamiRandom ) )
                {
                    
iCompensatePlayer iRandom 
                    
break 
                }
            } 
        } 
        
        
iMoneyBonus get_pcvar_numg_pBonusMoney 
        
        
get_user_nameiCompensatePlayer szCompensateName charsmaxszCompensateName ) ) 
        
get_user_nameiDeadPlayer szDeadName charsmaxszDeadName ) ) 
        
        
cs_set_user_moneyiCompensatePlayer cs_get_user_moneyiCompensatePlayer ) + iMoneyBonus 
        
        for ( new 
iNumPlayers i++ ) 
        { 
            
//With get_players() using opposite team, you do not need any team checking.
            
if ( ( iPlayers] != iCompensatePlayer ) && ( cs_get_user_teamiRandom ) == cs_get_user_team iPlayers] ) ) )
            { 
                
client_print_coloriPlayers] , GREY "%s Your teammate %s was awarded^x04 +$%d^x01 compensation for the suicide of %s" szPrefix szCompensateName iMoneyBonus szDeadName 
            } 
        } 
    } 
    return 
PLUGIN_CONTINUE

Spoiler
__________________

Last edited by Bugsy; 10-31-2016 at 23:50.
Bugsy is offline