AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Vote menu countdown (https://forums.alliedmods.net/showthread.php?t=317208)

666 07-02-2019 18:54

Vote menu countdown
 
good, I'm trying to make a menu with a countdown, until now I have achieved this, but has some problems which I will number:

1- the menu does not update the regressive time
2- players can vote again

until those two moments if you can optimize or improve please do it

PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

#define TASK_VOTE     3032
new RD_iVotes[2],RD_iMenu,RD_iNumPlayer,RD_iCountDown;
new 
iPlayers[32],szName[32];

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say .vote","Comand");
}

public 
Comand(id)
{
        if(!
task_exists(TASK_VOTE))
        {
            
RD_iCountDown 15;
            
set_task(1.0,"RD_FinishVote",TASK_VOTE,"",0,"b");
        }
        
        
get_players(iPlayers,RD_iNumPlayer);
        
get_user_name(id,szName,charsmax(szName));
            
        new 
iMenuTitle[512],iMenuSI[512],iMenuNO[512],iMenuTime[512];
        
formatex(iMenuTitle,charsmax(iMenuTitle),"VOTE: RESTART ROUND^nBy: %s",szName);
        
formatex(iMenuSI,charsmax(iMenuSI),"[%d] YES",RD_iVotes[0]);
        
formatex(iMenuNO,charsmax(iMenuNO),"[%d] NO",RD_iVotes[1]);
        
formatex(iMenuTime,charsmax(iMenuTime),"Vote Time %i",RD_iCountDown);
                            
        
RD_iMenu menu_create(iMenuTitle,"RD_VoteHandler");
        
menu_setprop(RD_iMenu,MPROP_NUMBER_COLOR,"\d");
        
menu_additem(RD_iMenu,iMenuSI,"0");
        
menu_additem(RD_iMenu,iMenuNO,"1");
        
menu_setprop(RD_iMenu,MPROP_EXITNAME,iMenuTime);
                       
        for( new 
i;RD_iNumPlayeri++ )
        
menu_display(iPlayers[i],RD_iMenu,0);
}

public 
RD_FinishVote()
{
        
RD_iCountDown--;
        
        for( new 
i;RD_iNumPlayeri++ )
        
menu_display(iPlayers[i],RD_iMenu,0);
        
        if(
RD_iCountDown <= 0)
        {
            
menu_destroy(RD_iMenu);
            
show_menu00"^n");
            
            if(
RD_iVotes[0] > RD_iVotes[1])
            {
                
client_print_color(0,print_team_default,"VOTE RESTART ROUND: accepted");
            }
            else
            {
                
client_print_color(0,print_team_default,"VOTE RESTART ROUND: rejected");
            }
            
            
RD_iCountDown 0;
            
remove_task(TASK_VOTE);
            
RD_iVotes[0] = RD_iVotes[1] = 0;
        }
}

public 
RD_VoteHandlerCallBack(id,iMenu,iKey)
{
    return 
ITEM_DISABLED;
}

