PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <colorchat>
#include <cstrike>
#define PLUGIN "JB Spec Day"
#define AUTHOR "Pancakez"
//How many different votes there will be in the menu
#define MAX_VOTEIDS 7
//How much "weight" a normal player's vote is worth
#define WEIGHT_PLAYER 1
//How much "weight" an admin's vote is worth
#define WEIGHT_ADMIN 2
new gVoteMenu;
new gVotes[MAX_VOTEIDS];
new gVoting;
new gVoteID[MAX_VOTEIDS];
new bool:IsCommander[33]
public plugin_init()
{
register_plugin(PLUGIN, "0.0.1", AUTHOR)
register_logevent("EventNewRound", 2, "1=Round_Start")
register_logevent("EventRoundEnd", 2, "1=Round_End")
register_clcmd("say /vote", "StartVote")
register_clcmd("say /blabla", "blabla")
}
public EventNewRound(id)
{
//StartVote(id)
}
public EventRoundEnd(id)
{
IsCommander[id] = false
}
public StartVote(id)
{
if( gVoting )
{
ColorChat(id, GREY, "[^4HB^3] There is already a vote going.");
return PLUGIN_HANDLED;
}
gVoteMenu = menu_create("\rWho should be the commander?", "menu_handler");
//Here you can do whatever you want to add your voteids.
//We are going to use players for the example
new players[32], pnum, tempid;
get_players(players, pnum, "a");
//Variable for if the player was added to the vote
new bool:player_added[33], voteid_count;
new szName[32], szTempid[10];
//Loop through until we get enough voteids or run out of players
while( voteid_count < MAX_VOTEIDS && voteid_count < pnum)
{
//Get a random player
tempid = players[ random(pnum) ];
//If they haven't been added yet
if( !player_added[tempid] )
{
get_user_name(tempid, szName, charsmax(szName));
//We are setting the data to the voteid number, not the actual voteid
num_to_str(voteid_count, szTempid, charsmax(szTempid));
menu_additem(gVoteMenu, szName, szTempid, 0);
//Make sure we do not add them again
player_added[tempid] = true;
//Save the voteid
gVoteID[voteid_count] = tempid;
//Go to the next voteid
voteid_count++;
}
}
//Now we have all the voteids
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 by their weight
if( is_user_admin(tempid) )
gVoting += WEIGHT_ADMIN;
else
gVoting += WEIGHT_PLAYER;
}
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 )
{
return PLUGIN_HANDLED;
}
new data[6], szName[64];
new access, callback;
menu_item_getinfo(menu, item, access, data,charsmax(data), szName,charsmax(szName), callback);
//Get the voteid number that was selected
new voteid_num = str_to_num(data);
//Increase the votes for what they selected by weight
if( is_user_admin(id) )
gVotes[voteid_num] += WEIGHT_ADMIN;
else
gVotes[voteid_num] += WEIGHT_PLAYER;
return PLUGIN_HANDLED;
}
public EndVote()
{
//This will hold how many different votes were selected
new votes_select;
//This will hold the top 3 votes
new votes[3];
//This will hold the top 3 selected voteids
new voteid[3];
new i, j;
//Loop through all the voteids
for( i=0; i<MAX_VOTEIDS; i++ )
{
//If the voteid recieved any votes
if( gVotes[i] )
{
//If we are still trying to get the top 3
if( votes_select < 3 )
{
//Save the data for the current voteid selected
votes[votes_select] = gVotes[i];
voteid[votes_select] = i;
//Go to the next voteid that might have been selected
votes_select++;
}
else
{
//Loop through all the top votes, replace any that are lower than the selected voteid
for( j=0; j<3; j++ )
{
//If this one recieved less votes
if( votes[j] < gVotes[i] )
{
//Change the data to the voteid with more votes
votes[j] = gVotes[i];
voteid[j] = i;
//Don't need to bother looking for more
break;
}
}
}
}
}
//If noone voted
if( !votes_select )
{
ColorChat(0, GREY, "[^4HB^3] Commander Vote Failed.");
}
//Else if one voteid recieved all the votes
else if( votes_select == 1 )
{
//Give it to the voteid
VoteGiveCommander( voteid[0] );
}
//Else if two different voteids recieved all the votes
else if( votes_select == 2 )
{
//If they recieved even votes
if( votes[0] == votes[1] )
{
//Give it to a random one
ColorChat(0, GREY, "[^4HB^3] Vote has tied. Choosing random from tied votes.");
VoteGiveCommander( voteid[ random(2) ] );
}
//Else if the first recieved the most
else if( votes[0] > votes[1] )
//Give it to the first
VoteGiveCommander( voteid[0] );
//Else the second recieved the most
else
//Give it to the second
VoteGiveCommander( voteid[1] );
}
//Else there were at least 3 different votes
else
{
//Here you might want to do run-off voting, but well just select a random one
ColorChat(0, GREY, "[^4HB^3] Could not determine a winner. Selecting random.");
VoteGiveCommander( voteid[ random(3) ] );
}
menu_destroy(gVoteMenu);
gVoting = 0;
}
VoteGiveCommander(index)
{
new id = gVoteID[index]
if( is_user_alive(id) )
{
IsCommander[id] = true
new szName[32];
get_user_name(id, szName, charsmax(szName));
ColorChat(0, GREY, "[^4HB^3] %s Have been voted as commander!", szName);
}
}
public blabla(id)
{
if(IsCommander[id] == true)
{
set_user_noclip(id, 1)
}
else client_print(id, print_chat, "You are not the commander!")
}
I want the CT's only to show up in the vote menu. I've tried several things but without succes. Don't bother the public bla bla, it's only testing things.