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

Voting: pick random options from the tied options


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kNowo
Senior Member
Join Date: Apr 2011
Location: Malaysia
Old 07-27-2013 , 13:10   Voting: pick random options from the tied options
Reply With Quote #1

Let's say 4 options from the vote has the most vote. How do I pick a random one from the 4?
I'm going to post default amxx mapchooser as an example.

Spoiler


This is the function where the votes are calculated in the above code
PHP Code:
public checkVotes()
{
    new 
0
    
    
for (new 0g_mapVoteNum; ++a)
        if (
g_voteCount[b] < g_voteCount[a])
            
a
... 

Last edited by kNowo; 07-27-2013 at 13:10.
kNowo is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 07-27-2013 , 13:17   Re: Voting: pick random options from the tied options
Reply With Quote #2

PHP Code:
public checkVotes()
{
    new 
0
    
    
for (new 0g_mapVoteNum; ++a)
        if (
g_voteCount[b] < g_voteCount[a])
            
a

        
else if (g_voteCount[b] > g_voteCount[a])
            
b

        
else random_num(a,b
</span></span>
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
Old 07-27-2013, 13:20
UchihaSkills
This message has been deleted by UchihaSkills.
UchihaSkills
Senior Member
Join Date: May 2013
Location: Germany
Old 07-27-2013 , 13:26   Re: Voting: pick random options from the tied options
Reply With Quote #3

add this Line
PHP Code:
 else random_num(g_voteCount[a], g_voteCount[b]) 
UchihaSkills is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 07-27-2013 , 14:45   Re: Voting: pick random options from the tied options
Reply With Quote #4

The list of all ties are going to be contained in the array aTies. iWinner is the index of either the winning option or of the randomly chosen option of the ties.

PHP Code:
public CountVotes()
{
    new Array:
aTies ArrayCreate();

    new 
iMax;

    for( new 
0sizeofg_voteCount ); i++ )
    {
        if( 
g_voteCount] > g_voteCountiMax ] )
        {
            
ArrayClearaTies );
            
ArrayPushCellaTies);
            
iMax i;
        }
        
        else if( 
g_voteCount] == g_voteCountiMax ] )
        {
            
ArrayPushCellaTies);
        }
    }

    new 
iWinner randomArraySizeaTies ) );


__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please

Last edited by nikhilgupta345; 07-28-2013 at 12:46.
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
kNowo
Senior Member
Join Date: Apr 2011
Location: Malaysia
Old 07-27-2013 , 15:30   Re: Voting: pick random options from the tied options
Reply With Quote #5

Quote:
Originally Posted by nikhilgupta345 View Post
The list of all ties are going to be contained in the array aTies. iWinner is the index of either the winning option or of the randomly chosen option of the ties.

PHP Code:
public CountVotes()
{
    new Array:
aTies;

    new 
iMax;

    for( new 
0sizeofg_voteCount ); i++ )
    {
        if( 
g_voteCount] > g_voteCountiMax ] )
        {
            
ArrayClearaTies );
            
ArrayPushCellaTies);
            
iMax i;
        }
        
        else if( 
g_voteCount] == g_voteCountiMax ] )
        {
            
ArrayPushCellaTies);
        }
    }

    new 
iWinner randomArraySizeaTies ) );


It compiles fine but I get an "Invalid array handle provided(0)" error on line ArrayPushCell( aTies, i );

Last edited by kNowo; 07-27-2013 at 16:04.
kNowo is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 07-28-2013 , 12:46   Re: Voting: pick random options from the tied options
Reply With Quote #6

Quote:
Originally Posted by kNowo View Post
It compiles fine but I get an "Invalid array handle provided(0)" error on line ArrayPushCell( aTies, i );
Sorry about that, fixed.
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
kNowo
Senior Member
Join Date: Apr 2011
Location: Malaysia
Old 07-29-2013 , 08:24   Re: Voting: pick random options from the tied options
Reply With Quote #7

Quote:
Originally Posted by nikhilgupta345 View Post
Sorry about that, fixed.
Thanks I figured it out after I posted the above post,

btw, this
Code:
new iWinner = random( ArraySize( aTies ) );

should be this
Code:
new iWinner = ArrayGetCell(iTies, random( ArraySize( aTies ) ));
kNowo is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 07-29-2013 , 18:46   Re: Voting: pick random options from the tied options
Reply With Quote #8

Quote:
Originally Posted by kNowo View Post
Thanks I figured it out after I posted the above post,

btw, this
Code:
new iWinner = random( ArraySize( aTies ) );

should be this
Code:
new iWinner = ArrayGetCell(iTies, random( ArraySize( aTies ) ));
Yup, sorry again
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please

Last edited by nikhilgupta345; 07-29-2013 at 18:46.
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
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 03:02.


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