AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   max clients and xxx% of... (https://forums.alliedmods.net/showthread.php?t=117657)

One 02-03-2010 10:04

max clients and xxx% of...
 
hi.

how can i get xx% of maxclients?

for example 12 users are on server and i want to catch if are 50% of this 12 users alive.
i think there was anything like this with the same question but i'm still searching around 15 min. and i cant find it :(

Seta00 02-03-2010 10:09

Re: max clients and xxx% of...
 
Try this:
PHP Code:

new maxplayers get_maxplayers(), alivePlayers;
for (new 
1maxplayers; ++i) {
    if (
is_user_alive(i))
        
alivePlayers++;
}

new 
percentage alivePlayers / (maxplayers/100); 


ehha 02-03-2010 10:11

Re: max clients and xxx% of...
 
counter = 0;
loop from 0 to maxplayers-1{
is_alive(x) counter++;
}

then get_playersnum() & do the math

edit: damn, Seta00 was faster :P
but he's made some mistakes:
-for should start from 0
-maxplayers should be get_playersnum() in percentage calculation

Owyn 02-03-2010 10:50

Re: max clients and xxx% of...
 
he has not, but you has :P

Exolent[jNr] 02-03-2010 11:10

Re: max clients and xxx% of...
 
Why do so many people not know how to loop through all players using get_maxplayers()?

Code:
new g_iMaxPlayers; public plugin_init( ) {     g_iMaxPlayers = get_maxplayers( ); } // ... for( new iPlayer = 1; iPlayer <= g_iMaxPlayers; iPlayer++ ) {     // player index -> iPlayer }

ehha 02-03-2010 11:26

Re: max clients and xxx% of...
 
My bad, I'm used to things starting from 0 to max-1 :(

fysiks 02-03-2010 13:36

Re: max clients and xxx% of...
 
Quote:

Originally Posted by ehha (Post 1077235)
My bad, I'm used to things starting from 0 to max-1 :(

You have to consider your context. 0 is worldspawn. 1 is the first player slot.

One 02-03-2010 14:44

Re: max clients and xxx% of...
 
ty guys :P


All times are GMT -4. The time now is 07:22.

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