Keymenulib

From EventScripts Community Encyclopedia


Information for beta testers:
If you notice weird behavior with keymenus using this module, please adjust eventscripts_debug to 1 and reproduce the problem. When reporting the problem in forums, please include the debug text from server console.


Module: keymenulib

Module Overview

EventScripts version: 2.0 or greater

Table of Contents

Contents


Description

Creates an easymenu popup menu using a keygroup or a KeyValues object.

Quick Example

Creating a simple keymenu:

# Create a playerlist keygroup
es.server.cmd("es_xcreateplayerlist playerlist")
# Create a new keymenu
myKeymenu = keymenulib.create('example_keymenu', '_temp', 'myscript/keymenu_submit', 'playerlist', '#keyvalue name', '#key', 'Playerlist\nSelect a player')
# Send the keymenu to everyone on the server
myKeymenu.send(es.getUseridList())

Module Content

Classes

Methods

keymenulib.create(keymenuname, variable, function, keygroup, menudisplay, menureturn, titletext)
Creates a new keymenu object with the specified name and returns a reference to the newly created keymenu class object of type keymenulib.Keymenu_keymenu.
The keymenu can be later referred to by the name given here by other functions shown here or with the keymenu console command.
Parameters:
  • keymenuname -- the global keymenu name that identifies this keymenu
  • variable -- server variable name that will contain the selected menu item
  • function -- a Python function or script block that acts as menuselectfb
  • keygroup -- keygroup name or KeyValues instance that will be used to fill the keymenu
  • menudisplay -- The text that will display as the options in the menu
    • #key - Uses the keys from the keygroup as the display
    • #keyvalue <key value name> - Uses the key values as the display
  • menureturn -- The value you want to return upon the player's selection from the menu
    • #key - Uses the keys from the keygroup to set the return var
    • #keyvalue <key value name> - Uses the key values to set the return var
  • titletext -- title you want to have across the top of your menu. As an optional parameter, you can add "Menu Title Text\nAdditional Text For Next Line Down"
Example:
# Create a playerlist keygroup
es.server.cmd("es_xcreateplayerlist playerlist")
# Create a new keymenu
myKeymenu = keymenulib.create('example_keymenu', '_temp', 'myscript/myblock', 'playerlist', '#keyvalue name', '#key', 'Playerlist\nSelect a player')
keymenulib.delete(keymenuname)
Deletes a keymenu with the given name if it exists.
Raises ValueError if the keymenu does not exist
Example:
try:
    keymenulib.delete('example_keymenu')
except ValueError:
    es.dbgmsg(0, 'example_keymenu did not exist...')
keymenulib.exists(keymenuname)
Returns True or False depending on if the named keymenu exists
Example:
if keymenulib.exists('example_keymenu'):
    keymenulib.delete('example_keymenu')
keymenulib.find(keymenuname)
Find the named keymenu object and returns the class object reference. If the named keymenu was not found, None is returned.
Example:
myKeymenu = keymenulib.find('example_keymenu')
if myKeymenu:
    myKeymenu.update()
keymenulib.send(keymenuname, users, page = 0)
Sends the specified keymenu to selected users. As with most other functions, users can be either a single userid or a list of users.
If the named keymenu is not found, this function raises ValueError
page is an optional parameter that allows you directly show a page to the users.
Example:
keymenulib.send('example_keymenu', es.getUseridList())
keymenulib.unsend(keymenuname, users, page = 0)
Removes the sent keymenu from users' queue if it exists there. If the keymenu is currently being displayed to the person, menuselect 10 is issued and any action tied to that is handled.
page is an optional parameter that allows you to only unsend one page of the menu.
Example:
keymenulib.unsend('example_keymenu', es.getUseridList())
keymenulib.getmenuname(popupname)
Returns the keymenu object of a given popup depending on if the popup is part of a keymenu.
Example:
myKeymenu = keymenulib.getmenuname('example_keymenu')

See Also

blog comments powered by Disqus