Raised This Month: $32 Target: $400
 8% 

Vote timelimit


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kooomax
Member
Join Date: Jan 2018
Old 05-26-2023 , 09:36   Vote timelimit
Reply With Quote #1

The idea of the plugin is that a vote will be held to choose the time of the players current map
A menu will open after say 50 seconds of going to the map, and players will choose from which time they want to set


Vote Timelimit For This namemap

1. 15 Minutes
2. 25 Minutes
3. 30 Minutes
4. I don't want to vote

It may also be possible to add a cmd to admin to open this menu

--
And also
In the last 3 minutes
A vote will be held for the extension of time

Do you want to extend the time

1. 5 Minutes
2. 10 Miuntes
3. I don't want to extend the time
kooomax is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-28-2023 , 22:36   Re: Vote timelimit
Reply With Quote #2

Have you tried any existing timelimit vote plugins? E.g. this one.

If you can find one that is similar to what you want it might be easier to just modify that one.
__________________
fysiks is offline
kooomax
Member
Join Date: Jan 2018
Old 05-29-2023 , 04:34   Re: Vote timelimit
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
Have you tried any existing timelimit vote plugins? E.g. this one.

If you can find one that is similar to what you want it might be easier to just modify that one.
It has what I want
But can it only be modified and added in the last 3 minutes of the map time

Do you want to extend the time

1.5 minutes
2. 10 minutes
3. I don't want to extend the time

Code:
#include <amxmodx>
#include <amxmisc>

#define PLUGIN	"TimeLimit vote"
#define AUTHOR	"many"
#define VERSION	"0.4"

#define MAX_RESULTS 5

//thnx pr4er for help

new Float:g_timelimit
new menu

new g_voteCount[MAX_RESULTS + 1]
new g_tls[MAX_RESULTS]
new tls[MAX_RESULTS]

new g_CountSys

public plugin_init() 
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	g_CountSys	= register_cvar("amx_countsys",	"1")
	
	new name[12], string[12]
	new multiplic = 20 // +++++
	
	for(new i=0;i<MAX_RESULTS;i++)
	{
		format(name, sizeof name -1, "amx_tl_%d", i+1)
		
		format(string, sizeof string -1, "%d", multiplic)
		
		tls[i] = register_cvar(name, string)
		
		multiplic += 10
	}
}

public plugin_cfg()
{
	menu = menu_create("\wChoose timelimit for this map?", "menu_handler")
	
	for(new i=0;i<MAX_RESULTS;i++)
		g_tls[i] = get_pcvar_num(tls[i])
	
	set_task(180.0, "start_vote")
	
	build_menu()
}

build_menu()
{	
	new option[64], temp[12]
	for(new i=0;i<MAX_RESULTS;i++)
	{
		format(option, sizeof option -1, "\w%d minutes", g_tls[i])
		format(temp, sizeof temp -1, "%d", i+1)
		
		menu_additem(menu, option, temp, 0)
	}
	
	menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)
}

public start_vote(id)
{	
	new players[32], inum, i
	get_players(players, inum, "ch")
	
	for(i=0;i<inum;i++)
		menu_display(players[i], menu, 0)
	
	set_task(15.0, "finish_vote")
	
	for(i=1;i<(MAX_RESULTS+1);i++)
		g_voteCount[i] = 0
	
	return PLUGIN_CONTINUE
}

public menu_handler(id, menu, item)
{
	if( !is_user_connected( id ) )
		return PLUGIN_HANDLED 

	if(item == MENU_EXIT)
	{
		menu_cancel(id)
		
		return PLUGIN_HANDLED
	}
	
	new data[6], name[32]
	new access, callback
	
	menu_item_getinfo(menu, item, access, data, 5, "", 0, callback)
	
	new key = str_to_num(data)
	get_user_name(id, name, 31)
	
	client_print(0, print_chat, "[KZ] %s voted for %d minutes", name, g_tls[key -1])
	
	g_voteCount[key]++
	
	menu_cancel(id)
	
	return PLUGIN_HANDLED
}

public finish_vote()
{	
	new players[32], inum
	get_players(players, inum, "ch")
	
	for(new i=0;i<inum;i++)
		client_cmd(players[i], "slot10")
	
	CountVotes()
}

public CountVotes()
{
	g_timelimit = get_cvar_float("mp_timelimit")
	new votesNum = 0
	
	if(!get_pcvar_num(g_CountSys))
	{	
		new best = 0
		
		for(new i=1;i<(MAX_RESULTS+1);i++)
		{
			if(g_voteCount[i] > g_voteCount[best])
				best = i
		}
		
		for(new i=1;i<(MAX_RESULTS+1);i++)
			votesNum += g_voteCount[i]
		
		new iRatio = votesNum ? floatround(get_cvar_float("amx_vote_ratio") * float(votesNum), floatround_ceil) : 1
		new iResult = g_voteCount[best]
		
		if(iResult >= iRatio)
		{
			new new_time = g_tls[best -1]
			
			client_print(0, print_chat, "[KZ] Voting successful. Option %d minutes won.", new_time)
			
			set_cvar_num("mp_timelimit", new_time)
		}
		else
		{
			client_print(0, print_chat, "[KZ] Voting failed.")
		}
	}
	if(get_pcvar_num(g_CountSys) == 1)
	{
		new summ_time = 0
		new _time
		
		for(new i=1;i<(MAX_RESULTS+1);i++)
		{
			votesNum += g_voteCount[i]
			summ_time += g_voteCount[i] * g_tls[i-1]
		}
		
		if(votesNum)
		{
			_time = floatround(float(summ_time) / float(votesNum), floatround_ceil)
			if (_time - (_time = _time / 10 * 10) >= 5) 
				_time += 10
			
			client_print(0, print_chat, "[KZ] Voting successful. Time limit is set to average - %d minutes", _time)
			
			set_cvar_num("mp_timelimit", _time)
			
		}
		else
		{
			client_print(0, print_chat, "[KZ] Voting failed.")
		}
		
	}
}

public plugin_end() 
{
	set_cvar_float("mp_timelimit", g_timelimit)
}
kooomax 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 22:34.


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