Raised This Month: $51 Target: $400
 12% 

New menu wierd acts


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
pokemonmaster
princess milk
Join Date: Nov 2010
Location: Somewhere in this world
Old 08-23-2014 , 05:24   New menu wierd acts
Reply With Quote #1

So I have came back to coding (temporarily) from a long time and I have wrote a plugin for a friend of mine.

The problem is, the menu acts so weird.
First, if i choose an option from the menu, it makes the others like they have automatically chose something. so they can't choose anything after I have clicked an option.

Secondly, the menu sometimes destroys it self, without any function making it to do that.

Thirdly, there is a weird error that comes and i don't know why.
Code:
L 08/23/2014 - 05:14:19: Invalid player id 0
L 08/23/2014 - 05:14:19: [AMXX] Displaying debug trace (plugin "test.amxx", version "1.0")
L 08/23/2014 - 05:14:19: [AMXX] Run time error 10: native error (native "player_menu_info")
L 08/23/2014 - 05:14:19: [AMXX]    [0] test.sma::MenuHandler_Gaurds (line 187)

also for this one, I have disabled the exit button for this but, it still shows.
Code:
L 08/23/2014 - 05:10:18: Plugin called menu_display when item=MENU_EXIT
L 08/23/2014 - 05:10:18: [AMXX] Displaying debug trace (plugin "test.amxx", version "1.0")
L 08/23/2014 - 05:10:18: [AMXX] Run time error 10: native error (native "menu_display")
L 08/23/2014 - 05:10:18: [AMXX]    [0] test.sma::MenuHandler_Gaurds (line 253)


Here is the plugin
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <colorchat>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

// --| Delay after map start to start the vote.
#define START_TIME 20.0
#define g_flPlayerPercent 0.75

#define TIMER_COUNT 10

#define GREEN 0

new const PREFIX[] = "^4[AMXX]"

// --| Don't Edit
new const TASKID_VOTE_MAP_START 187515;
new const 
TASKID_COUNTER 19715781

// --| The menu which says choose ct amount
new const VOTE_CT_AMOUNT[] = { 123};

// --| Don't edit.
enum VOTE_TYPE
{
    
VOTE_NONE,
    
VOTE_AMOUNT,
    
VOTE_CHOOSE,
    
VOTE_MAP_START
};

new 
VOTE_TYPE:g_iVoteRunning VOTE_NONE;
new 
g_iHasVoted[33];
new 
g_iVotes;

new 
g_iTimer
new g_iPlayerVotes[33]

new 
g_iGaurdAmount;
new 
g_iCurrGaurdAmount;

new 
g_iMenu;

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
    
register_event("TeamInfo""Event_TeamInfo""a""2=CT");
    
    
register_clcmd("say /votect""CmdVoteCT");
    
    
g_iVoteRunning VOTE_MAP_START;
    
set_task(20.0"StartVoting"TASKID_VOTE_MAP_START);
}

public 
Event_TeamInfo()
{
    static 
idid read_data(1);
    
client_disconnect(id);
}

public 
client_disconnect(id)
{
    if(
g_iHasVoted[id])
    {
        
g_iHasVoted[id] = 0;
        --
g_iVotes;
    }
}

public 
CmdVoteCT(id)
{
    static 
iPlayers[32], iNum;
    
    if(!
CanVote(id))
    {
        return;
    }
    
    
g_iHasVoted[id] = 1;
    
    
get_players(iPlayersiNum"e""TERRORIST");
    
    if( ++
g_iVotes < (iNum floatroundg_flPlayerPercent float(iNum) ) ) )
    {
        
server_print("g_iVotes = %d"g_iVotes);
        
server_print("%d"floatroundg_flPlayerPercent float(iNum) ) )
        
ColorChat(0GREEN"%s ^3%d Players ^1are still needed to vote."PREFIXiNum g_iVotes);
        
        return;
    }

    
g_iVotes 0;
    
arrayset(g_iHasVoted0sizeof(g_iHasVoted));
    
