Josbird's Cursor Menu

GETVX

Welcome to Josbird's Cursor Menu!

Supports up to 16 buttons at once. I'm still working on writing the full documentation, but for now, here's a quick guide.


The basic structure of a button

Each button is defined by an array with 12 values, as described below:

Array Index Value Description
0 Label text The actual text shown by the button.
1 Action ID The player variable CurrActionID becomes equal to this value when the button is clicked. Can be a string, number, or any other unique identifier you can think of.
2 Position X A number indicating the horizontal position of the center of the button in screen units. The positive X direction is right. The default screen size is 2.5 units tall, 5 units wide, and the center of the screen has coordinates (0, 0).
3 Position Y A number indicating the vertical position of the center of the button in screen units. The positive Y direction is up.
4 Click width A number indicating the width of the clickable area of the button in screen units.
5 Click height A number indicating the height of the clickable area of the button in screen units.
6 Is clickable A boolean (true or false) determining whether or not the button is currently clickable.
7 Is visible A boolean (true or false) determining whether or not the button is currently visible.
8 Text size A number indicating the text scale of the button. Maximum is 4.
9 Secondary action ID Same as Action ID, but for secondary fire. The variable CurrActionID_Secondary becomes equal to this value when the button is clicked with secondary fire.
10 Neutral color (Functionality not yet available) The color of the button when the cursor is not within the clickable area.
11 Hover color (Functionality not yet available) The color of the button when the cursor is within the clickable area.

Adding a button

To add buttons to the menu, you must append an array containing the button's information to the ButtonProperties array in the rule named ==>>>EDIT BUTTON & LABEL STARTING VALUES HERE<<<==. This array must also be wrapped in another array so that it doesn't simply add each individual property to the whole ButtonProperties array.

In simpler terms: For each button you want to add, copy the following action in the starting values rule, and then edit each slot so the button has the desired properties.

variables
{
    player:
        119: ButtonProperties
}

actions
{
    "Sample button"
    Modify Player Variable(Event Player, ButtonProperties, Append To Array, Array(Array(Custom String("Label text"), Custom String(
        "Action ID"), 0, 0, 1, 0.150, True, True, 3, Null, Null, Null)));
}

Note that these properties are stored in a variable, so they do not update unless the array itself is updated. This means that any time you want to change the text, size, position, or any other property of a button while the menu is open, you must manually set that variable as detailed later in "Modifying buttons while the menu is open".


Detecting button presses

As stated earlier in the table, whenever a button is clicked, the CurrActionID variable is set equal to that button's Action ID for one server tick. Using this, you can detect button presses by setting up a rule that checks when CurrActionID is equal to the desired action.

As an example, let's say I have a button set up whose Action ID is equal to the string "acknowledge", and I want the player's character to say Understood when this button is clicked. The rule to do so would look like this:

variables
{
    player:
        117: CurrActionID
}

rule("My button rule")
{
    event
    {
        Ongoing - Each Player;
        All;
        All;
    }

    conditions
    {
        Event Player.CurrActionID == Custom String("acknowledge");
    }

    actions
    {
        Communicate(Event Player, Acknowledge);
    }
}

Keep in mind that an Action ID does not have to be a Custom String. If I wanted to have a variety of buttons that did a similar action, but with a different value for each one, I could set those buttons' action IDs to, say, a number between 101 and 109. Then I could use one rule whose conditions check that the ID is within that range, then subtracts 100, and now I can perform some action based on that "argument" of a number from 1 to 9.


Modifying buttons while the menu is open

Modifying individual values of one of the buttons in the ButtonProperties array can be tricky, since the Modify Player Variable at Index action only supports one-dimensional arrays. However, we can use the new Mapped Array value to go through a button's values and edit the one we want. Here's an example action that modifies the third button in the ButtonProperties array at index #8:

variables
{
    player:
        119: ButtonProperties
}

actions
{
    Event Player.ButtonProperties[2] = Mapped Array(Event Player.ButtonProperties[2],
        Current Array Index == 8 ? Current Array Element * 1.5 : Current Array Element);
}

Let's break down this action. In the Workshop interface, the number 2 (the index of the button we're modifying) appears twice: once in Set Player Variable at Index, and again in Value in Array. The number 8 (the index of the property we're modifying) appears once in If-Then-Else, where the Mapped Array checks if the current index is equal to 8. If it is at that index, it multiplies that value at that index by 1.5, Otherwise, it copies that same value as it was. All in all, this action ends up simply scaling the button text up to 150% of its previous size.


Still have questions? Feel free to contact me on Discord at jprosk#6749. Make sure to mention you came from here so I know you're not a spam account!

Code Snippet

Loading...
Fullscreen
Copy to clipboard

Other Codes part of Modular utilities

View collection

0 Comments

Log in or Sign up to place a comment.

Update Log (4)

  • Fixed a bug where a few player variables would be unnecessarily updating while the menu is closed
  • Disabled some actions that ran the risk of accidentally deleting non-menu effects during menu cleanup
  • Added fancy divider rules to separate menu code from the rest of your mode
  • Added conditions to exclude dummy bots from menu setup
View all updates
Elo Hell Logo_H-M-Dark
Join the Elo Hell Workshops Discord
Workshop.codes - Background image