#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <fun>
//This will hold the VoteMenu
new gVoteMenu;
//This will hold the votes for each option
new gVotes[2];
//This determines if a vote is already happening
new gVoting;
public plugin_init(){
register_clcmd("say /free","freerun"),
RegisterHam(Ham_Use, "func_button", "ButtonUse");
//Register a way to get to your vote...
}
public ButtonUse(ent, id){
if (get_user_team(id)==1) return HAM_SUPERCEDE
return PLUGIN_HANDLED
}
public freerun(id)
{
if( get_user_team( id ) == 1 )
StartVote(id)
else
client_print(id, print_chat, "Ta komenda jest tylko dostepna dla Terrorysty!")
}
public StartVote(id)
{
//If there is already a vote, don't start another
if( gVoting )
{
client_print(id, print_chat, "There is already a vote going.");
//We return PLUGIN_HANDLED so the person does not get Unknown Command in console
return PLUGIN_HANDLED;
}
//Store the menu in the global
gVoteMenu = menu_create("\rCT chce free?!:", "menu_handler");
//Add some vote options
menu_additem(gVoteMenu, "Tak", "0", 0);
menu_additem(gVoteMenu, "Nie", "1", 0);
//We will need to create some variables so we can loop through all the players
new players[32], pnum, tempid;
//Fill players with available players
get_players(players, pnum);
//Start looping through all players to show the vote to
for( new i; i<pnum; i++ )
{
//Save a tempid so we do not re-index
tempid = players[i];
//Show the vote to this player
menu_display(tempid, gVoteMenu, 0);
//Increase how many players are voting
gVoting++;
}
//End the vote in 10 seconds
set_task(10.0, "EndVote");
return PLUGIN_HANDLED;
}
public menu_handler(id, menu, item)
{
//If the menu was exited or if there is not a vote
if( item == MENU_EXIT || !gVoting )
{
//Note were not destroying the menu
return PLUGIN_HANDLED;
}
new data[6], iName[64];
new access, callback;
menu_item_getinfo(menu, item, access, data,5, iName, 63, callback);
//Get the id of the player that was selected
new voteid = str_to_num(data);
//Increase the votes for what they selected
gVotes[voteid]++;
//Note were not destroying the menu
return PLUGIN_HANDLED;
}
public EndVote()
{
//If the first option recieved the most votes
if( gVotes[0] > gVotes[1] )
client_print(0, print_chat, "CT Chce Free, wszystkie pulapki zablokowane !", gVotes[0] )
//Else if the second option recieved the most votes
else if( gVotes[0] > gVotes[1] )
client_print(0, print_chat, "CT Nie chce Free, gramy normalnie dalej !", gVotes[1] );
//Otherwise the vote tied
else
client_print(0, print_chat, "CT Nie chce Free, gramy normalnie dalej !", gVotes[0] );
//Don't forget to destroy the menu now that we are completely done with it
menu_destroy(gVoteMenu);
//Reset that no players are voting
gVoting = 0;
}
Z góry dzięki
Użytkownik Monsulito edytował ten post 27.04.2010 10:10