AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Suggestions / Requests (https://forums.alliedmods.net/forumdisplay.php?f=12)
-   -   [EDIT] Can someone make this vote, close after x seconds ? (https://forums.alliedmods.net/showthread.php?t=316382)

Snake. 05-20-2019 15:08

[EDIT] Can someone make this vote, close after x seconds ?
 
PHP Code:

/*
    Original plugin by "many".  Modified extensively by Fysiks.
*/

#include <amxmodx>
#include <amxmisc>
#include <chatcolor>

#define MAX_OPTIONS 7

new g_pMenu
new g_pCountSystem
new g_pTimelimit

new g_voteCount[MAX_OPTIONS]
new 
g_iVoteTimes[MAX_OPTIONS]
new 
g_iNumOptions 0
new bool:g_bMenuExists false

public plugin_init()
{
    
register_plugin("MaxRounds Vote""0.5""Fysiks")

    
g_pCountSystem    register_cvar("amx_countsys",    "0")
    
register_srvcmd("amx_maxrounds_votes""set_vote_times")

    
// Load up the old default values
    
g_iVoteTimes[0] = 20
    g_iVoteTimes
[1] = 30
    g_iVoteTimes
[2] = 40
    g_iNumOptions 
3
    build_menu
()

    
set_task(60.0"start_vote")
    
register_dictionary_colored("maxroundsvote.txt");
}

public 
plugin_cfg()
{
    
g_pTimelimit get_cvar_pointer("mp_maxrounds")
}

public 
set_vote_times()
{
    new 
buff[8]
    new 
args clampread_argc(), 0MAX_OPTIONS+1)
    
g_iNumOptions args 1

    
if (args <= 1)
    {
        return
    }

    for (new 
1argsi++)
    {
        
read_argv(ibuffcharsmax(buff))
        
g_iVoteTimes[i-1] = str_to_num(buff)
    }
    
build_menu()
}

build_menu()
{
    if( 
g_bMenuExists // if( g_pMenu ) ??
        
menu_destroy(g_pMenu)

    
g_pMenu menu_create("\wChoose max rounds for this map""menu_handler")
    
g_bMenuExists true

    
new option[64], szNum[12]
    for(new 
0g_iNumOptionsi++)
    {
        
formatex(optioncharsmax(option), "\w%d rounds"g_iVoteTimes[i])
        
// server_print(">>>> %d <> %s <<<<", g_iVoteTimes[i], option) // debug
        
formatex(szNumcharsmax(option), "%d"i)
        
menu_additem(g_pMenuoptionszNum)
    }
    
menu_setprop(g_pMenuMPROP_EXITMEXIT_ALL)
}

public 
start_vote(id)
{
    new 
players[32], inumi
    get_players
(playersinum"ch")

    for(
0inumi++)
        
menu_display(players[i], g_pMenu0)

    for(
0g_iNumOptionsi++)
        
g_voteCount[i] = 0

    set_task
(15.0"CountVotes")
    
// server_print("<><><><><><><><><><><><><><><><><><><>") // debug
    
return PLUGIN_CONTINUE
}

public 
menu_handler(idg_pMenuitem)
{
    if(
item == MENU_EXIT)
        return 
PLUGIN_HANDLED

    
new data[6], name[32]
    new 
iAccesscallback

    menu_item_getinfo
(g_pMenuitemiAccessdata5""0callback)

    new 
key str_to_num(data)
    
get_user_name(idname31)

    
client_print_color(0print_chat"%L"LANG_PLAYER"VOTED"nameg_iVoteTimes[key])

    
g_voteCount[key]++

    return 
PLUGIN_HANDLED
}

public 
CountVotes()
{
    new 
votesNum 0

    
if( get_pcvar_num(g_pCountSystem) )
    {
        new 
sum_time 0
        
new iTime

        
for(new 0g_iNumOptionsi++)
        {
            
votesNum += g_voteCount[i]
            
sum_time += g_voteCount[i] * g_iVoteTimes[i]
        }

        if(
votesNum)
        {
            
iTime floatround(float(sum_time) / float(votesNum), floatround_ceil)
            if (
iTime - (iTime iTime 10 10) >= 5// What does this do??
                
iTime += 10

            
//client_print(0, print_chat, "Voting successful. Time limit is set to average: %d rounds", iTime)
            
client_print_color(0print_chat"%L"LANG_PLAYER"SUCCESFULL"iTime);

            
set_pcvar_num(g_pTimelimitiTime)
        }
        else
        {
            
client_print_color(0print_chat"%L"LANG_PLAYER"FAILED");
        }
    }
    else
    {
        new 
best 0

        
for(new i=0;i<(g_iNumOptions);i++)
        {
            if(
g_voteCount[i] > g_voteCount[best])
                
best i
        
}

        for(new 
0g_iNumOptionsi++)
            
votesNum += g_voteCount[i]

        new 
iRequired votesNum floatround(get_cvar_float("amx_vote_ratio") * float(votesNum), floatround_ceil) : 1
        
new iResult g_voteCount[best]

        if(
iResult >= iRequired)
        {
            new 
new_time g_iVoteTimes[best]

            
client_print_color(0print_chat"%L"LANG_PLAYER"WON"new_time);

            
set_pcvar_num(g_pTimelimitnew_time)
        }
        else
        {
            
client_print_color(0print_chat"%L"LANG_PLAYER"FAILED");
        }
    }



iceeedr 05-20-2019 15:23

Re: [EDIT] Can someone make this vote, close after x seconds ?
 
already closed in 15 secs

PHP Code:

set_task(15.0"CountVotes"


Snake. 05-20-2019 15:26

Re: [EDIT] Can someone make this vote, close after x seconds ?
 
Hm no if i dont choose anything, vote does not close.I can still choose even a message show up that i voted for. Just does not count that choose.

redivcram 05-21-2019 15:53

Re: [EDIT] Can someone make this vote, close after x seconds ?
 
Just create a global boolean variable like g_bVotingInProgress. Set to true in start_vote(), set to false in CountVotes and finally restrict item selecting in the vote menu.

fysiks 05-21-2019 22:35

Re: [EDIT] Can someone make this vote, close after x seconds ?
 
You can remove the menu on the screen with show_menu() as seen here.


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

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