AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   registering menus.. [ umm, solved! ] (https://forums.alliedmods.net/showthread.php?t=29775)

p3tsin 06-12-2006 12:24

registering menus.. [ umm, solved! ]
 
im working on a plugin which allows admins to control.. other players
the code below works, but i was just wondering if its ok to register every menu like it does right now,
or is there another way of catching the keypress?


Code:
register_event("ShowMenu","event_showmenu", "b") ... public event_showmenu(id) {     if(id != controlled)         return PLUGIN_CONTINUE     new menu[32], keys = read_data(1)     read_data(4, menu,31)     new name[32]     get_user_name(id, name,31)     client_print(controller,print_chat, "[%s] A ShowMenu was called on %s: %s",plugin,name,menu)     hasmenu = true     new menuid = register_menuid(menu,1)     register_menucmd(menuid,keys,"action_menu")     show_menu(controller,keys,menu)     return PLUGIN_CONTINUE } public action_menu(id,key) {     if(id != controller || !hasmenu)         return PLUGIN_CONTINUE     hasmenu = false     new num[2]     num_to_str(key+1, num,1)     engclient_cmd(controlled, "menuselect",num)     return PLUGIN_HANDLED }

wont this register the same menus over and over again as they pop up on the target's screen?

EDIT: oh, i forgot to explain what to code does exactly :P
it just replicates the menu displayed to the controlled player to the one controlling him who can then decide what the player should "select"

p3tsin 06-13-2006 08:04

okay, i looked how its done in amxx source and came up with this (if anyone is interested..)

Code:
public event_showmenu(id) {     if(id != controlled) return PLUGIN_CONTINUE     new menu[32], keys = read_data(1)     read_data(4, menu,31)     new name[32]     get_user_name(id, name,31)     client_print(controller,print_chat, "[%s] A ShowMenu was called on %s: %s",plugin,name,menu)     hasmenu = true          //keypress is catched in client_command()     message_begin(MSG_ONE,gMsg_ShowMenu,{0,0,0},controller)     write_short(keys)     write_char(-1)     write_byte(0)     write_string(menu)     message_end()     return PLUGIN_CONTINUE } public client_command(id) {     if(id != controller || !hasmenu) return PLUGIN_CONTINUE     new cmd[12]     read_argv(0, cmd,11)     if(equal(cmd,"menuselect")) {         hasmenu = false         new num[2]              //no need to check if menu even has this key,         read_argv(1, num,1)     //coz menuselect wont be called if it doesnt         engclient_cmd(controlled, "menuselect",num)     }     return PLUGIN_CONTINUE }

Peli 06-13-2006 16:24

Well your bools are messed up. Make sure they are below the plugin_init() like this:

Code:
public plugin_init() {    // registered stuff here } new bool:hasmenu[33] // Needs to be like this

Then in your functions you need to change this:
Code:
hasmenu = true/false

To:
Code:
hasmenu[id] = true/false


All times are GMT -4. The time now is 08:04.

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