Raised This Month: $ Target: $400
 0% 

[code] infinity loop


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
JusTGo
Veteran Member
Join Date: Mar 2013
Old 12-30-2015 , 06:03   Re: [code] infinity loop
Reply With Quote #1

Quote:
Originally Posted by addons_zz View Post
Yes. Nice work.


Do not mix the min and max ids with player team. Why do you checked if the player was alive? Dead players do not have team?
If the player was not connect, he would not be selected because every time he disconnect/connect he is added/removed from the selection.



I attached the full code.
ty again, i need the played to be alive && ct same time cause he can be in ct team and his dead so i used:
Code:
GetRandomPlayer() {     //No players(alive && ct) or all have been selected already     if( !g_Players || !GetAliveCt()         /*|| ( g_Players == g_Selected )*/ ) // so it will not return 0 when all players selected selected.     {         return 0;     }         new iRandomID;         //Keep looping while there is players that haven't yet been selected.     while( g_Players != g_Selected )     {         //Get random player id         iRandomID = random_num( g_Min, g_Max );                 //If player is connected and has not yet been selected         if( ( g_Players & ( 1 << iRandomID ) )             && !( g_Selected & ( 1 << iRandomID ) ) )         {             //Set bit for this ID in g_Selected bit-field so the player will now be considered selected             g_Selected |= ( 1 << iRandomID );                         if( is_user_alive( iRandomID + 1 ) && cs_get_user_team( iRandomID + 1 ) == CS_TEAM_CT )             {                 return ( iRandomID + 1 );             }             else             {                 return GetRandomPlayer()             }         }     }         //All players have already been selected.     /*if( g_Players == g_Selected )*/ // no need for this check the while loop will already do that for us.     return -1; // making this -1 so we now we will know when all players are selected } GetAliveCt() {     new iCt, id         for (id = 1; id <= g_MaxPlayers; id++)     {         if (is_user_alive( id ) && cs_get_user_team( id ) == CS_TEAM_CT)             iCt++     }         return iCt; }

its working perfect now but just some small issuses like for ex:
you call radom 3 times it gives you: 7 3 1 the you call it another time it gives your 7 3 1 its rare but happens or other thing for ex you get: 7 3 1 next time you do random you get 1 7 3 so you have the number 1 selected twice in a row but i guess thats how random_num() works.

edit:
https://forums.alliedmods.net/showpo...91&postcount=7
Code:
GetMaxMin( &iMin, &iMax ) {     for( new i = 0; i < g_MaxPlayers; i++ )     {         if( g_Players & ( 1 << i ) )         {             if( i < iMin )             {                 iMin = i;             }                         if( i > iMax )             {                 iMax = i;             }         }     } }

is this okay ?
__________________

Last edited by JusTGo; 12-30-2015 at 06:05.
JusTGo is offline
Old 12-30-2015, 07:39
addons_zz
This message has been deleted by addons_zz. Reason: fix erros
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 17:57.


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