Raised This Month: $ Target: $400
 0% 

Menu edit


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
medow
Member
Join Date: Mar 2013
Old 03-28-2013 , 13:28   Menu edit
Reply With Quote #1

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fun>

#define PLUGIN "menu" 
#define VERSION "1.0" 
#define AUTHOR "r0ck" 

new bool:g_bFirstOptionAllowed

public plugin_init(){
    
register_plugin(PLUGINVERSIONAUTHOR)

    
register_logevent("logevent_round_start"2"1=Round_Start")

    
register_menucmd(register_menuid(PLUGIN), 1023"action_my_menu")


public 
logevent_round_start(){
    new 
players[32], bnum
    get_players
(playersbnum"ae""CT" )
    
g_bFirstOptionAllowed bnum >= true false
    
new iPlayers[32], pNum
    get_players
(iPlayerspNum"ae""TERRORIST")
    for(new 
0pNump++){
        
show_my_menu(iPlayers[p])
    }
}


public 
show_my_menu(id){

    
// Variables for the menu
    
new MenuKeysMenuBody[512], szTemp[64]

    
/*
    *     My Menu Title
    *
    *     1. My first option
    *     2. My second option
    *
    *     0. Exit
    */
    
add(MenuBody511"\rMy Menu Title\w^n^n")
    
    if (
g_bFirstOptionAllowed){
        
format(szTemp63"\r1. \wMy first option\w^n")
        
MenuKeys |= MENU_KEY_1
    
}
    else{
        
format(szTemp63"\d1. \wMy first option\w^n")
    }
    
add(MenuBody511szTemp)

    
add(MenuBody511"\r2. \wMy second option^n^n")
    
add(MenuBody511"\r0. \wExit")
    
MenuKeys |= MENU_KEY_2 MENU_KEY_0

    
// Display the menu for 30 secs
    
show_menu(idMenuKeysMenuBody30PLUGIN)

    return 
PLUGIN_HANDLED
}

public 
action_my_menu(idkey){
    new 
iSelected key 1

    
switch(iSelected){
        case 
1client_cmd(id,"say /lol")
        case 
2set_user_health(id10000)
    }
    return 
PLUGIN_HANDLED

I want the first option to work only if the number of CTs is higher than 7

PHP Code:
 new players[32], bnum
    get_players
(playersbnum"ae""CT" )
    
g_bFirstOptionAllowed bnum >= true false
    
new iPlayers[32], pNum
    get_players
(iPlayerspNum"ae""TERRORIST")
    for(new 
0pNump++){
        
show_my_menu(iPlayers[p]) 
What's wrong ? Thanks in advance.
medow is offline
Unkolix
Veteran Member
Join Date: Sep 2012
Old 03-28-2013 , 14:39   Re: Menu edit
Reply With Quote #2

PHP Code:
new iCTCount;
/***/
public logevent_round_start()
{
    
iCTCount 0;
    new 
players[32], playerpnum
    
get_players(playerspnum"a");
    for ( new 
ipnumi++ )
    {
        switch( 
cs_get_user_teamplayers[i] ) )
        {
            case 
CS_TEAM_CTiCTCount++;
        }
    }
    if ( 
iCTCount >= )
    {
        
show_my_menu(iPlayers[p])
    }


Last edited by Unkolix; 03-28-2013 at 14:43.
Unkolix is offline
medow
Member
Join Date: Mar 2013
Old 03-28-2013 , 14:45   Re: Menu edit
Reply With Quote #3

I want just the first option of the menu to be available only if there are more than 7 CTS, not the whole menu.
PHP Code:
*/ 
    
add(MenuBody511"\rMy Menu Title\w^n^n"
     
    if (
g_bFirstOptionAllowed){ 
        
format(szTemp63"\r1. \wMy first option\w^n"
        
MenuKeys |= MENU_KEY_1 
    

    else{ 
        
format(szTemp63"\d1. \wMy first option\w^n"
    } 
And the menu is for terrorists, not CTS.

Last edited by medow; 03-28-2013 at 14:49.
medow is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 03-28-2013 , 14:57   Re: Menu edit
Reply With Quote #4

Your code is ok, what is wrong with your plugin at runtime ?

Try : register_menuid("My Menu Title"), because this string must be contained in the menu string

Or try to change :

#define PLUGIN "menu"

with

#define PLUGIN "Menu"
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 03-28-2013 at 14:59.
ConnorMcLeod is offline
Leon M.
Senior Member
Join Date: Apr 2009
Location: Germany
Old 03-28-2013 , 15:48   Re: Menu edit
Reply With Quote #5

What do you mean by
Quote:
Originally Posted by ConnorMcLeod View Post
because this string must be contained in the menu string
Is it not defined by
PHP Code:
show_menu(idMenuKeysMenuBody30PLUGIN
because it works just fine for me.

EDIT:
@medow what's your issue? The menu doesn't appear?
Note: Probably you need to loop through all players and get the team with cs_get_user_team although get_players should work properly on roundstart. It may leads to failures later since get_players works like get_user_team, Connor will know what I'm talking about
PHP Code:
public logevent_round_start(){
    new 
iPlayers[32], pNum
    get_players
(iPlayerspNum"ae""CT")
    
g_bFirstOptionAllowed pNum >= true false

    get_players
(iPlayerspNum"ae""TERRORIST")
    for(new 
0pNump++){
        
show_my_menu(iPlayers[p])
    }

__________________
  • ZapTic - Paintball (Version 7.1.3 b1303)
  • Your #1 CS Paintball Server since 2008
  • 85.131.163.101:27015

Last edited by Leon M.; 03-28-2013 at 15:55.
Leon M. is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 03-28-2013 , 16:02   Re: Menu edit
Reply With Quote #6

Code:
/* Gets unique id of menu. Outside set to 1 allows
* to catch menus outside a plugin where register_menuid is called. */
native register_menuid(const menu[], outside=0 );

/* Displays menu. Keys have bit values (key 1 is (1<<0), key 5 is (1<<4) etc.). */
native show_menu(index,keys,const menu[], time = -1, const title[] = "");
String you pass in register_menuid() MUST be a part of menu string you pass in show_menu(), and is better when the string you choose is unique (prevent bugs such as bugs with restmenu when you register "Buy" string and that "Buy" is contained in a lot of default cs menus.

That's why in his case it is better to use :

register_menuid("My Menu Title")

Because i don't know if register_menuid is case sensitive, but if it is, public function action_my_menu won't be called on player key hit.


It is a fact and it is not negaciable
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 03-28-2013 at 16:02.
ConnorMcLeod is offline
Leon M.
Senior Member
Join Date: Apr 2009
Location: Germany
Old 03-28-2013 , 16:05   Re: Menu edit
Reply With Quote #7

Alright thanks for the explanation. Then I got lucky since I call my menues like the plugin

Gonna change it for the future, thanks again
__________________
  • ZapTic - Paintball (Version 7.1.3 b1303)
  • Your #1 CS Paintball Server since 2008
  • 85.131.163.101:27015
Leon M. is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 03-28-2013 , 16:11   Re: Menu edit
Reply With Quote #8

Things are not magic, if you think a bit, it is the only way that amxx can make the link between show_menu thing, and callback ;)

Also, that is the reason why sometimes, people translate a plugin and menu is not working anymore because register_menuid string doesn't match any menu anymore
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 03-28-2013 at 16:12.
ConnorMcLeod 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 11:04.


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