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


Raised This Month: $ Target: $400
 0% 

Player count.


Post New Thread Reply   
 
Thread Tools Display Modes
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-15-2012 , 17:04   Re: Player count.
Reply With Quote #11

Quote:
Originally Posted by Mucx View Post
Meanwhile i discovered this, but i have no clue what version is better.

PHP Code:
stock GetPlayersNumCsTeams:iTeam ) {
    new 
iNum;
    for( new 
1<= get_maxplayers( ); i++ ) {
        if( 
is_user_connected) && cs_get_user_team) == iTeam )
            
iNum++;
    }
    return 
iNum;

I would use this one for simplicity. The difference will likely be negligible to your server. However, there is one optimization that is needed:

PHP Code:
stock GetPlayersNumCsTeams:iTeam )
{
    new 
iNumiMaxPlayers get_maxplayers();
    for( new 
1<= iMaxPlayersi++ )
    {
        if( 
is_user_connected) && cs_get_user_team) == iTeam )
            
iNum++;
    }
    return 
iNum;

There is a way to optimize a little more but this should be fine.
__________________
fysiks is offline
makavelli
Senior Member
Join Date: Nov 2006
Location: Belgium
Old 01-16-2012 , 08:27   Re: Player count.
Reply With Quote #12

oh ok,
sry if my questions are annoying but its the only way i will really learn this stuff;
Got a few more questions:
PHP Code:
stock GetPlayersNumCsTeams:iTeam 

    new 
iNumiMaxPlayers get_maxplayers(); //what does this i stand for in this script is it just a string to store the playernumbers in?
     
for( new 1<= iMaxPlayersi++ ) //what does this outcome mean; i++?
    

        if( 
is_user_connected) && cs_get_user_team) == iTeam 
            
iNum++; // and what are the meanings of the ( i )'s in this line? and the inum++?
    

    return 
iNum

makavelli is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 01-16-2012 , 09:13   Re: Player count.
Reply With Quote #13

The i is a variable that holds the count of the loop.
The loop starts at 1, and increments i by 1 every time it loops.

PHP Code:
for(new 1iMaxPlayersi++)
{
    
// If player with index i is connected & in the right team
    
if(is_user_connected(i) && cs_get_user_team(i) == iTeam)
        
// Increment the player count var by 1
        
iNum++

    
// i get increments by 1.

So if for example iMaxPlayers is 4, the loop does this:
PHP Code:
1. if player 1 is connected in the right teamiNum (which is 0 here) + 1.
2. if player 2 is connected in the right teamiNum (which is 1 here) + 1.
3. if player 3 is not connected or not in the right team, do nothing.
4. if player 4 is connected in the right teamiNum (which is 2 here) + 1. 
So iNum now holds 3, the amount of players connected & in the right team.
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
makavelli
Senior Member
Join Date: Nov 2006
Location: Belgium
Old 01-16-2012 , 10:21   Re: Player count.
Reply With Quote #14

Quote:
Originally Posted by drekes View Post
PHP Code:
for(new 1iMaxPlayersi++)//--> but I cant find his condition for his iMaxPlayers or is that always the server's player slots? and why must there be an i before MaxPlayers?
{
    
// If player with index i is connected & in the right team
//1--> what do you mean by player with index i, what is index i with that player?
//1--->  lets say that he is player 1 that connects is i this then for him:
//1----> i = 1. if player 1 is connected & in the right team, iNum (which is 0 here) + 1.
//2-> the right team is Ter, does he have to repeat this code block again then for the ct and spec team?

    
if(is_user_connected(i) && cs_get_user_team(i) == iTeam)
        
// Increment the player count var by 1
//3-> && cs_get_user_team(i) == iTeam (this means: check if player is on ter team right? or: & in the right team ==(that equals) Ter.?
      
iNum++

    
// i get increments by 1.

So if for example iMaxPlayers is 4, the loop does this:
PHP Code:
1. if player 1 is connected in the right teamiNum (which is 0 here) + 1.
2. if player 2 is connected in the right teamiNum (which is 1 here) + 1.
3. if player 3 is not connected or not in the right team, do nothing.
4. if player 4 is connected in the right teamiNum (which is 2 here) + 1. 
So iNum now holds 3, the amount of players connected & in the right team.

Last edited by makavelli; 01-16-2012 at 10:22.
makavelli is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-16-2012 , 16:18   Re: Player count.
Reply With Quote #15

The "i" in iMaxPlayers is just part of the name. It doesn't change anything. It is just a method of reminding the people who read the code that the variable is an integer.
__________________
fysiks is offline
makavelli
Senior Member
Join Date: Nov 2006
Location: Belgium
Old 01-17-2012 , 08:52   Re: Player count.
Reply With Quote #16

Quote:
Originally Posted by fysiks View Post
The "i" in iMaxPlayers is just part of the name. It doesn't change anything. It is just a method of reminding the people who read the code that the variable is an integer.
oh ok does that count for everything starting with i.... in his script?
makavelli is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-17-2012 , 19:46   Re: Player count.
Reply With Quote #17

Quote:
Originally Posted by makavelli View Post
oh ok does that count for everything starting with i.... in his script?
It really depends on who is the author of the code because some people don't understand what it means and just put an "i" in front of all their variables.

In the case of this code (iNum, iMaxPlayers) they are being used as integers.
__________________
fysiks 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 09:36.


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