Left 4 Dead 2

Left 4 Dead 2

Ikke nok vurderinger
Creating menus using project_smok
Af randy
A detailed guide on how to create your own dynamic menus using project_smok
   
Pris
Føj til foretrukne
Gjort til foretrukken
Fjern som foretrukken
Introduction
This guide explains how to create menus with dynamic labels in detail using the project_smok add-on. Everything about this add-on is documented in it's source code page[github.com]. This guide was made for versions of project_smok v3.0.0 and higher.

https://sp.zhabite.com/sharedfiles/filedetails/?id=2229460523

Follow each section in order to successfully create a basic custom menu. If you have any questions, suggestions or issue reports, feel free to ask, share and report them in the add-on's discussions:
Locating the Configuration Files
You can locate the configuration files for custom menus under the directory
\Steam\steamapps\common\Left 4 Dead 2\left4dead2\ems\admin system\menus

Locate the folder




Create an empty .txt file




Name it however you like




Start editing the file

Menus
Menus created via configuration files serve a similar purpose the the client-menu project_smok provides, calling commands.

Custom menus, besides allowing calling commands, also allow:
  • Calling custom functions

  • Dynamic labels, having menu option texts update over time

  • Scroll through and select options with custom controls or built-in menu commands

  • Execute server-console commands

  • Restrict menu access with a minimum user level

Limitations
Custom menus unfortunately don't look and work as good as the built-in client menu. Some of the limitations of these menus can be listed as:
  • Very small-sized, hard-to-read font

  • ~240 characters at most for each menu as total character count of it's labels.

  • A menu can be viewed by only 1 player at a time

  • Somewhat inconsistent scrolling controls due to the update rate
Menu File Format
Custom menu files must include some key-value pairs to create functional menus. A table of these pairs given below.

my_menu.txt contents
Key
Value Type
Default value
Explanation
Name
string
This value is required
Name of this menu, used to refer to this menu from other menus or from commands
MinimumUserLevel
user_level
PS_USER_BASIC
Minimum user level required for this menu's user
Type
menu_type
PS_MENU_TYPE_SCROLLABLE
Type of the menu. Only available type for v3.0.0 is PS_MENU_TYPE_SCROLLABLE
UpdateRate
integer or float (>=0.075)
0.075
Intervals in seconds to use for updating labels and checking scroll/select controls. This must be kept very low for better scrolling controls
Controls
table
{
Up = BUTTON_RELOAD | BUTTON_ZOOM,
Down = BUTTON_WALK | BUTTON_ZOOM,
Select = BUTTON_RELOAD | BUTTON_SHOVE,
Exit = BUTTON_RELOAD | BUTTON_WALK
}
Scrolling and selecting controls for menu options. Table keys: (Up, Down, Select, Exit) Available button names given in another table below.
Items
array<table>
[]
Array of menu option tables. First table will be the first option. Accepts variety of values in as elements, explained below

The buttons available for Controls value given below. Buttons can be combined with | character.

Button Names for Controls
Button Name
On Keyboard/Mouse(Default)
BUTTON_FORWARD
W
BUTTON_BACK
S
BUTTON_LEFT
A
BUTTON_RIGHT
D
BUTTON_JUMP
SPACE
BUTTON_DUCK
LCTRL
BUTTON_WALK
LSHIFT
BUTTON_ATTACK
MOUSE1
BUTTON_SHOVE
MOUSE2
BUTTON_ZOOM
MOUSE3
BUTTON_RELOAD
R
BUTTON_USE
E
BUTTON_SCORE
TAB
BUTTON_ALT1
LALT
BUTTON_ALT2
RALT(? not sure)

These buttons are required to be the only buttons pressed by the player for making them work. For example BUTTON_FORWARD|BUTTON_RELOAD means W+R buttons need to be pressed without any other buttons, so something like W+R+SPACE won't work.




The tables in Items array, look for keys given below.

