AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Menu Error (https://forums.alliedmods.net/showthread.php?t=61472)

X-Script 10-01-2007 10:01

Menu Error
 
Hello, how is everybody?

Well i've finished this code and it works and compiles fine but when I bring up the first menu for the radio commands all the sounds go to the correct number, THEN when I hit Continue to go onto the next menu i'll press ONE on the next menu and it'll play the sound from the first menu instead of the second one, how come?

PHP Code:

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Custom Radio Commands"
#define VERSION "1.0"
#define AUTHOR "X-Script"

#define radio_menu (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)|(1<<9)
#define radio_menu1 (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)

new custom_radio


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /radio""C_RADIO")
    
register_clcmd("say /radio1""C_RADIO1")
    
register_concmd("/radio""C_RADIO")
    
register_concmd("/radio1""C_RADIO1")

    
register_menucmd(register_menuid("RADIO"), radio_menu"SelectRadio")
    
register_menucmd(register_menuid("RADIO1"), radio_menu1"SelectRadio1")
    
    
custom_radio register_cvar("amx_newradio""1")
    
}

public 
client_putinserver(id)
{
    
set_task(10.0"connectmessage"id)
}

public 
connectmessage(id)
{
    
client_print(idprint_chat"This server is running Custom Radio Commands by X-Script!")
    
client_print(idprint_chat"Bind two keys to the commands: /radio and /radio1 then press the keys for the Radio Menus")
    return 
PLUGIN_HANDLED
}

public 
plugin_precache()
{
    
precache_sound("RADIO/roger.wav")
    
precache_sound("RADIO/negative.wav")
    
precache_sound("RADIO/go.wav")
    
precache_sound("RADIO/followme.wav")
    
precache_sound("RADIO/stormfront.wav")
    
precache_sound("RADIO/locknload.wav")
    
precache_sound("RADIO/matedown.wav")
    
precache_sound("RADIO/com_reportin.wav")
    
precache_sound("RADIO/fireinhole.wav")
    
precache_sound("RADIO/imhit.wav")
    
precache_sound("RADIO/needbackup.wav")
    
precache_sound("RADIO/position.wav")
    
precache_sound("RADIO/regroup.wav")
    
precache_sound("RADIO/blow.wav")
    
precache_sound("RADIO/clear.wav")
    return 
PLUGIN_HANDLED
}

public 
C_RADIO(id)
{
    
show_menu(idradio_menu"Custom Radio Menu^n^n1. Roger^n2. Negative^n3. Go^n4. Follow Me^n5. Move It^n6. Move Out^n7. Man Down^n8. Status^n9. Fire In Hole^n0. More^n^n", -1"RADIO")
    return 
PLUGIN_HANDLED
}

public 
SelectRadio(idkey)
{
     
/* Radio Commands:
    * 1: Roger
    * 2: Negative
    * 3: Go
    * 4: Follow Me
    * 5: Move It
    * 6: Move Out
    * 7: Man Down
    * 8: Status
    * 9: Fire In Hole
    * 0: More
    * 
    */
    
    
if ( get_pcvar_num(custom_radio) == )
    {
        return 
PLUGIN_HANDLED
    
}
    
    switch(
key)
    {
        case 
0:
        {
            
client_cmd(0,"spk RADIO/roger.wav")
        }
        
        case 
1:
        {
            
client_cmd(0,"spk RADIO/negative.wav")
        }
        
        case 
2:
        {
            
client_cmd(0,"spk RADIO/go.wav")
        }
        
        case 
3:
        {
            
client_cmd(0,"spk RADIO/followme.wav")
        }
        
        case 
4:
        {
            
client_cmd(0,"spk RADIO/stormfront.wav")
        }
        
        case 
5:
        {
            
client_cmd(0,"spk RADIO/locknload.wav")
        }
        
        case 
6:
        {
            
client_cmd(0,"spk RADIO/matedown.wav")
        }
        
        case 
7:
        {
            
client_cmd(0,"spk RADIO/com_reportin.wav")
        }
        
        case 
8:
        {
            
client_cmd(0,"spk RADIO/fireinhole.wav")
        }
        
        case 
9:
        {
            
C_RADIO1(id)
        }
    }
    return 
PLUGIN_HANDLED
}

public 
C_RADIO1(id)
{
    
show_menu(idradio_menu1"Custom Radio Menu^n^n1. Taking Fire^n2. Need Backup^n3. Cover Area^n4. Return Base^n5. Get Down^n6. Clear^n0. Exit^n^n", -1"RADIO1")
    return 
PLUGIN_HANDLED
}

