in package menus
How do I close the active menu of the user, so I make sure that only 1 menu is open at the time, without saving the class object of every menu for each player?
closing menus
Re: closing menus
This closes the active menu (if there is one) of a specific player.Though, closing the active menu doesn't ensure that only one menu is opened/queued. There could be multiple menus in the queue.
Also, note that the same menu instance can't be sent twice. The menus logic will take care of that and skips menus that are sent a second time.
Syntax: Select all
user_queue = PagedMenu.get_user_queue(<index>)
if user_queue.active_menu is not None:
user_queue.active_menu.close(<index>)
Also, note that the same menu instance can't be sent twice. The menus logic will take care of that and skips menus that are sent a second time.
Re: closing menus
But it's never the same menu instance anyway since I'm calling the menu on a function, its a new class object every time right? I understood from EventScripts you give an id aka name for the popup, but apparently not here. So in order for this to work properly I have to save the menu object for every player, seems like a lot work?
If I call this menu twice on @SayCommand there will be two menus in the queue hm...
Syntax: Select all
def zones_modify_coordinates(self, index):
player = Player(index)
steamid = player.steamid
self.menu = PagedMenu(
title='Title',
top_separator='',
bottom_separator='',
select_callback=self.zones_modify_coordinates_callback
)
self.menu.append(PagedOption('Create Start Zone', 'create_start_zone))
self.menu.send(player.index)
If I call this menu twice on @SayCommand there will be two menus in the queue hm...
Re: closing menus
We don't use names for our menus, because that was quite annoying in ES and is actually redundant and not OOP. There are multiple ways to solve your issue:
- Use a build callback instead of creating a new menu everytime in your function.
- Use the caching you mentioned. That shouldn't be that much work like you think.
- Create named menus using this code :D
Syntax: Select all
from menus import PagedMenu, PagedOption
class NamedPagedMenu(PagedMenu):
def __init__(self, name, *args, **kwargs):
self.name = name
super().__init__(*args, **kwargs)
def __eq__(self, other):
if isinstance(other, NamedPagedMenu):
return self.name == other.name
return super().__eq__(other)
# Test code
from events import Event
@Event('player_say')
def player_say(event):
text = event['text']
menu = NamedPagedMenu('my_menu')
menu.append(PagedOption(text))
menu.send()
Return to “Plugin Development Support”
Who is online
Users browsing this forum: No registered users and 96 guests