View Single Post
tedaimlocks
Senior Member
Join Date: Jan 2024
Old 04-17-2024 , 09:27   Re: Choosing a random player
Reply With Quote #13

Quote:
Originally Posted by Bugsy View Post
PHP Code:
new iPlayers32 ] , iNum iRandom;
get_playersiPlayers iNum );

if ( 
iNum )
{
      
iRandom iPlayers randomiNum ) ];

Works ty, also quick question, i made this if no player is connected, dunno if its right though ( it works, i tested )
HTML Code:
public ChooseHero()
{
        new iPlayers[ 32 ] , iNum , iRandom;
        get_players( iPlayers , iNum );
        if ( iNum ) {
              iRandom = iPlayers [ random( iNum ) ];
        }
        else if ( !iNum ) {
              return PLUGIN_HANDLED;
        }
        set_user_armor(iRandom, get_user_armor(iRandom) + 150);
        set_user_health(iRandom, get_user_health(iRandom) + 150);
	give_item(iRandom, "weapon_hegrenade");
	give_item(iRandom, "weapon_flashbang");

	new szName[32];
	get_user_name(iRandom, szName, charsmax(szName));
        ColorChat(0, GREEN, "^x01[^x04SPK ZM^x01]^x04 %s ^x03was chosen to be the ^x04Hero ^x03of the round! They have got ^x04+150HP+150AP+MULTIJUMPS", szName);
}
edit : if i want to skip bots and dead players how should i do it?
edit 2 : i made a check to see if user is bot and if is dead but what should i return, or what should i do to choose another player?
HTML Code:
public ChooseHero()
{
        new iPlayers[ 32 ] , iNum , iRandom;
        get_players( iPlayers , iNum );
        if ( iNum ) {
              iRandom = iPlayers [ random( iNum ) ];
        }
        else if ( !iNum ) {
              return PLUGIN_HANDLED;
        }
        else if ( !is_user_alive (iRandom) || is_user_bot( iRandom )) {
              return;
        }
        set_user_armor(iRandom, get_user_armor(iRandom) + 150);
        set_user_health(iRandom, get_user_health(iRandom) + 150);
	give_item(iRandom, "weapon_hegrenade");
	give_item(iRandom, "weapon_flashbang");

	new szName[32];
	get_user_name(iRandom, szName, charsmax(szName));
        ColorChat(0, GREEN, "^x01[^x04SPK ZM^x01]^x04 %s ^x03was chosen to be the ^x04Hero ^x03of the round! They have got ^x04+150HP+150AP+MULTIJUMPS", szName);
}

Last edited by tedaimlocks; 04-17-2024 at 10:00.
tedaimlocks is offline