Veteran Member
Join Date: Feb 2012
Location: GuateAmala
|
12-12-2020
, 20:31
Vote menu for kill
|
#1
|
Hello everyone, I found this code that makes when a player writes /votekill he gets a menu with all the players and when he selects a name all the players get that if they want to kill that player if the majority vote yes he kills him and if it is the opposite, it does not kill him, what I want to do is that when one writes /votekill, all the living players will get a menu with all the names of the live players on the server and that they vote for who wants to kill the player who receives the most votes it kills it, could someone help me please? ... Thanks in advance
PHP Code:
#include <amxmodx>
#define SetPlayerBit(%1,%2) ( %1 |= ( 1 << ( %2 & 31 ) ) ) #define ClearPlayerBit(%1,%2) ( %1 &= ~( 1 << ( %2 & 31 ) ) ) #define GetPlayerBit(%1,%2) ( ( 1 <= %2 <= 32 ) && ( %1 & ( 1 << ( %2 & 31 ) ) ) )
enum _:Vote_Type { VT_Accept, VT_Reject }
const MENU_KEYS = MENU_KEY_1|MENU_KEY_2;
new const g_szCountdown[ ][ ] = { "one","two","three","four","five","six","seven","eight","nine","ten" };
new g_iVoted, g_iJudged, g_iSayText, g_iConnected, g_iCountDown, g_iSyncObject, g_iMaxPlayers, g_szVoted[ 32 ], Float:g_fLastKill, g_iPlayerVotes[ Vote_Type ];
public plugin_init( ) { register_plugin( "Votekill", "1.0", "Manu" ); register_clcmd( "say /votekill", "CommandVotekill" ); register_menucmd( register_menuid( "Votekill Menu" ), MENU_KEYS, "VoteHandler" ); g_iSyncObject = CreateHudSyncObj( ); g_iMaxPlayers = get_maxplayers( ); g_iSayText = get_user_msgid( "SayText" ); }
/* =================================================== * [ Tasks ] * ==================================================== */
public DoCountdown( ) { set_hudmessage( 85, 212, 255, -1.0, 0.8, 1, 2.0, 1.0 ); ShowSyncHudMsg( 0, g_iSyncObject, "[ Votekill ] Voting will end in %d second(s)", g_iCountDown ); ShowVotekillMenu( 0 ); client_cmd( 0, "spk %s", g_szCountdown[ --g_iCountDown ] ); }
public EndVotekill( ) { set_hudmessage( 85, 212, 255, -1.0, 0.8, 1, 2.0, 3.0 ); if( g_iPlayerVotes[ VT_Reject ] < g_iPlayerVotes[ VT_Accept ] ) { new iId = GetUserIndex( g_iJudged ); if( GetPlayerBit( g_iConnected, iId ) ) { user_kill( iId ); ShowSyncHudMsg( 0, g_iSyncObject, "Enough votes were obtained^nPlayer %s has been killed!", g_szVoted ); } else ShowSyncHudMsg( 0, g_iSyncObject, "Player %s disconnected before punishment.", g_szVoted ); } else ShowSyncHudMsg( 0, g_iSyncObject, "Not enough votes were obtained." ); }
/* =================================================== * [ Client-related ] * ==================================================== */
public client_putinserver( iId ) SetPlayerBit( g_iConnected, iId ); public client_disconnect( iId ) ClearPlayerBit( g_iConnected, iId );
public CommandVotekill( iId ) { if( g_fLastKill < get_gametime( ) ) { if( get_playersnum( ) >= 3 ) { static iMenu, iPlayer, szData[ 8 ], szName[ 16 ]; iMenu = menu_create( "\wPlayers list", "VotekillHandler" ); for( iPlayer = 1; iPlayer <= g_iMaxPlayers; iPlayer++ ) { if( !GetPlayerBit( g_iConnected, iPlayer ) || ( get_user_flags( iPlayer ) & ADMIN_IMMUNITY ) ) continue; get_user_name( iPlayer, szName, charsmax( szName ) ); formatex( szData, charsmax( szData ), "%d %d", iPlayer, get_user_userid( iPlayer ) ); menu_additem( iMenu, szName, szData ); } menu_setprop( iMenu, MPROP_NEXTNAME, "Next" ); menu_setprop( iMenu, MPROP_BACKNAME, "Back" ); menu_setprop( iMenu, MPROP_EXITNAME, "Cancel" ); menu_display( iId, iMenu ); } else PrintColor( iId,"^x04[Votekill]^x01 There must be at least three players to start a vote." ); } else PrintColor( iId,"^x04[Votekill]^x01 Remain^x04 %d^x01 seconds remaining before another votekill can be started.",floatround( g_fLastKill - get_gametime( ) ) ); return PLUGIN_HANDLED; }
public VotekillHandler( iId, iMenu, iItem ) { if( iItem != MENU_EXIT ) { static szData[ 8 ], szPlayer[ 4 ], iNum, iPlayer, szName[ 32 ]; menu_item_getinfo( iMenu, iItem, iNum, szData, charsmax( szData ), _, _, iNum ); strtok( szData, szPlayer, charsmax( szPlayer ), szData, charsmax( szData ), ' ', true ); if( GetPlayerBit( g_iConnected, ( iPlayer = str_to_num( szPlayer ) ) ) && ( get_user_userid( iPlayer ) == str_to_num( szData ) ) ) { g_iJudged = get_user_userid( iPlayer ); get_user_name( iId, szName, charsmax( szName ) ); get_user_name( iPlayer, g_szVoted, charsmax( g_szVoted ) ); PrintColor( 0, "^x04[Votekill]^x01 The player^x04 %s^x01 has started a^x04 votekill^x01 against^x04 %s^x01.", szName, g_szVoted ); StartVotekill( ); } } }
public VoteHandler( iId, iKey ) { if( !GetPlayerBit( g_iConnected, iId ) || GetPlayerBit( g_iVoted, iId ) ) return PLUGIN_HANDLED; g_iPlayerVotes[ iKey ]++; SetPlayerBit( g_iVoted, iId ); client_cmd( iId,"spk buttons/lightswitch2.wav" ); ShowVotekillMenu( iId ); return PLUGIN_HANDLED; }
/* =================================================== * [ Other functions ] * ==================================================== */
GetUserIndex( const iUserId ) { for( new iPlayer = 1; iPlayer <= g_iMaxPlayers; iPlayer++ ) { if( !GetPlayerBit( g_iConnected, iPlayer ) || ( get_user_userid( iPlayer ) != iUserId ) ) continue; return iPlayer; } return 0; }
StartVotekill( ) { g_iCountDown = 10; g_iPlayerVotes[ VT_Accept ] = 0; g_iPlayerVotes[ VT_Reject ] = 0; g_fLastKill = get_gametime( ) + 120.0; for( new iPlayer = 1; iPlayer <= g_iMaxPlayers; iPlayer++ ) ClearPlayerBit( g_iVoted, iPlayer ); set_task( 1.0, "DoCountdown", .flags = "a", .repeat = 10 ); set_task( 12.0, "EndVotekill" ); }
ShowVotekillMenu( iId ) { static szBuffer[ 256 ], iLen; iLen = formatex( szBuffer, charsmax( szBuffer ), "Vote to assassinate\y%s\w^n^n", g_szVoted ); iLen += formatex( szBuffer[ iLen ], charsmax( szBuffer ) - iLen, "\r[1] \yAccept \w[ Votes: \y%d \w]^n", g_iPlayerVotes[ VT_Accept ] ); iLen += formatex( szBuffer[ iLen ], charsmax( szBuffer ) - iLen, "\r[2] \yRefuse \w[ Votes: \y%d \w]^n^n", g_iPlayerVotes[ VT_Reject ] ); iLen += formatex( szBuffer[ iLen ], charsmax( szBuffer ) - iLen, "\r[!] \wVoting ends in \y%d segcond(s)", g_iCountDown ); show_menu( iId, MENU_KEYS, szBuffer, 1, "Votekill Menu" ); return PLUGIN_HANDLED; }
PrintColor( iId, szText[ ], any:... ) { static szBuffer[ 192 ]; vformat( szBuffer, charsmax( szBuffer ), szText, 3 ); if( !iId ) { message_begin( MSG_ALL, g_iSayText, _, iId ); write_byte( 1 ); write_string( szBuffer ); message_end( ); } else { message_begin( MSG_ONE, g_iSayText, _, iId ); write_byte( iId ); write_string( szBuffer ); message_end( ); } }
Last edited by wicho; 12-12-2020 at 20:41.
|
|