Raised This Month: $ Target: $400
 0% 

What is the problem of this plugin?


Post New Thread Reply   
 
Thread Tools Display Modes
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
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 09-18-2013 , 12:52   Re: What is the problem of this plugin?
Reply With Quote #2

menu_additem(gVoteMenu, szName, szVoteId, 0);

Also you need to limit the time that the menu is displayed. Matching the time of set_task(10.0, "EndVote").
This is done by calling menu_cancel(player) for all players that haven't voted in the EndVote function.
__________________
Black Rose is offline
Dark_Siders
Member
Join Date: Aug 2013
Location: Dreaming World
Old 09-19-2013 , 03:03   Re: What is the problem of this plugin?
Reply With Quote #3

Quote:
Originally Posted by Black Rose View Post
menu_additem(gVoteMenu, szName, szVoteId, 0);
Thanks, I corrected it.

Quote:
Originally Posted by Black Rose View Post
Also you need to limit the time that the menu is displayed. Matching the time of set_task(10.0, "EndVote").
This is done by calling menu_cancel(player) for all players that haven't voted in the EndVote function.
I'm new with scripting and I don't know this case.Please,do that in the code and put it here.

And in the vote menu, when I choose a player it doesn't show the result after 10 seconds and it doesn't set the player's health to 255. What should I do?

Please correct the code.
__________________
***********
I want to die peacefully in my sleep like my grandfather, not screaming in terror like his passengers.

***********
Dark_Siders is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 09-19-2013 , 17:40   Re: What is the problem of this plugin?
Reply With Quote #4

The problem is find_player() doesn't find a match because the argument you send to it is not actually a userid.
The whole vote count needs a rewrite. I can't really understand how the code works as it is. Try looking at some other plugins.

I can do a rewrite of the plugin this weekend if you want.
__________________
Black Rose is offline
Cigojlo
Senior Member
Join Date: May 2013
Location: Serbia / Belgrade
Old 09-19-2013 , 19:42   Re: What is the problem of this plugin?
Reply With Quote #5

Quote:
Originally Posted by Black Rose View Post
The problem is find_player() doesn't find a match because the argument you send to it is not actually a userid.
The whole vote count needs a rewrite. I can't really understand how the code works as it is. Try looking at some other plugins.

I can do a rewrite of the plugin this weekend if you want.
Can ustop spaming forum with bullshit if u want to help post code, i saw all ur post, like spaming bot, kid what u want new title
__________________
Quote:
Originally Posted by ghinghis View Post
the fuking TOP.SMA cannot be compiled moron !!!!!
Cigojlo is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-19-2013 , 22:02   Re: What is the problem of this plugin?
Reply With Quote #6

Quote:
Originally Posted by Cigojlo View Post
Can ustop spaming forum with bullshit if u want to help post code, i saw all ur post, like spaming bot, kid what u want new title
I believe that his post was very useful. This is the scripting help section, we generally don't (and shouldn't) do everything for you, we try to help you learn to do it on your own.
__________________
fysiks is offline
Dark_Siders
Member
Join Date: Aug 2013
Location: Dreaming World
Old 09-20-2013 , 03:32   Re: What is the problem of this plugin?
Reply With Quote #7

Quote:
Originally Posted by Black Rose View Post
The problem is find_player() doesn't find a match because the argument you send to it is not actually a userid.
The whole vote count needs a rewrite. I can't really understand how the code works as it is. Try looking at some other plugins.

I can do a rewrite of the plugin this weekend if you want.
OK, I'm new to scripting.So please rewrite this plugin to teach and show me how can I make a better vote menu that works correctly.I will be glad if you rewrite this plugin.I'm waiting for this weekend.

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

***********
Dark_Siders is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 09-20-2013 , 20:11   Re: What is the problem of this plugin?
Reply With Quote #8

