Hi all!
I'm new with amxmodx scripting.I have made a advanced vote plugin for my practice.But it doesn't work correctly. This plugin must open a vote menu and the title is"Which player should get 255 health.". This vote menu bring 7 players name for 10 seconds and players should vote to one of the players in the menu.After 10 seconds it collects votes and selections and selects the player who has the most votes and sets his health to 255. The problem is here, when you say the command /vote the menu doesn't appear and after 10 seconds it prints a chat that says Vote has tied.
This is the code:
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fun>
#define MAX_VOTEIDS 7
#define WEIGHT_PLAYER 1
#define WEIGHT_ADMIN 2
new gVoteMenu;
new gVotes[MAX_VOTEIDS];
new gVoting;
new gVoteID[MAX_VOTEIDS];
public plugin_init() {
register_plugin("My Advanced Vote Menu", "1.0", "Dark_siders");
register_clcmd("say /vote", "StartVote");
}
public StartVote(id)
{
if (gVoting)
{
new szName[32];
get_user_name(id, szName, charsmax(szName));
client_print(id, print_chat, "%s be patience.There is already a vote going.", szName);
return PLUGIN_HANDLED;
}
arrayset(gVotes, 0, sizeof gVotes);
gVoteMenu = menu_create("\Which player should get 255 health?", "menu_handler");
new players[32], pnum, tempid;
get_players(players, pnum, "a");
new bool:player_added[33], voteid_count;
new szName[32], szVoteId[10];
while (voteid_count < MAX_VOTEIDS && voteid_count < pnum)
{
tempid = players[random(pnum)];
if (!player_added[tempid])
{
get_user_name(tempid, szName, charsmax(szName));
num_to_str(voteid_count, szVoteId, charsmax(szVoteId));
menu_additem(tempid, szName, szVoteId, 0);
player_added[tempid] = true;
gVoteID[voteid_count] = get_user_userid(tempid);
voteid_count++;
}
}
for (new i; i<pnum; i++)
{
tempid = players[i];
menu_display(tempid, gVoteMenu, 0);
if ( is_user_admin(tempid))
{
gVoting += WEIGHT_ADMIN;
}
else
{
gVoting += WEIGHT_PLAYER;
}
}
set_task(10.0, "EndVote");
return PLUGIN_HANDLED;
}
public menu_handler(id, gVoteMenu, item)
{
if (item == MENU_EXIT || !gVoting)
{
return PLUGIN_HANDLED;
}
new szData[6], szName[64];
new item_access, item_callback;
menu_item_getinfo(gVoteMenu, item, item_access, szData, charsmax(szData), szName, charsmax(szName), item_callback);
new voteid_num = str_to_num(szData);
if (is_user_admin(id))
{
gVotes[voteid_num] += WEIGHT_ADMIN;
}
else
{
gVotes[voteid_num] += WEIGHT_PLAYER;
}
return PLUGIN_HANDLED;
}
public EndVote(id)
{
new votes_selected;
new votes[3];
new voteid[3];
new i, j;
for (i=0; i<MAX_VOTEIDS; i++)
{
if (gVotes[i])
{
if (votes_selected < 3)
{
votes[votes_selected] = gVotes[i];
voteid[votes_selected] = i;
votes_selected++;
}
else
{
for (j=0; j<3; j++)
{
if ( votes[j] < gVotes[i])
{
votes[j] = gVotes[i];
voteid[j] = i;
break;
}
}
}
}
}
if (!votes_selected)
{
client_print(0, print_chat, "No one voted!");
}
else if (votes_selected == 1)
{
new player = find_player("k", voteid[0]);
VoteGiveHealth(player);
}
else if (votes_selected == 2)
{
if (votes[0] == votes[1])
{
client_print(0, print_chat, "Vote has tied. Choosing random from tied votes.");
new player = find_player("k", voteid[random(2)]);
VoteGiveHealth(player);
}
else if (votes[0] > votes[1])
{
new player = find_player("k", voteid[0]);
VoteGiveHealth(player);
}
else
{
new player = find_player("k", voteid[1]);
VoteGiveHealth(player);
}
}
else
{
new player = find_player("k", voteid[random(MAX_VOTEIDS)]);
client_print(0, print_chat, "Could nt determinate a winner.Selecting random");
VoteGiveHealth(player);
}
menu_destroy(gVoteMenu);
gVoting = 0;
}
VoteGiveHealth(id)
{
if (is_user_alive(id))
{
set_user_health(id, 255);
new szName[32];
get_user_name(id, szName, charsmax(szName));
client_print(0, print_chat, "%s got 255 health", szName);
}
}
Please help me!
__________________