AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
|
10-31-2016
, 23:42
Re: Compensation [v0.1]
|
#2
|
See my comments and spoiler below.
PHP Code:
public GiveCompensation( iDeadPlayer ) { //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_num( g_pPluginEnable ) ) return PLUGIN_HANDLED
new iPlayers[ 32 ] , iNumPlayers , iRandom , iMoneyBonus new szCompensateName[ 32 ] , szDeadName[ 32 ] , 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_players( iPlayers , 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 > 1 ) { //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 i = 0 ; i < iNumPlayers ; i++ ) { //With get_players() using opposite team, you can set the player id directly here: iCompensate = ... iRandom = iPlayers[ random( iNumPlayers ) ] //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_team( iRandom ) != cs_get_user_team( iDeadPlayer ) ) ) { if ( HaveAnTeam( iRandom ) ) { iCompensatePlayer = iRandom break } } } iMoneyBonus = get_pcvar_num( g_pBonusMoney ) get_user_name( iCompensatePlayer , szCompensateName , charsmax( szCompensateName ) ) get_user_name( iDeadPlayer , szDeadName , charsmax( szDeadName ) ) cs_set_user_money( iCompensatePlayer , cs_get_user_money( iCompensatePlayer ) + iMoneyBonus ) for ( new i = 0 ; i < iNumPlayers ; i++ ) { //With get_players() using opposite team, you do not need any team checking. if ( ( iPlayers[ i ] != iCompensatePlayer ) && ( cs_get_user_team( iRandom ) == cs_get_user_team ( iPlayers[ i ] ) ) ) { client_print_color( iPlayers[ i ] , GREY , "%s Your teammate %s was awarded^x04 +$%d^x01 compensation for the suicide of %s" , szPrefix , szCompensateName , iMoneyBonus , szDeadName ) } } } return PLUGIN_CONTINUE }
Spoiler
PHP Code:
public client_disconnect(id) { if ( get_pcvar_num( g_pPluginEnable ) && HaveAnTeam( id ) ) { GiveCompensation( id ) } }
public Event_DeathMsg() { if ( get_pcvar_num( g_pPluginEnable ) ) { new iKiller = read_data( 1 ) new iVictim = read_data( 2 ) if ( ( iKiller == iVictim ) && ( HaveAnTeam( iKiller ) ) ) { GiveCompensation( iVictim ) } } }
public GiveCompensation( iDeadPlayer ) { new iPlayers[ 32 ] , iNumPlayers , iMoneyBonus new szCompensateName[ 32 ] , szDeadName[ 32 ] , iCompensatePlayer new const szOppositeTeams[ CsTeams ][] = { "" , "CT" , "TERRORIST" , "" }; get_players( iPlayers , iNumPlayers , "eh" , szOppositeTeams[ cs_get_user_team( iDeadPlayer ) ] ) if ( iNumPlayers ) { iCompensatePlayer = iPlayers[ random( iNumPlayers ) ] iMoneyBonus = get_pcvar_num( g_pBonusMoney ) get_user_name( iCompensatePlayer , szCompensateName , charsmax( szCompensateName ) ) get_user_name( iDeadPlayer , szDeadName , charsmax( szDeadName ) ) cs_set_user_money( iCompensatePlayer , cs_get_user_money( iCompensatePlayer ) + iMoneyBonus ) for ( new i = 0 ; i < iNumPlayers ; i++ ) { if ( iPlayers[ i ] != iCompensatePlayer ) { client_print_color( iPlayers[ i ] , GREY , "%s Your teammate %s was awarded^x04 +$%d^x01 compensation for the suicide of %s" , szPrefix , szCompensateName , iMoneyBonus , szDeadName ) } } } }
__________________
Last edited by Bugsy; 10-31-2016 at 23:50.
|
|