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

[HELP] Compare variables.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
monster321
Member
Join Date: Apr 2012
Old 04-11-2015 , 13:15   [HELP] Compare variables.
Reply With Quote #1

I'm working in a plugin with a special day votes, and i have a question about it. Example:

Code:
#include < amxmodx > #include < amxmisc > new vote_active, voteday[ 3 ]; // Init public plugin_init() {     // Register     register_plugin( "Compare variables", "1.0", "monster321" )         // Clcmd TEST     register_clcmd( "say test", "test_plugin" ) } // CMD TestPlugin public test_plugin( id ) {     if( !is_user_admin( id ) || vote_active )         return PLUGIN_HANDLED;         for( new i; i <= 32; i++ )     {         if( !is_user_connected( i ) )             continue;                     vote_menu( i )                 voteday[ 0 ] = 0;         voteday[ 1 ] = 0;         voteday[ 2 ] = 0;         vote_active = true;                 set_task( 15.0, "vote_end", i )     } } // Special day vote public vote_menu( id ) {     new menu = menu_create( "\wWhat you want to play?", "vote_handler" )         menu_additem( menu, "\ySpecial day 1", "1" )     menu_additem( menu, "\ySpecial day 2", "2" )     menu_additem( menu, "\ySpecial day 3", "3" )         menu_setprop( menu, MPROP_EXITNAME, "\wPrefer not vote" )         menu_display( id, menu, 0 ) } public vote_handler( id, menu, item ) {     if( item == MENU_EXIT )     {         menu_destroy( menu )         return PLUGIN_HANDLED;     }         if( !vote_active )         return PLUGIN_HANDLED;         new data[ 6 ], name[ 64 ], access, callback;     menu_item_getinfo( menu, item, access, data, 5, name, 63, callback )         switch( str_to_num( data ) )     {         case 1: voteday[ 0 ] ++;         case 2: voteday[ 1 ] ++;         case 3: voteday[ 2 ] ++;     }         menu_destroy( menu )     return PLUGIN_HANDLED; } public vote_end( id ) {     vote_active = false;     // I want get here the variable "voteday" with more votes to start the day.     // But I want this so optimized. }

Someone can help me? Thanks for your time.

Last edited by monster321; 04-11-2015 at 13:16.
monster321 is offline
Send a message via MSN to monster321 Send a message via Skype™ to monster321
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-11-2015 , 15:28   Re: [HELP] Compare variables.
Reply With Quote #2

Just use the variable since it's global. If that's not what you wanted to hear, you need to explain better what you actually want.
__________________
fysiks is offline
monster321
Member
Join Date: Apr 2012
Old 04-11-2015 , 18:28   Re: [HELP] Compare variables.
Reply With Quote #3

Ok, this plugin is to a mod created for me ( Jailbreak: Uprising ), at the days 5..15..25..35..etc. In this day, all the players are frozen and the vote is started. When the vote finish the option with more votes starts.

Last edited by monster321; 04-11-2015 at 18:31.
monster321 is offline
Send a message via MSN to monster321 Send a message via Skype™ to monster321
Kiske
Veteran Member
Join Date: May 2009
Old 04-11-2015 , 21:15   Re: [HELP] Compare variables.
Reply With Quote #4

You want only for three options, or n options ?

If you only need for three options, use this:
PHP Code:
new iWinner_Id;

if(
voteday[0] >= voteday[1]) {
    if(
voteday[0] >= voteday[2]) {
        
iWinner_Id 0;
    } else {
        
iWinner_Id 2;
    }
} else if(
voteday[1] >= voteday[2]) {
    
iWinner_Id 1;
} else {
    
iWinner_Id 2;


With n options (maybe there is a better way somewhere):
PHP Code:
#define MAX_OPTIONS 10

new iOrder[MAX_OPTIONS];
new 
iRandom[MAX_OPTIONS];
new 
iWinner_Id;
new 
i;
new 
0;

for(
0MAX_OPTIONS; ++i) {
    
iOrder[i] = voteday[i];
}

SortIntegers(iOrder, (MAX_OPTIONS-1), Sort_Descending);

for(
0MAX_OPTIONS; ++i) {
    if(
iOrder[0] == voteday[i]) {
        
iRandom[j] = i;
        ++
j;
    }
}

if(
== 1) {
    
iWinner_Id iRandom[0];
} else { 
// If there are draw, choose randomly
    
iWinner_Id iRandom[random_num(0, (j-1))];

__________________


Last edited by Kiske; 04-11-2015 at 21:20.
Kiske is offline
Send a message via Skype™ to Kiske
monster321
Member
Join Date: Apr 2012
Old 04-12-2015 , 11:01   Re: [HELP] Compare variables.
Reply With Quote #5

That is impressive, thanks Kiske and about your question is to n options.

Last edited by monster321; 04-12-2015 at 11:08.
monster321 is offline
Send a message via MSN to monster321 Send a message via Skype™ to monster321
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 04-14-2015 , 07:37   Re: [HELP] Compare variables.
Reply With Quote #6

Please mind that your for loop in test_plugin( ) is wrong. If you use this way to loop through players you need to loop from 1 to 32 and not from 0 to 32.

Last edited by mottzi; 04-14-2015 at 07:37.
mottzi is offline
Send a message via MSN to mottzi
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 13:20.


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