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

Player vote menu


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
rago12
Junior Member
Join Date: Jul 2016
Old 01-29-2021 , 09:54   Player vote menu
Reply With Quote #1

Hello! I am having a hard time understanding the player vote menu example from https://forums.alliedmods.net/showth...6364#AVoteMenu ,
and would appreciate if somebody could help me with the code

I am trying to make a Vote menu which opens to all T players only when a T player types /vote
from where T players can place a vote on chosen existing CT player and then execute a cmd on the one with most the votes

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

public plugin_init() 
	register_clcmd( "say /vote","AwesomeMenu" );

public AwesomeMenu( id )
{
	new menu = menu_create( "Vote which CT to do action on:", "menu_handler" );
	
	new players[32], pnum, tempid
	new szName[32], szTempid[10]
	
	get_players(players, pnum)
	
	for( new i; i<pnum; i++ )
	{
		tempid = players[i]
		
		if (cs_get_user_team(tempid) != CS_TEAM_CT)
		{
			continue
		}
		get_user_name(tempid, szName, 31)
		num_to_str(tempid, szTempid, 9)
		menu_additem(menu, szName, szTempid, 0)
	}

	menu_setprop( menu, MPROP_EXIT, MEXIT_ALL );

	menu_display( id, menu, 0 );

}
public menu_handler( id, menu, item ){
	//Store votes from all T players whom voted>
	//Then execute action on the max voted CT player from menu
}
rago12 is offline
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 01-29-2021 , 12:54   Re: Player vote menu
Reply With Quote #2

https://www.amxmodx.org/api/amxmodx/get_players
__________________


Quote:
Originally Posted by fysiks View Post
Please stop trying to help. You appear to just be posting random stuff. Wait until you actually understand more about AMX Mod X and how the game works.
https://iceeedr.com.br/

Last edited by iceeedr; 01-29-2021 at 12:55.
iceeedr is offline
Send a message via Skype™ to iceeedr
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 01-29-2021 , 14:13   Re: Player vote menu
Reply With Quote #3

So, what's your doubt?
The code you provided add all CT players and their respective indexes to the menu.
Code:
menu_additem(menu, szName, szTempid)
In your case, szTempid is the index of the player. To get it in the menu_handler function, use menu_item_getinfo
Code:
new szTempid[10], iAccess, iCallback menu_item_getinfo(menu, item, iAccess, szTempid, charsmax(szTempid), _, _, iCallback) new player_id = str_to_num(szTempid) // do something with player_id

I would store the player userid instead of its index because if any of the players that are in the menu disconnect and another join in the same slot while the menu is open, you will end up selecting the wrong player. In your case, instead of this

Code:
num_to_str(tempid, szTempid, 9)

Code:
new player_id = str_to_num(szTempid)

you would have the following
Code:
num_to_str(get_user_userid(tempid), szTempid, 9)

Code:
new player_id = find_player("k", str_to_num(szTempid)) if (player_id) {     // player was found, do something } else {     // player is no longer connected }
__________________








CrazY. is offline
rago12
Junior Member
Join Date: Jul 2016
Old 01-31-2021 , 05:29   Re: Player vote menu
Reply With Quote #4

I am stil confused, so, when i get their ID, how do i gather & determine what to do with equal and greater votes
rago12 is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 01-31-2021 , 08:49   Re: Player vote menu
Reply With Quote #5

You'll need a global variable to store the votes.

Code:
new g_PlayerVotes[MAX_PLAYERS+1]


In menu_handler

Code:
g_PlayerVotes[player_id]++


Once the voting is over, determine the winner or winners

Code:
new minimum = 1 new players[MAX_PLAYERS], count for (new i = 1; i < sizeof g_PlayerVotes; i++) {     if (g_PlayerVotes[i] > minimum)         minimum = g_PlayerVotes[i] } for (new i = 1; i < sizeof g_PlayerVotes; i++) {     if (g_PlayerVotes[i] == minimum)         players[count++] = i } if (count == 1) {     // just one winner } else if (count > 1) {     // more than one winner, there is a tie } else {     // no one received at least 1 vote }

In case of tie, you can start another voting but add just the players that tied in the menu, randomly choose between the winners or even work with all of them together. The winner indexes are stored in the players[] array and you would handle that just like get_players.
Note that you will need to do some is_user_connected checks (or work with userid) and reset the g_PlayerVotes[] array (set all to 0) every time a voting begin.
__________________









Last edited by CrazY.; 01-31-2021 at 09:04.
CrazY. is offline
rago12
Junior Member
Join Date: Jul 2016
Old 02-06-2021 , 11:01   Re: Player vote menu
Reply With Quote #6

Thank you for the help!
I figured it out
rago12 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 02:48.


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