Menu

class pysamp.menu.Menu(id: int)

Bases: object

Create and manage menus using this class.

Create a new menu with create(). Then add items to it with add_item(), and finally show it to players using show().

add_item(column: int, text: str) None

Add a new menu item to the menu.

Parameters
  • column (int) – The columt to add to. (0 or 1)

  • text (str) – The text to write. Max length: 31

Returns

No return value.

Note

You can only have 12 items per menu. You can only add 8 color codes per one item.

classmethod create(title: str, columns: int, x: float, y: float, column_1_width: float, column_2_width: float = 0.0) Menu

Create a new menu.

Parameters
  • title (str) – The menu title.

  • columns (int) – How many columns the meny should have.

  • x (float) – The X position on the screen (horizontally).

  • y (float) – the Y position on the screen (vertically)

  • column_1_width (float) – The width of the first column.

  • column_2_width (optional float) – The width of the second column.

Returns

Returns an instance of Menu.

Note

If the title’s length is equal to or greater than 32 chars, the title is truncated to 30 characters. You can only create and access 2 columns (0 & 1).

Warning

There is a limit of 12 items per menu, and a limit of 128 menus in total.

destroy() None

Destroy the menu.

Returns

No return value.

disable() None

Disable the menu.

Returns

No return value.

disable_row(row: int) None

Disable one of the menu rows for all players.

Parameters

row (int) – The row to disable. Rows start at 0.

Returns

No return value.

static get_player_menu(player: Player) Optional[Menu]

Figure out which menu a has last had open when no menu is currently open.

Parameters

player (Player) – The player to check last open menu for.

Returns

An instance of the menu. None if no menu was opened.

hide_for_player(player: Player) None

Hide the menu for a player.

Parameters

player (Player) – The player you want to hide the menu for.

Returns

No return value.

is_valid() bool

Check if the menu is valid.

Returns

True if valid, otherwise False.

set_column_header(column: int, text: str) None

Set the menu column header text.

Parameters
  • column (int) – The column you want to set the header for. (0 or 1)

  • text (str) – The header text you would like to set.

Returns

No return value.

show(player: Player) None

Show the menu for a given player.

Parameters

player (Player) – The player you would like to see the menu.

Returns

No return value.