Raised This Month: $ Target: $400
 0% 

problem with the amount of players


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 



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