public 
RD_VoteHandler(id,iMenu,iItem)
{
    if(
iItem == MENU_EXIT)
    {
        return 
PLUGIN_HANDLED;
    }
    
    new 
data[6], iName[64];
    new 
accesscallback;
    
menu_item_getinfo(iMenuiItemaccessdata5iName63callback);
    
    new 
votekey str_to_num(data);
    
RD_iVotes[votekey]++;
    
    switch(
votekey)
    {
        case 
0Comand(id);
        case 
1Comand(id);
    }
    return 
PLUGIN_HANDLED;



Natsheh 07-03-2019 02:57

Re: Vote menu countdown
 
PHP Code:

/* Plugin generated by AMXX-Studio */ 

#include <amxmodx> 
#include <amxmisc> 

#define PLUGIN "vote round restart" 
#define VERSION "1.0" 
#define AUTHOR "nobody" 

#define TASK_VOTE     3032 

new g_iMenug_iCountdownbool:g_bVoted[33];

public 
plugin_init() 

    
register_plugin(PLUGINVERSIONAUTHOR
     
    
register_clcmd("say .vote","clcmd_vote"); 


public 
clcmd_vote(idlevelcid)
{
    if(!
cmd_access(idlevelcid1) || task_exists(TASK_VOTE)) return 1;

    
vote_menu(id10"0""0"); return 1;
}

vote_menu(idcountdownszVoteYesNum[], szVoteNoNum[]) 
{
        static 
szTitle[96];
        if(
g_iMenu 0)
        {
                
menu_destroy(g_iMenu); g_iMenu 0;
        }
        else if(
id 0)
        {
                new 
szName[32];
                
get_user_name(idszNamecharsmax(szName));
                
formatex(szTitle,charsmax(szTitle),"VOTE: Round Restart^nBy: %s",szName);
                
g_iCountdown countdown;
                
set_task(1.0"RD_FinishVote"TASK_VOTE__"b");
                for(new 
isizeof g_bVotedi++) g_bVoted[i] = false;
         }

        new 
iAPlayers[32], pnum;
        
get_players(iAPlayerspnum"ch")

        new 
szBuffer[128]
        
g_iMenu menu_create(szTitle,"RD_VoteHandler"); 

        
formatex(szBuffer,charsmax(szBuffer),"[%s] YES"szVoteYesNum); 
        
menu_additem(g_iMenu,szBuffer,szVoteYesNum);

        
formatex(szBuffer,charsmax(szBuffer),"[%s] NO^n^n^nVote Time %i"szVoteNoNumcountdown);
        
menu_additem(g_iMenu,szBuffer,szVoteNoNum);

         
menu_setprop(g_iMenu,MPROP_EXITMEXIT_NEVER); 
                             
     
menu_setprop(g_iMenu,MPROP_NUMBER_COLOR,"\w");  
                        
        for( new 
i;pnumi++ ) {
                
menu_display(iAPlayers[i],g_iMenu,0); 
        }


public 
RD_FinishVote(taskid

        if(
g_iMenu <= 0)
        {
             
remove_task(taskid);
             return;
        }

        new 
szYesVotes[4], szNoVotes[4]; 
        new 
paccesscallback
        
menu_item_getinfo(g_iMenu0paccessszYesVotes3""0callback);

         
menu_item_getinfo(g_iMenu1paccessszNoVotes3""0callback);

        if(
g_iCountdown <= 0
        {
            
show_menu00"^n"); 
             
            if(
str_to_num(szNoVotes) < str_to_num(szYesVotes))
            { 
                
client_print_color(0,print_team_default,"VOTE RESTART ROUND: accepted"); 
            } 
            else 
            { 
                
client_print_color(0,print_team_default,"VOTE RESTART ROUND: rejected"); 
            } 
        }
        else
        {
             
vote_menu(0, --g_iCountdownszYesVotesszNoVotes);
             return;
        }

        
menu_destroy(g_iMenu); 
        
g_iMenu 0;
        
remove_task(taskid);


public 
RD_VoteHandler(id,iMenu,iItem

    if(
iItem == MENU_EXIT
    { 
        return 
PLUGIN_HANDLED
    } 
    if(
g_bVoted[id])
    {
        
menu_display(idiMenu);
        return 
PLUGIN_HANDLED;
    }
     
    new 
szYesVotes[4], szNoVotes[4]; 
    new 
paccesscallback
    
menu_item_getinfo(iMenu0paccessszYesVotes3""0callback);
    
    
menu_item_getinfo(iMenu1paccessszNoVotes3""0callback);

    
g_bVoted[id] = true// NoAccess / player voted
    
switch(iItem
    { 
        case 
0:
        {
               
num_to_str(str_to_num(szYesVotes) + 1szYesVotescharsmax(szYesVotes));
               
vote_menu(0g_iCountdownszYesVotesszNoVotes);
         }
        case 
1:
        {
               
num_to_str(str_to_num(szNoVotes) + 1szNoVotescharsmax(szNoVotes));
               
vote_menu(0g_iCountdownszYesVotesszNoVotes);
         }
    } 
    return 
PLUGIN_HANDLED



666 07-03-2019 09:39

Re: Vote menu countdown
 
Quote:

Originally Posted by Natsheh (Post 2657563)
PHP Code:

/* Plugin generated by AMXX-Studio */ 

#include <amxmodx> 
#include <amxmisc> 

#define PLUGIN "vote round restart" 
#define VERSION "1.0" 
#define AUTHOR "nobody" 

#define TASK_VOTE     3032 

new g_iMenug_iCountdownbool:g_bVoted[33];

public 
plugin_init() 

    
register_plugin(PLUGINVERSIONAUTHOR
     
    
register_clcmd("say .vote","clcmd_vote"); 


public 
clcmd_vote(idlevelcid)
{
    if(!
cmd_access(idlevelcid1) || task_exists(TASK_VOTE)) return 1;

    
vote_menu(id10"0""0"); return 1;
}

vote_menu(idcountdownszVoteYesNum[], szVoteNoNum[]) 
{
        static 
szTitle[96];
        if(
g_iMenu 0)
        {
                
menu_destroy(g_iMenu); g_iMenu 0;
        }
        else if(
id 0)
        {
                new 
szName[32];
                
get_user_name(idszNamecharsmax(szName));
                
formatex(szTitle,charsmax(szTitle),"VOTE: Round Restart^nBy: %s",szName);
                
g_iCountdown countdown;
                
set_task(1.0"RD_FinishVote"TASK_VOTE__"b");
                for(new 
isizeof g_bVotedi++) g_bVoted[i] = false;
         }

        new 
iAPlayers[32], pnum;
        
get_players(iAPlayerspnum"ach")

        new 
szBuffer[128]
        
g_iMenu menu_create(szTitle,"RD_VoteHandler"); 

        
formatex(szBuffer,charsmax(szBuffer),"[%s] YES"szVoteYesNum); 
        
menu_additem(g_iMenu,szBuffer,szVoteYesNum);

        
formatex(szBuffer,charsmax(szBuffer),"[%s] NO"szVoteNoNum);
        
menu_additem(g_iMenu,szBuffer,szVoteNoNum); 

        
formatex(szBuffer,charsmax(szBuffer),"^n^n^nVote Time %i"countdown);
        
menu_addtext(g_iMenuszBuffer);

         
menu_setprop(g_iMenu,MPROP_EXITMEXIT_NEVER); 
                             

        
menu_setprop(g_iMenu,MPROP_NUMBER_COLOR,"\w");  
                        
        for( new 
i;pnumi++ ) {
                
menu_display(iAPlayers[i],g_iMenu,0); 
        }


public 
RD_FinishVote(taskid

        if(
g_iMenu <= 0)
        {
             
remove_task(taskid);
             return;
        }

        new 
szYesVotes[4], szNoVotes[4]; 
        new 
paccesscallback
        
menu_item_getinfo(g_iMenu0paccessszYesVotes3""0callback);

         
menu_item_getinfo(g_iMenu1paccessszNoVotes3""0callback);

        if(
g_iCountdown <= 0
        {
            
show_menu00"^n"); 
             
            if(
str_to_num(szNoVotes) < str_to_num(szYesVotes))
            { 
                
client_print_color(0,print_team_default,"VOTE RESTART ROUND: accepted"); 
            } 
            else 
            { 
                
client_print_color(0,print_team_default,"VOTE RESTART ROUND: rejected"); 
            } 
            
menu_destroy(g_iMenu); 
            
g_iMenu 0;
        }
        else
        {
             
vote_menu(0g_iCountdownszYesVotesszNoVotes);
             
g_iCountdown--;
             return;
        }

        
remove_task(taskid);


public 
RD_VoteHandler(id,iMenu,iItem

    if(
iItem == MENU_EXIT
    { 
        return 
PLUGIN_HANDLED
    } 
    if(
g_bVoted[id])
    {
        
menu_display(idiMenu);
        return 
PLUGIN_HANDLED;
    }
     
    new 
szYesVotes[4], szNoVotes[4]; 
    new 
paccesscallback
    
menu_item_getinfo(iMenu0paccessszYesVotes3""0callback);
    
    
menu_item_getinfo(iMenu1paccessszNoVotes3""0callback);

    
g_bVoted[id] = true// NoAccess / player voted
    
switch(iItem
    { 
        case 
0:
        {
               
num_to_str(++str_to_num(szYesVotes), szYesVotescharsmax(szYesVotes));
               
vote_menu(0g_iCountdownszYesVotesszNoVotes);
         }
        case 
1:
        {
               
num_to_str(++str_to_num(szNoVotes), szNoVotescharsmax(szNoVotes));
               
vote_menu(0g_iCountdownszYesVotesszNoVotes);
         }
    } 
    return 
PLUGIN_HANDLED



well I can not compile it because of these errors

error 022: must be lvalue <non-constant>
line 132: num_to_str(++str_to_num(szYesVotes), szYesVotes, charsmax(szYesVotes));
line 137: num_to_str(++str_to_num(szNoVotes), szNoVotes, charsmax(szNoVotes));

Natsheh 07-03-2019 09:46

Re: Vote menu countdown
 
Code updated try again.

666 07-03-2019 10:00

Re: Vote menu countdown
 
Quote:

Originally Posted by Natsheh (Post 2657605)
Code updated try again.

ok now what happens is that the menu opens the vote but the countdown is always at 10 and it seems it will never end

Natsheh 07-03-2019 10:10

Re: Vote menu countdown
 
Quote:

Originally Posted by 666 (Post 2657606)
ok now what happens is that the menu opens the vote but the countdown is always at 10 and it seems it will never end

Alright problem solved, code updated, I was decreasing after showing the menu solved by doing the opposite.

666 07-03-2019 10:29

Re: Vote menu countdown
 
Quote:

Originally Posted by Natsheh (Post 2657608)
Alright problem solved, code updated, I was decreasing after showing the menu solved by doing the opposite.

Literally when the voting begins the menu is shown and the countdown does not go back, now on one occasion start the vote and press many times yes and the countdown start hahaha

hey I realized that when the player has already voted, he can not select the grenades or weapons by means of the numbers or buttons, this can be fixed

Natsheh 07-03-2019 11:20

Re: Vote menu countdown
 
Quote:

Originally Posted by 666 (Post 2657611)
Literally when the voting begins the menu is shown and the countdown does not go back, now on one occasion start the vote and press many times yes and the countdown start hahaha

hey I realized that when the player has already voted, he can not select the grenades or weapons by means of the numbers or buttons, this can be fixed


I think 1st problem is solved,

2th problem is not because there is a bug in new amxx menu with amx_addtext I removed it and moved the countdown timer to item two using new line character to separate them.


Menu should now been shown to dead players also.

666 07-03-2019 11:44

Re: Vote menu countdown
 
Quote:

Originally Posted by Natsheh (Post 2657615)
I think 1st problem is solved,

2th problem is not because there is a bug in new amxx menu with amx_addtext I removed it and moved the countdown timer to item two using new line character to separate them.


Menu should now been shown to dead players also.

I tried it and the option "NO" does not appear like the countdown and it still does not work.

I remove this function from RD_FinishVote and it works fine, now tell me if it is ok or not, this is the function:

PHP Code:

if(g_iMenu <= 0)
{
     
remove_task(taskid);
     return;    



Natsheh 07-03-2019 12:06

Re: Vote menu countdown
 
Quote:

Originally Posted by 666 (Post 2657618)
I tried it and the option "NO" does not appear like the countdown and it still does not work.

I remove this function from RD_FinishVote and it works fine, now tell me if it is ok or not, this is the function:

PHP Code:

if(g_iMenu <= 0)
{
     
remove_task(taskid);
     return;    




This has nothing to do with not showing the option NO

I just deleted the option NO by accident I readded it . Code updated.

The thing you removed is just a safe check to not throw an error invalid menu id.

Everything is hard to modify when you're using a phone


All times are GMT -4. The time now is 17:22.

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