arrayset(g_iPlayerVotes0sizeof(g_iPlayerVotes));
    
    
g_iTimer TIMER_COUNT 1;
    
ColorChat(0GREEN"%s ^3VOTE SUCCEEDED ^1and will start in %d seconds!"PREFIXg_iTimer 1);
    
StartVoting();
}

public 
StartVoting()
{
    
g_iVoteRunning VOTE_AMOUNT
    g_iTimer 
TIMER_COUNT 1;
    
    
VoteWillRunCounter(TASKID_COUNTER);
    
set_task(1.0"VoteWillRunCounter"TASKID_COUNTER,_,_"a"g_iTimer);
}

public 
VoteWillRunCounter(iTaskId)
{
    if(!--
g_iTimer)
    {
        new 
iPlayers[32], iNum;
        
get_players(iPlayersiNum);
        
        if(!
iNum)
        {
            return;
        }
        
        
g_iVoteRunning VOTE_AMOUNT;
        
        new 
g_iMenu menu_create("Choose amount of Gaurds""MenuHandler_Gaurds");
        
        
menu_setprop(g_iMenuMPROP_EXITMEXIT_NEVER);
        new 
iiPlayer
        
for(new szItem[13]; sizeof VOTE_CT_AMOUNTi++)
        {
            
formatex(szItemcharsmax(szItem), "%d (%%0)"VOTE_CT_AMOUNT[i]);
            
menu_additem(g_iMenuszItem);
        }
        
        for(
0iNumi++)
        {
            
iPlayer iPlayers[i];
            
            switch(
cs_get_user_team(iPlayer))
            {
                case 
CS_TEAM_CT:
                {
                    
cs_set_user_team(iPlayerCS_TEAM_T);
                }
                
                case 
CS_TEAM_UNASSIGNED:
                {
                    continue;
                }
                
                case 
CS_TEAM_SPECTATOR:
                {
                    continue;
                }
            }
            
            
menu_display(iPlayerg_iMenu);
        }
        
        
set_task(15.0"CalcWinner");
    }
    
    else
    {
        new 
szNumWord[7];
        
num_to_word(g_iTimerszNumWord6);
        
        
client_cmd(0"spk ^"fvox/%s", szNumWord);
    }
}

public MenuHandler_Gaurds(id, menu, item)
{
    if(g_iVoteRunning == VOTE_NONE)
    {
        DestroyMenu()
        return;
    }
    
    new iOldPage, iDump;
    player_menu_info(id, iDump, iDump, iOldPage);
    if(g_iHasVoted[id])
    {
        if(g_iMenu != -1)
        {
            menu_display(id, menu, iOldPage);
        }
        
        return;
    }
    
    new szName[32]
    get_user_name(id, szName, charsmax(szName))
    
    g_iHasVoted[id] = 1;
    /*if(item == MENU_EXIT)
    {
        server_print("
Here");
        ColorChat(id, GREEN, "
%^3%^1chose not to vote.", PREFIX, szName);
        
        menu_display(id, menu, iOldPage);
        return;
    }*/
    
    ++g_iVotes
    new szItemName[32];
    
    switch(g_iVoteRunning)
    {
        case VOTE_NONE:
        {
            DestroyMenu();
            return;
        }
        
        case VOTE_AMOUNT:
        {
            ++g_iPlayerVotes[item]
    
            formatex(szItemName, charsmax(szItemName), "
%(%%%d)", VOTE_CT_AMOUNT[item], ( g_iPlayerVotes[item] / g_iVotes )  * 100)
            ColorChat(0, GREEN, "
%^3%^1chose ^3%^1as amount of ^3Gaurds.", PREFIX, get_player_name(id), VOTE_CT_AMOUNT[item]);
        }
        
        case VOTE_CHOOSE:
        {
            new szInfo[6], iDump;
            menu_item_getinfo(menu, item, iDump, szInfo, charsmax(szInfo),_,_, iDump);
            
            new iVotedPlayerID  = str_to_num(szInfo);
            ++g_iPlayerVotes[iVotedPlayerID];
            
            new szVoterName[32], szVotedName[32];
            get_user_name(id, szVoterName, 31);
            
            formatex(szItemName, charsmax(szItemName), "
%(%%%d)", get_player_name(iVotedPlayerID, szVotedName), ( g_iPlayerVotes[iVotedPlayerID] / g_iVotes ) * 100)
            
            ColorChat(0, GREEN, "
%^3%^1chose ^3%^1as ^3Gaurd.", PREFIX, szVoterName, szVotedName);
        }
    }
    
    menu_item_setname(menu, item, szItemName);
    
    new iPlayers[32], iNum;
    get_players(iPlayers, iNum, "
e", "TERRORIST");
    
    for(new i; i < iNum; i++)
    {
        player_menu_info(iPlayers[i], iDump, iDump, iOldPage);
        menu_display(iPlayers[i], menu, iOldPage);
    }
}

public CalcWinner()
{
    DestroyMenu()
    
    new iArray[33][2], i
    for(i = 0; i < 33; i++)
    {
        iArray[i][0] = g_iPlayerVotes[i]
        iArray[i][1] = i
    }
    
    switch(g_iVoteRunning)
    {
        // |||| ---------------------------------------------||||
        // |||| ---------------------------------------------||||
        // |||| ---------------  Vote_Amount  ---------------||||
        // |||| ---------------------------------------------||||
        // |||| ---------------------------------------------||||
        case VOTE_AMOUNT:
        {
            SortCustom2D(iArray, sizeof VOTE_CT_AMOUNT, "
SortingFunc")
    
            new iSame
            for(i = 1; i < sizeof( VOTE_CT_AMOUNT ); i++)
            {
                if(iArray[0][0] == iArray[i][0])
                {
                    ++iSame;
                    continue;
                }
                
                break;
            }
            
            new iWinner;
            if(iSame)
            {
                iWinner = random(iSame + 1);
                ColorChat(0, GREEN, "
%^1Vote ended with a tieChoosing a random number.", PREFIX);
            }
            
            new iPlayers[32], iNum;
            get_players(iPlayers, iNum, "
e", "TERRORIST");
            
            g_iGaurdAmount = VOTE_CT_AMOUNT[iArray[iWinner][1]];
            
            if(g_iGaurdAmount >= iNum)
            {
                g_iGaurdAmount = iNum - 1;
                server_print( " 
iNum == %d", iNum);
                server_print( " 
GaurdAmount == %d", g_iGaurdAmount);
                
                if(!g_iGaurdAmount)
                {
                    StopVote();
                    
                    cs_set_user_team(iPlayers[0], CS_TEAM_CT);
                    return;
                }
                    
                ColorChat(0, GREEN, "
%^3VOTE HAS ENEDED. ^1Choosen ^3Gaurds ^1number is more than current joined players.", PREFIX);
                ColorChat(0, GREEN, "
%^1Changing choosen ^3Gaurds amount ^1to ^3%d.", PREFIX, g_iGaurdAmount);
            }
            
            else    ColorChat(0, GREEN, "
%^3VOTE HAS ENEDED. ^1There will be ^3%d Gaurds. ^1(Won by %d votes).", PREFIX, g_iGaurdAmount , iArray[iWinner][0]);
            
            g_iCurrGaurdAmount = 0;
            set_task(2.0, "
StartPlayersVote");
        }
        
        // |||| ---------------------------------------------||||
        // |||| ---------------------------------------------||||
        // |||| ---------------  Vote_Choose  ---------------||||
        // |||| ---------------------------------------------||||
        // |||| ---------------------------------------------||||
        case VOTE_CHOOSE:
        {
            SortCustom2D(iArray, sizeof(iArray), "
SortingFunc");
            
            new iSame = 1
            for(i = 1; i < sizeof( VOTE_CT_AMOUNT ); i++)
            {
                if(iArray[0][0] == iArray[i][0])
                {
                    ++iSame
                    continue;
                }
                
                break;
            }
            
            new iPlayers[32], iNum;
            get_players(iPlayers, iNum, "
e", "TERRORIST");
            
            if(!iNum)
            {
                StopVote();
                return;
            }
            
            new iWinner, iCount;
            
            for(new i; i < iSame; i ++)
            {
                if(is_user_connected(iArray[i][1]))
                {
                    iCount++
                    if(random_num(0, 1))
                    {
                        iWinner = iArray[i][1];
                        break;
                    }
                }
            }
            
            if(!iWinner)
            {
                if(iCount)
                {
                    while( ( iWinner = iArray[random(iSame)][1] ) )
                    {
                        if(is_user_connected(iWinner))
                        {
                            break;
                        }
                    }
                }
                    
                else 
                {
                    for(new i = iSame; i < sizeof iArray; i++)
                    {
                        if(is_user_connected(iArray[i][1]))
                        {
                            iWinner = iArray[i][1];
                            break;
                        }
                    }
                }
            }
                
            ColorChat(0, GREEN,
            iSame > 1 ? "
%^1Vote ended with a tieChoosing a random player." : "%^3%^1will be a ^3Gaurd.",
            PREFIX, get_player_name(iWinner));
            
            cs_set_user_team(iWinner, CS_TEAM_CT);
            
            ++g_iCurrGaurdAmount
            
            // Make sure there is atleast 1 TERRORIST
            if( (iNum - 1 ) == 1)
            {
                ColorChat(0, GREEN, "
%^1Stopped voting to make sure there are terrorists left.", PREFIX);
                StopVote();
                return;
            }
            
            if(g_iCurrGaurdAmount < g_iGaurdAmount)
            {
                set_task(1.0, "
StartPlayersVote");
            }
            
            else
            {
                StopVote()
                server_cmd("
sv_restart 1")
                
                user_kill(iPlayers[0]);
            }    
        }
    }
}

StopVote()
{
    g_iVoteRunning = VOTE_NONE
    if(task_exists(TASKID_VOTE_MAP_START))
    {
        remove_task(TASKID_VOTE_MAP_START);
    }
    
    if(task_exists(TASKID_COUNTER))
    {
        remove_task(TASKID_COUNTER);
    }
    
    server_cmd("
sv_restart 1")
}

public StartPlayersVote()
{
    g_iVotes = 0
    arrayset(g_iHasVoted, 0, 33);
    arrayset(g_iPlayerVotes, 0, 33);
    
    g_iVoteRunning = VOTE_CHOOSE
    DoPlayersMenu()
}

DoPlayersMenu()
{
    new iPlayers[32], iPlayer, iNum, i, szInfo[4], szItemName[40];
    get_players(iPlayers, iNum, "
e", "TERRORIST");
    
    g_iMenu = menu_create(GetGaurdPosTitle(), "
MenuHandler_Gaurds")
    menu_setprop(g_iMenu, MPROP_EXIT, MEXIT_NEVER);
    
    for(i = 0; i < iNum; i++)
    {
        iPlayer = iPlayers[i];
        
        formatex(szItemName, charsmax(szItemName), "
%(%%0)", get_player_name(iPlayer));
        num_to_str(iPlayer, szInfo, charsmax(szInfo));
        
        menu_additem(g_iMenu, szItemName, szInfo);
    }
    
    for(i = 0; i < iNum; i++)
    {
        menu_display(iPlayers[i], g_iMenu);
    }
    
    set_task(16.0, "
CalcWinner") 
}

GetGaurdPosTitle()
{
    new iGaurdNum = g_iCurrGaurdAmount + 1;
    new iNew;
    
    new szTitle[40];
    
    if(iGaurdNum > 10)
    {
        iNew = iGaurdNum % 10;
    }
    
    new szPos[6]
    switch(iNew)
    {
        case 1:        szPos = "
st";
        case 2:        szPos = "
nd";
        case 3:        szPos = "
rd";
        default:    szPos = "
th";
    }
    
    formatex(szTitle, charsmax(szTitle), "
Choose the %d%s Gaurd.", iGaurdNum, szPos);
    
    return szTitle;
}

public SortingFunc(iEntry1[], iEntry2[])
{
    if(iEntry1[0] > iEntry2[0])
    {
        return -1;
    }
    
    if(iEntry1[0] < iEntry2[0])
    {
        return 1;
    }
    
    return 0;
}

CanVote(id)
{
    if(g_iVoteRunning)
    {
        ColorChat(id, GREEN, "
%^3Vote ^1is already running or will run.", PREFIX);
        return 0;
    }
    
    if(cs_get_user_team(id) == CS_TEAM_CT)
    {
        ColorChat(id, GREEN, "
%^3Gaurds ^1can't vote.", PREFIX);
        return 0;
    }
    
    /*get_players(iCTPlayers, iNum, "e", "CT");
    
    if(iNum)
    {
        ColorChat(id, GREEN, "%s ^1The ^3Gaurds team must be empty to vote.", PREFIX);
        return 0;
    }*/
    
    if(g_iHasVoted[id])
    {
        ColorChat(id, GREEN, "%s ^1You have already ^3voted.", PREFIX);
        new iPlayers[32], iNum;
        get_players(iPlayers, iNum, "e", "TERRORIST");
    
        server_print("iNum = %d", iNum);
        
        server_print("g_iVotes = %d", g_iVotes);
        
        iNum = floatround( g_flPlayerPercent * float(iNum) )
        
        server_print("%d", floatround( g_flPlayerPercent * float(iNum) ) )
        ColorChat(id, GREEN, "%s ^3%d players ^1are still needed to start the vote.", PREFIX, iNum - g_iVotes);
        return 0;
    }
    
    return 1;
}

get_player_name(id, szName[32] = "")
{
    get_user_name(id, szName, 31);
    return szName;
}

DestroyMenu()
{
    new iPlayers[32], iNum;
    get_players(iPlayers, iNum);
    
    /*for(new i, iMenu, iDump, iPlayer; i < iNum; i++)
    {
        iPlayer = iPlayers[i];
        
        player_menu_info(iPlayer, iDump, iMenu, iDump);
        
        if(iMenu == g_iMenu)
        {
            menu_cancel(iPlayer);
        }
    }*/
    
    menu_destroy(g_iMenu);
    client_cmd(0, "slot0");
    
    g_iMenu = -1;
    
    arrayset(g_iHasVoted, 0, 33);

I know that I didn't provide many information but, that's all what I could provide as I have no idea why these happen.

In hope for help I ask.
Attached Files
File Type: sma Get Plugin or Get Source (test.sma - 452 views - 12.0 KB)
__________________
اَشْهَدُ اَنْ لَّآ اِلٰهَ اِلَّا اللہُ وَحْدَه لَا شَرِيْكَ لَه وَ اَشْهَدُ اَنَّ مُحَمَّدًا عَبْدُه وَرَسُوْلُه
No longer active in AMXX. Sorry.
pokemonmaster is offline
bat
Veteran Member
Join Date: Jul 2012
Old 08-23-2014 , 06:40   Re: New menu wierd acts
Reply With Quote #2

Just check if client is connected :/
__________________
bat is offline
Send a message via Skype™ to bat
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 08-23-2014 , 10:36   Re: New menu wierd acts
Reply With Quote #3

Code:
client_cmd(0, "spk ^"fvox/%s", szNumWord);

I have the feeling that you miss a " there.
__________________
Kia is offline
pokemonmaster
princess milk
Join Date: Nov 2010
Location: Somewhere in this world
Old 08-23-2014 , 13:57   Re: New menu wierd acts
Reply With Quote #4

Quote:
Originally Posted by bat View Post
Just check if client is connected :/
if a menu handler was called upon a player, he should be connected.

That's why I'm asking why these errors come.


Quote:
Originally Posted by Kia View Post
Code:
client_cmd(0, "spk ^"fvox/%s", szNumWord);


I have the feeling that you miss a " there.
That would not make the menus do all of this ... and the second one is not really important
__________________
اَشْهَدُ اَنْ لَّآ اِلٰهَ اِلَّا اللہُ وَحْدَه لَا شَرِيْكَ لَه وَ اَشْهَدُ اَنَّ مُحَمَّدًا عَبْدُه وَرَسُوْلُه
No longer active in AMXX. Sorry.
pokemonmaster is offline
NikKOo31
Senior Member
Join Date: May 2013
Location: Home
Old 08-23-2014 , 14:23   Re: New menu wierd acts
Reply With Quote #5

Add a client print in the handler and show the value of 'item'
If it is -3 (MENU_EXIT) then you should destroy the menu
__________________
Hey ^_^
NikKOo31 is offline
pokemonmaster
princess milk
Join Date: Nov 2010
Location: Somewhere in this world
Old 08-23-2014 , 14:52   Re: New menu wierd acts
Reply With Quote #6

Quote:
Originally Posted by NikKOo31 View Post
Add a client print in the handler and show the value of 'item'
If it is -3 (MENU_EXIT) then you should destroy the menu
I don't want to do that cause it's a menu for all players (actually, it's a vote menu, and it should not be destroyed except after the voting has been done and it is time to calculate the winner.)
__________________
اَشْهَدُ اَنْ لَّآ اِلٰهَ اِلَّا اللہُ وَحْدَه لَا شَرِيْكَ لَه وَ اَشْهَدُ اَنَّ مُحَمَّدًا عَبْدُه وَرَسُوْلُه
No longer active in AMXX. Sorry.
pokemonmaster is offline
NikKOo31
Senior Member
Join Date: May 2013
Location: Home
Old 08-23-2014 , 14:59   Re: New menu wierd acts
Reply With Quote #7

Quote:
Originally Posted by pokemonmaster View Post
I don't want to do that cause it's a menu for all players (actually, it's a vote menu, and it should not be destroyed except after the voting has been done and it is time to calculate the winner.)
Doesn't matter what it is for, if item == -3 and you show the menu again you will keep getting that error. Add the client print and check the value of item.
__________________
Hey ^_^
NikKOo31 is offline
pokemonmaster
princess milk
Join Date: Nov 2010
Location: Somewhere in this world
Old 08-23-2014 , 15:01   Re: New menu wierd acts
Reply With Quote #8

Quote:
Originally Posted by NikKOo31 View Post
Doesn't matter what it is for, if item == -3 and you show the menu again you will keep getting that error. Add the client print and check the value of item.
If you look closly at the code, I have disabled the Exit option from the menu. So, item should never be -3
__________________
اَشْهَدُ اَنْ لَّآ اِلٰهَ اِلَّا اللہُ وَحْدَه لَا شَرِيْكَ لَه وَ اَشْهَدُ اَنَّ مُحَمَّدًا عَبْدُه وَرَسُوْلُه
No longer active in AMXX. Sorry.
pokemonmaster is offline
Nextra
Veteran Member
Join Date: Apr 2008
Location: Germany
Old 08-23-2014 , 15:45   Re: New menu wierd acts
Reply With Quote #9

  • Disabling the exit option does not mean the handler can not receive MENU_EXIT:
    • You execute menu_cancel() on clients, which will pass the MENU_EXIT code to the menu handler.
    • Calling menu_destroy() on a menu handle also results in the core effectively calling menu_cancel() on all clients still having the menu open, all resulting in a MENU_EXIT code.
    • If a client disconnects while a menu displayed core will fire MENU_EXIT to the menu handler. So you have to check if a client is still connected if you receive MENU_EXIT.
    • Other menus can override the currently displayed menu, which will also fire MENU_EXIT
  • Every menu handler is absolutely required to handle MENU_EXIT, and it should always be the very first thing to be handled. Most of your problems come up only because you do not.
  • If you like you can use the AMXX 1.8.3 dev builds which have introduced automatic menu timeouts on newmenus.
    • AMXX 1.8.3 also introduces a native color chat function and a special %n format option that will automatically insert the player name.
  • Be careful with switching a large amount of clients to another team within a single frame, it can crash your server.
__________________
In Flames we trust!

Last edited by Nextra; 08-23-2014 at 15:50.
Nextra is offline
Reply



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 13:30.


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