Raised This Month: $62 Target: $400
 15% 

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


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Snake.
Senior Member
Join Date: Jul 2017
Location: Istanbul
Old 05-20-2019 , 15:08   [EDIT] Can someone make this vote, close after x seconds ?
Reply With Quote #1

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");
        }
    }

Snake. is offline
Send a message via Skype™ to Snake.
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 05-20-2019 , 15:23   Re: [EDIT] Can someone make this vote, close after x seconds ?
Reply With Quote #2

already closed in 15 secs

PHP Code:
set_task(15.0"CountVotes"
__________________
iceeedr is offline
Send a message via Skype™ to iceeedr
Snake.
Senior Member
Join Date: Jul 2017
Location: Istanbul
Old 05-20-2019 , 15:26   Re: [EDIT] Can someone make this vote, close after x seconds ?
Reply With Quote #3

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.
Snake. is offline
Send a message via Skype™ to Snake.
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 05-21-2019 , 15:53   Re: [EDIT] Can someone make this vote, close after x seconds ?
Reply With Quote #4

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.
__________________
Discord: wEight#6773

Hobbies:
- Map Designing (Any Half-Life 1 Engine Game)
- Pawn (Intermediate / Counter-Strike 1.6 only)
- VB.Net (Intermediate / Winforms)

Last edited by redivcram; 05-21-2019 at 15:54.
redivcram is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-21-2019 , 22:35   Re: [EDIT] Can someone make this vote, close after x seconds ?
Reply With Quote #5

You can remove the menu on the screen with show_menu() as seen here.
__________________
fysiks is offline
Reply


Thread Tools
Display Modes

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 12:05.


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