Tables in Items array
Key
Value Type
Default value
Explanation
label
string
"unknown_{x}" for option x
Label to display. The $[expression] format can be used for dynamic labels
command
array<array<string>, function, string> or string
[]
List of commands and functions to call and server commands to execute OR server command to execute. Details below
next_menu
string
""
Menu to display after this option gets selected. Write the name of this menu to basically keep the menu open after selection

The Items.command value can be given an array of ordered commands/functions/server-commands to execute. Instead of an array of these types, it also accepts string type values which are considered to be server-console commands.

While using Items.command as an array, table below can be referred to select array's element types.

Items.command array element options
Value Type
Explanation
array<string>
Command call with the format: ["command", "arg_1", "arg_2", ...]
string
Server console command to execute
function
A function with 4 parameters (<PS_Player> player, <integer> item_index, <string> item_label, <variable> command ) . The command parameter gets the Items.command array itself.

Menu From Scratch
Follow this example to create a basic menu named ExampleMenu. You can add/edit menu options to try different possibilities for yourself.

Decide for a name and the minimum user level




Initialize the Items array




Add a menu option by creating a table Items array, decide for a label and this option's callbacks. For example call the explosion command




Create another table for the second option. For example call the rainbow command on yourself(with >self target format) and call a custom function printing a message to everyone




Create the tables for the third and forth options. For example make these options change a server cvar




Create a dynamic label for the fifth option. Use $[expression] format for evaluating expressions every UpdateRate second for the label. Be careful with the strings within expressions, don't forget \" characters to wrap values to act like strings if you need.




Full view of the menu file contents




File contents of this example
Name = "ExampleMenu" // Name for the menu MinimumUserLevel = PS_USER_ADMIN // >= Admin user levels Items = [ // 1. Call "explosion" command { label = "Delayed explosion" command = [ // These slashes are here because steam markdown sux [ // "explosion" // ] // ] // next_menu = "ExampleMenu" }, // <- Don't forget ',' at the end for multiple menu options // 2. Call "rainbow" command on yourself, 20 seconds, 0.1 second intervals // and print a message with a custom function { label = "Go rainbow" command = [ ["rainbow>self", "20", "0.1"], // <- Don't forget ',' at the end for multiple elements @(player,index,label,command) ::Messages.InformAll(player.GetCharacterName() + " is feeling amazing!") ] next_menu = "ExampleMenu" }, // 3. Execute command in server console, cvar sb_open_fire forces bots to open fire { label = "Change sb_open_fire to 1" command = "scripted_user_func cvar,sb_open_fire,1" next_menu = "ExampleMenu" }, // 4. Reverse 3rd option { label = "Change sb_open_fire to 0" command = "scripted_user_func cvar,sb_open_fire,0" next_menu = "ExampleMenu" }, // 5. Dynamic label, using $[expression] format ; display option info message and echo to server console { label = "$[format( \"Dynamic label. Time() is %.2f\", Time() )]" command = [ @(player,index,label,command) ::Messages.InformPlayer(player, format("Selected %d\r\tLabel: %s\r\t", index, label) ), "echo \"Someone just selected option 5!\"" ] next_menu = "ExampleMenu" }, // 6. Another way of closing the menu: no references or callbacks { label = "Close" } ]
Registering the Menu
After the menu is created, add the file name of the menu file (in this case my_menu) without the extension ".txt" to the file_list.txt in the same directory




Check console messages to see if it was registered

Using the Menu
All custom menu related command are listed under menus[github.com] category in the documentation.

These commands can be easily accessed through Smok Menu with 6->2 menu sequence

Use open_menu[github.com] command to open a custom menu.

View of the menu in-game, with the scroll/select settings menu opened in the client-menu

Reloading menus in-game
Custom menus can be reloaded using reload_menus[github.com] command. This should add new menus from the files but it's not guaranteed to update menus which are being viewed by players.