Raised This Month: $ Target: $400
 0% 

max clients and xxx% of...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
One
Veteran Member
Join Date: Oct 2008
Location: Hardstyle-eSports.de
Old 02-03-2010 , 10:04   max clients and xxx% of...
Reply With Quote #1

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
__________________
One is offline
Send a message via ICQ to One Send a message via AIM to One Send a message via MSN to One Send a message via Yahoo to One Send a message via Skype™ to One
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 02-03-2010 , 10:09   Re: max clients and xxx% of...
Reply With Quote #2

Try this:
PHP Code:
new maxplayers get_maxplayers(), alivePlayers;
for (new 
1maxplayers; ++i) {
    if (
is_user_alive(i))
        
alivePlayers++;
}

new 
percentage alivePlayers / (maxplayers/100); 
Seta00 is offline
ehha
SourceMod Donor
Join Date: Apr 2006
Location: Sibiu
Old 02-03-2010 , 10:11   Re: max clients and xxx% of...
Reply With Quote #3

counter = 0;
loop from 0 to maxplayers-1{
is_alive(x) counter++;
}

then get_playersnum() & do the math

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

Last edited by ehha; 02-03-2010 at 10:17.
ehha is offline
Owyn
Veteran Member
Join Date: Nov 2007
Old 02-03-2010 , 10:50   Re: max clients and xxx% of...
Reply With Quote #4

he has not, but you has
__________________
☜ Free Mozy ☂backup\҉sync user
Quote:
Американский форум - Задаёшь вопрос, потом тебе отвечают.
Израильский форум - Задаёшь вопрос, потом тебе задают вопрос.
Русский форум - Задаёшь вопрос, потом тебе долго рассказывают, какой ты мудак.
Owyn is offline
Send a message via ICQ to Owyn
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 02-03-2010 , 11:10   Re: max clients and xxx% of...
Reply With Quote #5

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 }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
ehha
SourceMod Donor
Join Date: Apr 2006
Location: Sibiu
Old 02-03-2010 , 11:26   Re: max clients and xxx% of...
Reply With Quote #6

My bad, I'm used to things starting from 0 to max-1
__________________
ehha is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-03-2010 , 13:36   Re: max clients and xxx% of...
Reply With Quote #7

Quote:
Originally Posted by ehha View Post
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.
__________________
fysiks is offline
One
Veteran Member
Join Date: Oct 2008
Location: Hardstyle-eSports.de
Old 02-03-2010 , 14:44   Re: max clients and xxx% of...
Reply With Quote #8

ty guys
__________________
One is offline
Send a message via ICQ to One Send a message via AIM to One Send a message via MSN to One Send a message via Yahoo to One Send a message via Skype™ to One
Reply


Thread Tools
Display Modes

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 07:22.


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