Raised This Month: $ Target: $400
 0% 

problem with the amount of players


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
OnePL
BANNED
Join Date: May 2012
Location: GB
Old 06-11-2014 , 13:25   problem with the amount of players
Reply With Quote #1

hi,

I used many ways to count the players on the server
Each of them wailed me

I way:
PHP Code:
GetPlayersNum(teamalive) {
    new 
iPlayers;
    for(new 
maxpl0i--) {
        if(!
is_user_connected(i)) continue;

        if(
get_user_team(i) == team && (is_user_alive(i) == alive || alive == 2)) iPlayers++;
    }
    return 
iPlayers;

II way:
PHP Code:
stock GetPlayersNum(teamalive) {
    if(!(
<= team <= 2)) return 0;

    static 
Players[33], num;
    for(new 
1<= maxpli++) {
        if(
get_user_team(i) != team || is_user_alive(i) != alive) continue;

        
Players[++num] = i;
    }
    return 
Players[num];

III way:
PHP Code:
stock GetPlayersNum(teamalive) {
    static 
players[32], numcount;
    
get_players(playersnumalive "ach" "ch");
    for(new 
inumi++)
        if(
get_user_team(players[i]) == teamcount++;

    return 
count;

IV way:
PHP Code:
stock GetPlayersNum(teamalive) {
    for(new 
num1<= maxpli++) {
        if(!
is_user_connected(i) || get_user_team(i) != team) continue;
        if(
alive && !is_user_alive(i)) continue;

        
num++;
    }
    return 
num;

V way:
PHP Code:
stock GetPlayersNum(teamalive) {
    static 
players[32], num;
    
get_players(playersnumalive "ach" "ch"team == "CT" "TERRORIST");
    return 
count;

maxpl = get_maxplayers()

stock is used every second (in task)
every stock working at 90%
10% - sometimes bad counts, for example, when 2 terrorists it shows 7

Last edited by OnePL; 06-11-2014 at 13:26.
OnePL is offline
Send a message via ICQ to OnePL Send a message via AIM to OnePL Send a message via Yahoo to OnePL Send a message via Skype™ to OnePL
ironskillz1
AlliedModders Donor
Join Date: Jul 2012
Location: Sweden
Old 06-11-2014 , 13:47   Re: problem with the amount of players
Reply With Quote #2

You can try this. https://forums.alliedmods.net/showthread.php?p=1297719

It fixed my problems when i had an jailbreak server
__________________
I have many private and unique plugins for Jailbreak and Hide'N'Seek. PM me for more info.

Pm me.

Check out my roulette site.
ironskillz1 is offline
Send a message via Skype™ to ironskillz1
OnePL
BANNED
Join Date: May 2012
Location: GB
Old 06-11-2014 , 14:11   Re: problem with the amount of players
Reply With Quote #3

This fix was not implemented in 1.8.2 & 1.8.3?
OnePL is offline
Send a message via ICQ to OnePL Send a message via AIM to OnePL Send a message via Yahoo to OnePL Send a message via Skype™ to OnePL
SpeeDeeR
Veteran Member
Join Date: Mar 2010
Location: Bulgaria
Old 06-11-2014 , 14:18   Re: problem with the amount of players
Reply With Quote #4

get_players(iPlayers, iNum, "ch");
iNum returns the number of players related to the flags passed. There is no need to make a separate function.

Last edited by SpeeDeeR; 06-11-2014 at 14:18.
SpeeDeeR is offline
ironskillz1
AlliedModders Donor
Join Date: Jul 2012
Location: Sweden
Old 06-11-2014 , 14:19   Re: problem with the amount of players
Reply With Quote #5

Quote:
Originally Posted by OnePL View Post
This fix was not implemented in 1.8.2 & 1.8.3?
I dont think so. Maybe an person with more knowledge can answer that
__________________
I have many private and unique plugins for Jailbreak and Hide'N'Seek. PM me for more info.

Pm me.

Check out my roulette site.
ironskillz1 is offline
Send a message via Skype™ to ironskillz1
OnePL
BANNED
Join Date: May 2012
Location: GB
Old 06-11-2014 , 15:15   Re: problem with the amount of players
Reply With Quote #6

Quote:
Originally Posted by SpeeDeeR View Post
get_players(iPlayers, iNum, "ch");
iNum returns the number of players related to the flags passed. There is no need to make a separate function.
check V way in first post
OnePL is offline
Send a message via ICQ to OnePL Send a message via AIM to OnePL Send a message via Yahoo to OnePL Send a message via Skype™ to OnePL
SpeeDeeR
Veteran Member
Join Date: Mar 2010
Location: Bulgaria
Old 06-11-2014 , 15:48   Re: problem with the amount of players
Reply With Quote #7

I checked it. You are returning 'count' and you have to return 'num', idk what 'count' is, it isn't even defined.
SpeeDeeR is offline
OnePL
BANNED
Join Date: May 2012
Location: GB
Old 06-11-2014 , 16:26   Re: problem with the amount of players
Reply With Quote #8

mistake when copying
OnePL is offline
Send a message via ICQ to OnePL Send a message via AIM to OnePL Send a message via Yahoo to OnePL Send a message via Skype™ to OnePL
OnePL
BANNED
Join Date: May 2012
Location: GB
Old 06-11-2014 , 20:29   Re: problem with the amount of players
Reply With Quote #9

get_user_team fix by ConnorMcLeod not solved the problem
OnePL is offline
Send a message via ICQ to OnePL Send a message via AIM to OnePL Send a message via Yahoo to OnePL Send a message via Skype™ to OnePL
Nextra
Veteran Member
Join Date: Apr 2008
Location: Germany
Old 06-12-2014 , 05:48   Re: problem with the amount of players
Reply With Quote #10

PHP Code:
stock GetPlayersNum(teamalive) {
    static 
players[32], numcount;
    
get_players(playersnumalive "ach" "ch");
    for(new 
inumi++)
        if(
get_user_team(players[i]) == teamcount++;

    return 
count;

Using static variables in this way is completely wrong. First and foremost it is pointless premature optimization and secondly it will guarantee that this function will return the wrong result. The count variable is incremented every time this function is called and never reset to zero, so this code will not work.

PHP Code:
stock GetPlayersNum(teamalive) {
    if(!(
<= team <= 2)) return 0;

    static 
Players[33], num;
    for(new 
1<= maxpli++) {
        if(
get_user_team(i) != team || is_user_alive(i) != alive) continue;

        
Players[++num] = i;
    }
    return 
Players[num];

This is obviously wrong. It will return the highest index that is connected and in the specified team instead of the actual player count. You should return num and remove the Players array entirely. Also you use a static variable again which will break this code. You can't have tested this for long because this function will quickly fail with index out of bounds errors as you try to access the Players array beyond the valid 32 index.

PHP Code:
stock GetPlayersNum(teamalive) {
    for(new 
num1<= maxpli++) {
        if(!
is_user_connected(i) || get_user_team(i) != team) continue;
        if(
alive && !is_user_alive(i)) continue;

        
num++;
    }
    return 
num;

This is wrong and I would be very surprised if you even managed to compile this. You can't return num here because it has only been defined inside the for loop.

PHP Code:
stock GetPlayersNum(teamalive) {
    static 
players[32], num;
    
get_players(playersnumalive "ach" "ch"team == "CT" "TERRORIST");
    return 
count;

This doesn't compile, count is never defined.

PHP Code:
GetPlayersNum(teamalive) {
    new 
iPlayers;
    for(new 
maxpl0i--) {
        if(!
is_user_connected(i)) continue;

        if(
get_user_team(i) == team && (is_user_alive(i) == alive || alive == 2)) iPlayers++;
    }
    return 
iPlayers;

This is the only function that looks correct at a first glance. I might have missed something or you haven't actually tested the function in this version, maybe you recreated it from memory and did something different.

I would recommend working off this version and trying it again. I can't believe that this simple function should fail so frequently, so I don't think any bug in get_user_team is responsible. The bugs in get_user_team (that have now been fixed in 1.8.3 anyway) were only exhibited in some specific edge cases, nothing that would fail 1/10 times when run every second.
__________________
In Flames we trust!

Last edited by Nextra; 06-12-2014 at 05:52.
Nextra 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:38.


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