This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

Choosing a random player


Post New Thread Reply   
 
Thread Tools Display Modes
bigdaddy424
Senior Member
Join Date: Oct 2021
Location: Jupiter
Old 04-16-2024 , 20:13   Re: Choosing a random player
Reply With Quote #11

Quote:
Originally Posted by WATCH_D0GS UNITED View Post
random() will select a random value from 0 to the specified max value.

random(7) -> {0,1,2,3,4,5,6,7}

which sometimes, will lead to this:

PHP Code:
iRandom iPlayers 
Valid client entity indexes are from 1 to 32.

As an additional note, there are two more issues which are related to the use of get_players() native which we will not point out here,
but we are pretty sure that if someone knows how entity index slots works in the game this person will understand why.
youre totally confused and try to not lose it lol
__________________
bigdaddy424 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-16-2024 , 20:36   Re: Choosing a random player
Reply With Quote #12

Quote:
Originally Posted by WATCH_D0GS UNITED View Post
random() will select a random value from 0 to the specified max value.

random(7) -> {0,1,2,3,4,5,6,7}
No, random(7) = {0,1,2,3,4,5,6}

Quote:
Originally Posted by WATCH_D0GS UNITED View Post
which sometimes, will lead to this:

iRandom = iPlayers [ 0 ]

Valid client entity indexes are from 1 to 32.
This is fine as you are not using the random number as the player index, you are using it as an index to the iPlayers array, which get_players() fills with all valid player id's.. The iPlayers[ 0 ] slot will contain a valid player id if iNum is > 0.
Quote:
Originally Posted by WATCH_D0GS UNITED View Post
As an additional note, there are two more issues which are related to the use of get_players() native which we will not point out here,
but we are pretty sure that if someone knows how entity index slots works in the game this person will understand why.
There is no issues with the code I posted above to get a random player.

Please don't try to help others if you are not confident in what you are saying.
__________________

Last edited by Bugsy; 04-16-2024 at 20:37.
Bugsy is offline
tedaimlocks
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
mlibre
Veteran Member
Join Date: Nov 2015
Location: return PLUGIN_CONTINUE
Old 04-17-2024 , 10:40   Re: Choosing a random player
Reply With Quote #14

Quote:
Optional list of filtering flags:

"a" - do not include dead clients
"b" - do not include alive clients
"c" - do not include bots
"d" - do not include human clients
"e" - match with team
"f" - match with part of name
"g" - match case insensitive
"h" - do not include HLTV proxies
"i" - include connecting clients
Code:
span style="color: #cf0020;">// Choose a random player every round and give them the stuff under "ac")         //...
}
__________________
mlibre is offline
tedaimlocks
Member
Join Date: Jan 2024
Old 04-17-2024 , 10:50   Re: Choosing a random player
Reply With Quote #15

Quote:
Originally Posted by mlibre View Post
Code:
span style="color: #cf0020;">// Choose a random player every round and give them the stuff under "ac")         //...
}
Working ty, edit : may anyone help adding +2 multijumps for the randomly chosen player?

Last edited by tedaimlocks; 04-17-2024 at 10:51.
tedaimlocks is offline
mlibre
Veteran Member
Join Date: Nov 2015
Location: return PLUGIN_CONTINUE
Old 04-17-2024 , 19:12   Re: Choosing a random player
Reply With Quote #16

clear and what else
__________________
mlibre is offline
WATCH_D0GS UNITED
Senior Member
Join Date: Jan 2023
Old 04-17-2024 , 20:43   Re: Choosing a random player
Reply With Quote #17

Quote:
Originally Posted by bigdaddy424 View Post
youre totally confused and try to not lose it lol
��Useless.

Is this what you have to say for those who a day tried to help you optimize your content in something?

Now that we know what kind of person you are, we will no more give feedback to you in anything or suggest your content to someone.

Also, you are confused:

Quote:
Originally Posted by bigdaddy424 View Post
you can get a random player like this
Code:
new id, players = get_playersnum()
if (players)
	id = random(1, players)
PHP Code:
error 088: number of arguments does not match definition 
Keep trying to catch gun sounds in FM_EmitSound like many Veteran members suggested in this forum



Quote:
Originally Posted by Bugsy View Post
No, random(7) = {0,1,2,3,4,5,6}

Quote:
Originally Posted by Bugsy View Post

This is fine as you are not using the random number as the player index, you are using it as an index to the iPlayers array, which get_players() fills with all valid player id's.. The iPlayers[ 0 ] slot will contain a valid player id if iNum is > 0.
Thanks for the explanation.

We now understand that iPlayers[ 0 ] will hold a value of a valid client index, not the cell index value itself.
This should also be better documented in the API page.

Quote:
Originally Posted by Bugsy View Post
Please don't try to help others if you are not confident in what you are saying.
We had absolutely no doubt of what we were talking about.

What was said is partially correct, it becomes an exception only in this specific case.

Quote:
Originally Posted by mlibre View Post
in get_players does not apply, in get_maxplayers yes!
��Thanks mate.
__________________
💻Know Our New Blog👄
🔗tube2downs.blogspot.com

Last edited by WATCH_D0GS UNITED; 04-17-2024 at 20:57. Reason: EXCLUSIVE upper bound
WATCH_D0GS UNITED is offline
tedaimlocks
Member
Join Date: Jan 2024
Old 04-18-2024 , 00:58   Re: Choosing a random player
Reply With Quote #18

Quote:
Originally Posted by mlibre View Post
clear and what else
Nothing else, just that
tedaimlocks is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 04-18-2024 , 02:23   Re: Choosing a random player
Reply With Quote #19

@WATCH_D0GS UNITED, who is WE ?
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
WATCH_D0GS UNITED
Senior Member
Join Date: Jan 2023
Old 04-18-2024 , 06:56   Re: Choosing a random player
Reply With Quote #20

Quote:
Originally Posted by Natsheh View Post
@WATCH_D0GS UNITED, who is WE ?
You are not expecting for us to give you full real names in this kind of site full of admin-only psychopaths, you are?
__________________
💻Know Our New Blog👄
🔗tube2downs.blogspot.com
WATCH_D0GS UNITED 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 17:03.


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