Raised This Month: $12 Target: $400
 3% 

get_players() returning wrong value


Post New Thread Reply   
 
Thread Tools Display Modes
Natsheh
Veteran Member
Join Date: Sep 2012
Old 10-17-2017 , 19:16   Re: get_players() returning wrong value
Reply With Quote #21

Check out post #10
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 10-17-2017 , 20:28   Re: get_players() returning wrong value
Reply With Quote #22

Quote:
Originally Posted by EFFx View Post
Forget about the code's sense....
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 10-17-2017 , 20:32   Re: get_players() returning wrong value
Reply With Quote #23

You have 1 player on the server:
EFFx in CT team.
So, get_players in CheckSpec will return 1 player - EFFx.
get_players in kickRandomSpec will return 0 players, because you are in CT team, not in SPEC.
kickRandomSpec is called from the loop inside CheckSpec (there is a check for team number if(1 <= get_user_team(iPlayers[i]) <= 2), CT is 2, so check is passed).
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 10-17-2017 , 20:37   Re: get_players() returning wrong value
Reply With Quote #24

Ah I got it, but the if(1 <= get_user_team(iPlayers[i]) <= 2) check is a reason to kick a spec, like, if there's 4 players on X team and 5 in the other, it should kick a random spec.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 10-17-2017 at 20:38.
EFFx is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-17-2017 , 21:34   Re: get_players() returning wrong value
Reply With Quote #25

Quote:
Originally Posted by PRoSToTeM@ View Post
It produces raw random value (from 0 to 2^31-1) for random(0).
That's a bug that should be fixed.
__________________
fysiks is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 10-17-2017 , 22:31   Re: get_players() returning wrong value
Reply With Quote #26

Quote:
Originally Posted by fysiks View Post
That's a bug that should be fixed.
I think it is defined behaviour: https://github.com/alliedmodders/amx....cpp#L451-L452. So, documentation should be fixed.
What is your suggestion? Producing an error? I think error should be produced only for negative numbers, behaviour for 0 should stay the same.
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-17-2017 , 23:25   Re: get_players() returning wrong value
Reply With Quote #27

Quote:
Originally Posted by PRoSToTeM@ View Post
I think it is defined behaviour: https://github.com/alliedmodders/amx....cpp#L451-L452. So, documentation should be fixed.
What is your suggestion? Producing an error? I think error should be produced only for negative numbers, behaviour for 0 should stay the same.
If I were to guess what a function called "random" would return when supplied zero, I would expect zero. From the underlying code, I understand why it does what it does but from a common sense point of view (when used in context) it's seems wrong.

Ideally, I would say that a function called "random" should never manipulate 'result' at all and shouldn't take any arguments. However, obviously, that can't be done. Similarly, changing as I stated above is probably not the best either due to backwards compatibility.

In summary, the best solution here, unfortunately, is updating the documentation.
__________________
fysiks is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 10-18-2017 , 01:10   Re: get_players() returning wrong value
Reply With Quote #28

Quote:
Originally Posted by fysiks View Post
If I were to guess what a function called "random" would return when supplied zero, I would expect zero. From the underlying code, I understand why it does what it does but from a common sense point of view (when used in context) it's seems wrong.
random(X) is returning value from 0 to X-1, if X=0 then we should get value from 0 to -1, but there are no integer numbers between 0 and -1.
Quote:
Originally Posted by fysiks View Post
Ideally, I would say that a function called "random" should never manipulate 'result' at all and shouldn't take any arguments. However, obviously, that can't be done. Similarly, changing as I stated above is probably not the best either due to backwards compatibility.
Are you talking about C/C++ rand? random(0) is the same as rand(). We can add a default value for random argument.

Also, you should never use random(0)%X instead of random_num(0, X-1), because with random(0)%X you won't get uniform distribution (rand in C/C++ has the same problem). And unfortunately random(X) also has this problem.
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-18-2017 , 09:07   Re: get_players() returning wrong value
Reply With Quote #29

Quote:
Originally Posted by PRoSToTeM@ View Post
random(X) is returning value from 0 to X-1, if X=0 then we should get value from 0 to -1, but there are no integer numbers between 0 and -1.
I understand the math. I'm talking about common sense usage of the function.

Quote:
Originally Posted by PRoSToTeM@ View Post
Also, you should never use random(0)%X instead of random_num(0, X-1), because with random(0)%X you won't get uniform distribution (rand in C/C++ has the same problem). And unfortunately random(X) also has this problem.
Yeah, I was thinking about that too.

Regardless, to maintain backward compatibility, the only thing that can be done is to document the behavior.
__________________
fysiks is offline
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 08:42.


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