AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP] Compare variables. (https://forums.alliedmods.net/showthread.php?t=261382)

monster321 04-11-2015 13:15

[HELP] Compare variables.
 
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. :)

fysiks 04-11-2015 15:28

Re: [HELP] Compare variables.
 
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.

monster321 04-11-2015 18:28

Re: [HELP] Compare variables.
 
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.

Kiske 04-11-2015 21:15

Re: [HELP] Compare variables.
 
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))];



monster321 04-12-2015 11:01

Re: [HELP] Compare variables.
 
That is impressive, thanks Kiske and about your question is to n options.

mottzi 04-14-2015 07:37

Re: [HELP] Compare variables.
 
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.


All times are GMT -4. The time now is 16:50.

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