AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Online Players >= (https://forums.alliedmods.net/showthread.php?t=295380)

LifeStone 03-24-2017 06:08

Online Players >=
 
Hello i want to make my plugin to work when is 5 or more players online and not only the alives what i cant write ?

klippy 03-24-2017 06:54

Re: Online Players >=
 
You can use get_playersnum()

CrazY. 03-24-2017 07:30

Re: Online Players >=
 
Or.. try that:

PHP Code:

if (get_alive_players() >= 5) {
   
// your code...l
}

get_alive_players()
{
   static 
aliveid;
   
alive 0;

   for (
id 1id <= get_maxplayers(); id++) {
        if (
is_user_alive(id))
            
alive++;
}

return 
alive;



klippy 03-24-2017 07:35

Re: Online Players >=
 
CrazY, they never asked for the number of alive players. Please read thoroughly before posting.

Also, as a side note, there's no reason to use static modifier as you assign values to these variables before using them anyway.

OciXCrom 03-24-2017 09:06

Re: Online Players >=
 
And there's definitely no need to loop through all players.

PHP Code:

new iPlayers[32], iPnum
get_players
(iPlayersiPnum"a")

// iPnum is the number of alive players. 


Natsheh 03-24-2017 09:33

Re: Online Players >=
 
Quote:

Originally Posted by OciXCrom (Post 2506307)
And there's definitely no need to loop through all players.

PHP Code:

new iPlayers[32], iPnum
get_players
(iPlayersiPnum)

// iPnum is the number of alive players. 


iPnum is the number of connected players
PHP Code:

new iPlayers[32], iPnum
get_players
(iPlayersiPnum"a"// now iPnum is equal to all the alive players.. 


CrazY. 03-24-2017 10:30

Re: Online Players >=
 
O.o

Yes sir. :attack:

And to get a random player ?

Natsheh 03-24-2017 11:00

Re: Online Players >=
 
PHP Code:

new players[32], pnum;
get_players(playerspnum"a");

if(!
pnum) return;

new 
random_chosen_id players[random(pnum-1)]

// random_chosen_id  var is the player id whom chosen randomly.. 

already been made just search..

EFFx 03-24-2017 13:22

Re: Online Players >=
 
Do not need the -1 Natsheh.

@LifeStone,

Use the native that KliPPy said.

PHP Code:

if(get_playersnum() >= 5)
{
     
// bla bla



Natsheh 03-24-2017 14:02

Re: Online Players >=
 
Quote:

Originally Posted by EFFx (Post 2506374)
Do not need the -1 Natsheh.

@LifeStone,

Use the native that KliPPy said.

PHP Code:

if(get_playersnum() >= 5)
{
     
// bla bla



Again that post was an answer for @CrazY. Question!


All times are GMT -4. The time now is 17:47.

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