Only tested in single player.
If you have any questions, let me know.
Code:
#include <amxmodx> #include <amxmisc> #include <fun> new g_pcvar_playernum,     g_pcvar_health,     g_pcvar_votetime,     g_pcvar_nextvote,     g_pcvar_playerweight,     g_pcvar_adminweight,     g_pcvar_display,     g_pcvar_accessflags; new gVotes[33]; new g_hMenu; public plugin_init() {         register_plugin("Healthvote", "1.0", "[ --{-@ ]");         register_clcmd("say /vote", "StartVote");     register_clcmd("say_team /vote", "StartVote");         g_pcvar_playernum = register_cvar("hv_playernum", "7");     g_pcvar_health = register_cvar("hv_health", "255");     g_pcvar_playerweight = register_cvar("hv_playerweight", "1");     g_pcvar_adminweight = register_cvar("hv_adminweight", "2");     g_pcvar_accessflags = register_cvar("hv_access", "");     g_pcvar_votetime = get_cvar_pointer("amx_vote_time");     g_pcvar_nextvote = get_cvar_pointer("amx_last_voting");     g_pcvar_display = get_cvar_pointer("amx_vote_answers"); } public StartVote(id) {         new name[32];     get_pcvar_string(g_pcvar_accessflags, name, charsmax(name));         if ( ! cmd_access(id, read_flags(name), 0, 0) )         return PLUGIN_CONTINUE;         new Float:gametime = get_gametime();     new Float:nextvote = get_pcvar_float(g_pcvar_nextvote);         if ( gametime < nextvote ) {         get_user_name(id, name, charsmax(name));         gametime = nextvote - gametime;         client_print(id, print_chat, "%s, you have to wait %d more second%s to start a new vote.", name, floatround(gametime, floatround_ceil), gametime > 1.0 ? "s" : "");         return PLUGIN_HANDLED;     }         arrayset(gVotes, 0, sizeof gVotes);         new menuhead[40], players[32], info[3], playersnum, temp;     formatex(menuhead, charsmax(menuhead), "Which player should get %d health?", get_pcvar_num(g_pcvar_health));         new g_hMenu = menu_create(menuhead, "HandleVote");     get_players(players, playersnum, "h");         new maxvoteplayers = get_pcvar_num(g_pcvar_playernum);     if ( playersnum < maxvoteplayers )         maxvoteplayers = playersnum;         for ( new i = 0 ; i < maxvoteplayers ; i++ ) {         temp = random(playersnum - i);         get_user_name(players[temp], name, charsmax(name));                 info[0] = players[temp];         info[1] = get_user_userid(players[temp]);         menu_additem(g_hMenu, name, info);                 players[temp] = players[playersnum - i];     }         get_players(players, playersnum, "h");         for ( new i = 0 ; i < playersnum ; i++ )         menu_display(players[i], g_hMenu);         new Float:votetime = get_pcvar_float(g_pcvar_votetime);     set_pcvar_float(g_pcvar_nextvote, gametime + votetime + 2.0);     set_task(votetime, "EndVote");         return PLUGIN_HANDLED; } public HandleVote(id, menu, item) {         if ( item == MENU_EXIT )         return;         new info[3], temp;     menu_item_getinfo(menu, item, temp, info, charsmax(info), _, _, temp);         if ( ! is_user_connected(info[0]) || info[1] != get_user_userid(info[0]) )         gVotes[info[0]] = 0;     else {         gVotes[info[0]] = is_user_admin(id) ? get_pcvar_num(g_pcvar_adminweight) : get_pcvar_num(g_pcvar_playerweight);                 if ( get_pcvar_num(g_pcvar_display) ) {             new name_voter[32], name_voted[32];             get_user_name(id, name_voter, charsmax(name_voter));             get_user_name(info[0], name_voted, charsmax(name_voted));             client_print(0, print_chat, "%s voted for %s", name_voter, name_voted);         }     } } public EndVote(id) {         new name[32], players[32], playersnum, maxvotecount = 1;     get_players(players, playersnum, "h");         SortCustom1D(players, playersnum, "SortFunc");         while ( maxvotecount < playersnum && is_user_connected(players[maxvotecount]) && gVotes[players[maxvotecount]] == gVotes[players[0]] )         maxvotecount++;         new health = get_pcvar_num(g_pcvar_health);         if ( ! gVotes[players[0]] )         client_print(0, print_chat, "No one voted!");         else if ( maxvotecount == 1 ) {         get_user_name(players[0], name, charsmax(name));         set_user_health(players[0], health);         client_print(0, print_chat, "%s received %d health.", name, health);     }     else {         new message[256] = "Vote has tied between ";         new len = strlen(message);                 for ( new i = 0 ; i < maxvotecount ; i++ ) {                         get_user_name(players[i], name, charsmax(name));             len += copy(message[len], charsmax(message) - len, name);                         if ( i < maxvotecount - 2 )                 len += copy(message[len], charsmax(message) - len, ", ");             else if ( i == maxvotecount - 2 )                 len += copy(message[len], charsmax(message) - len, " & ");         }                 copy(message[len], charsmax(message) - len, ". A random player will be chosen.");         client_print(0, print_chat, message);                 new temp = players[random(maxvotecount)];         get_user_name(temp, name, charsmax(name));         set_user_health(temp, health);         client_print(0, print_chat, "%s was randomly selected and received %d health.", name, health);     }     menu_destroy(g_hMenu); } public SortFunc(elem1, elem2) {     if ( ! is_user_connected(elem1) || gVotes[elem2] > gVotes[elem1] )         return 1;     if ( ! is_user_connected(elem2) || gVotes[elem1] > gVotes[elem2] )         return -1;     return 0; }
__________________

Last edited by Black Rose; 09-21-2013 at 04:46.
Black Rose is offline
Dark_Siders
Member
Join Date: Aug 2013
Location: Dreaming World
Old 09-21-2013 , 03:25   Re: What is the problem of this plugin?
Reply With Quote #9

Thank you!

But as I said I don't know a lot about scripting and I'm beginner.So there are many things in the code that I don't know or it's hard to understand.
I want to learn.So, please give an explanation of the code and why we use this functions or other things like copy , ",", ,get_pcvar_num and etc.
__________________
***********
I want to die peacefully in my sleep like my grandfather, not screaming in terror like his passengers.

***********
Dark_Siders is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 09-21-2013 , 04:51   Re: What is the problem of this plugin?
Reply With Quote #10

I can't explain what every function does. Look in the .inc files for the explanation of them.
I only used amxmodx.inc, amxmisc.inc and fun.inc so it won't be hard to find.
If you're wondering about a specific use, ask again and I'll explain.

I'll try adding some pointers in the code during the day.
__________________
Black Rose is offline
Reply


Thread Tools
Display Modes

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