public 
SelectRadio1(idkey)
{
     
/* Radio Commands:
    * 1: Taking Fire
    * 2: Need Backup
    * 3: Cover Area
    * 4: Return Base
    * 5: Get Down
    * 6: Clear
    * 0: Exit
    *
    *
    */
   
    
    
if ( get_pcvar_num(custom_radio) == )
    {
        return 
PLUGIN_HANDLED
    
}
    
    switch(
key)
    {
        case 
0:
        {
            
client_cmd(0,"spk RADIO/imhit.wav")
        }
        
        case 
1:
        {
            
client_cmd(0,"spk RADIO/needbackup.wav")
        }
        
        case 
2:
        {
            
client_cmd(0,"spk RADIO/position.wav")
        }
        
        case 
3:
        {
            
client_cmd(0,"spk RADIO/regroup.wav")
        }
        
        case 
4:
        {
            
client_cmd(0,"spk RADIO/blow.wav")
        }
        
        case 
5:
        {
            
client_cmd(0,"spk RADIO/clear.wav")
        }
        
        case 
6:
        {
        
        }
    }
    return 
PLUGIN_HANDLED



purple_pixie 10-01-2007 11:32

Re: Menu Error
 
Wouldn't it be just a whole lot easier to use the new menu system?

X-Script 10-01-2007 11:32

Re: Menu Error
 
nahh.

purple_pixie 10-01-2007 11:56

Re: Menu Error
 
Really?

I would have thought that
PHP Code:

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Custom Radio Commands"
#define VERSION "1.0"
#define AUTHOR "X-Script"
#define TOTAL_RADIOS 15

new custom_radio;
new 
menu_handle ;
new 
radio_files[TOTAL_RADIOS][]=
{    
    
"RADIO/roger.wav"
    
,"RADIO/negative.wav"
    
,"RADIO/go.wav"
    
,"RADIO/followme.wav"
    
,"RADIO/stormfront.wav"
    
,"RADIO/locknload.wav"
    
,"RADIO/matedown.wav"
    
,"RADIO/com_reportin.wav"
    
,"RADIO/fireinhole.wav"
    
,"RADIO/imhit.wav"
    
,"RADIO/needbackup.wav"
    
,"RADIO/position.wav"
    
,"RADIO/regroup.wav"
    
,"RADIO/blow.wav"
    
,"RADIO/clear.wav"

}
new 
radio_names[TOTAL_RADIOS][]=
{
    
"Roger"
    
,"Negative"
    
,"Go"
    
,"Follow Me"
    
,"Move It"
    
,"Move Out"
    
,"Man Down"
    
,"Status"
    
,"Fire in the Hole"
    
,"Taking Fire"
    
,"Need Backup"
    
,"Cover Area"
    
,"Return to Base"
    
,"Get Down"
    
,"Clear"
}

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /radio""C_RADIO")
    
register_clcmd("say /radio1""C_RADIO1")
    
register_concmd("/radio""C_RADIO")
    
register_concmd("/radio1""C_RADIO1")
   
    
custom_radio register_cvar("amx_newradio""1")  
    
create_menu()
}
create_menu()
{
    
menu_handle menu_create("Radio","SelectRadio")
    for ( new 
TOTAL_RADIOS++ )
    {
        
menu_additem(menu_handle,radio_names[i])
    }
    
menu_setprop(menu_handleMPROP_PERPAGE,9)
    
menu_setprop(menu_handle,MPROP_EXIT,MEXIT_ALL)
}

public 
client_putinserver(id)
{
    
set_task(10.0"connectmessage"id)
}

public 
connectmessage(id)
{
    
client_print(idprint_chat"This server is running Custom Radio Commands by X-Script!")
    
client_print(idprint_chat"Bind two keys to the commands: /radio and /radio1 then press the keys for the Radio Menus")
    return 
PLUGIN_HANDLED
}

public 
plugin_precache()
{
    new 
sound[64];
    for ( new 
TOTAL_RADIOS ++ )
        
precache_sound(sound)
    return 
PLUGIN_HANDLED
}

public 
C_RADIO(id)
{
    
menu_display(id,menu_handle)
    return 
PLUGIN_HANDLED
}

public 
SelectRadio(idmenukey)
{
    if ( 
get_pcvar_num(custom_radio) == )
    {
        return 
PLUGIN_HANDLED
    
}
    if ( 
key == MENU_EXIT )
    {
        return 
PLUGIN_HANDLED ;
    }
    
client_cmd(0,"spk %s",radio_files[key])
    
    return 
PLUGIN_HANDLED ;
}

public 
C_RADIO1(id)
{
    
menu_display(id,menu_handle,1)
        return 
PLUGIN_HANDLED


this is a fair bit simpler and should work fine ... want to try it out?

-Pixie

EDIT: Oh, and sorry to completely rip out your switch statements ... I just vastly prefer arrays to switches.
Switches are awesome when you need one, but if you could get away with an array, I prefer the array method.

Notice how much smaller my "build menu" and "press menu key" functions are :-P
(and precache, since it can use the same array as the menu select one )

X-Script 10-01-2007 12:54

Re: Menu Error
 
:O

That is a much more efficient way, thank you!


All times are GMT -4. The time now is 16:12.

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