Raised This Month: $ Target: $400
 0% 

What is the problem of this plugin?


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Dark_Siders
Member
Join Date: Aug 2013
Location: Dreaming World
Old 09-18-2013 , 03:23   What is the problem of this plugin?
Reply With Quote #1

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(idszNamecharsmax(szName));
    
client_print(idprint_chat"%s be patience.There is already a vote going."szName);
    return 
PLUGIN_HANDLED;
  }
  
arrayset(gVotes0sizeof gVotes);
  
  
gVoteMenu menu_create("\Which player should get 255 health?""menu_handler");
  
  new 
players[32], pnumtempid;
  
get_players(playerspnum"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(tempidszNamecharsmax(szName));
      
num_to_str(voteid_countszVoteIdcharsmax(szVoteId));
      
menu_additem(tempidszNameszVoteId0);
      
player_added[tempid] = true;
      
gVoteID[voteid_count] = get_user_userid(tempid);
      
voteid_count++;
    }
  }
  
  for (new 
ii<pnumi++)
  {
    
tempid players[i];
    
menu_display(tempidgVoteMenu0);
    
    if ( 
is_user_admin(tempid))
    {
      
gVoting += WEIGHT_ADMIN;
    }
    else
    {
      
gVoting += WEIGHT_PLAYER;
    }
  }
  
set_task(10.0"EndVote");
  return 
PLUGIN_HANDLED;
}

public 
menu_handler(idgVoteMenuitem)
{
  if (
item == MENU_EXIT || !gVoting)
  {
    return 
PLUGIN_HANDLED;
  }
  
  new 
szData[6], szName[64];
  new 
item_accessitem_callback;
  
menu_item_getinfo(gVoteMenuitemitem_accessszDatacharsmax(szData), szNamecharsmax(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 
ij;
  
  for (
i=0i<MAX_VOTEIDSi++)
  {
    if (
gVotes[i])
    {
      if (
votes_selected 3)
      {
        
votes[votes_selected] = gVotes[i];
        
voteid[votes_selected] = i;
        
        
votes_selected++;
      }
      else
      {
        for (
j=0j<3j++)
        {
          if ( 
votes[j] < gVotes[i])
          {
            
votes[j] = gVotes[i];
            
voteid[j] = i;
            
            break;
          }
        }
      }
    }
  }
  
  if (!
votes_selected)
  {
    
client_print(0print_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(0print_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(0print_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(id255);
    new 
szName[32];
    
get_user_name(idszNamecharsmax(szName));
    
client_print(0print_chat"%s got 255 health"szName);
  }

Please help me!
__________________
***********
I want to die peacefully in my sleep like my grandfather, not screaming in terror like his passengers.

***********
Dark_Siders is offline
 



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 19:06.


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