Make a simple and efficient game guardian menu template script with 3 functions and UI hiding implementation, if user selected one of the options in the menu it should hide script & game guardian UI and it should be shown again if the user interacted with game guardian icon after that.
Assistant
Here's a simple and efficient Game Guardian menu template script with 3 functions and UI hiding implementation:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
-- Initialize the menu
local menu = {
title = "My Game Guardian Menu",
options = {
{ name = "Option 1", func = function() print("Option 1 selected") end },
{ name = "Option 2", func = function() print("Option 2 selected") end },
{ name = "Option 3", func = function() print("Option 3 selected") end }
}
}
-- Variable to track if the UI is hidden
local uiHidden = false
-- Function to show or hide the UI
function toggleUI()
if uiHidden then
gg.setVisible(true) -- Show Game Guardian UI
uiHidden = false
else
gg.setVisible(false) -- Hide Game Guardian UI
uiHidden = true
end
end
-- Function to handle menu selection
function onMenuSelect(optionIndex)
toggleUI() -- Hide UI when an option is selected
menu.options[optionIndex].func() -- Call the function associated with the selected option
end
-- Function to display the menu
function showMenu()
gg.setVisible(true) -- Ensure Game Guardian UI is visible
gg.clearResults() -- Clear any previous search results
gg.toast("Menu Opened") -- Show a toast message
gg.alert("Welcome to My Game Guardian Menu\nSelect an option from the list.") -- Display an alert with the menu title
gg.setRanges(0) -- Set the search range to the entire process
gg.searchNumber(1, 0, false, gg.TYPE_FLOAT, gg.SIGN_EQUAL, 0, -1) -- Dummy search to populate the list with addresses
for i, option in ipairs(menu.options) do
gg.addOption({name = option.name}) -- Add each option to the Game Guardian list
end
gg.addToResult(1, "Select an option:\n") -- Add a header to the search results
gg.setResults(10) -- Set the number of results to display
gg.setVisible(true) -- Ensure Game Guardian UI is visible
gg.setOptionListCallback(onMenuSelect) -- Set the callback function for menu selection
end
-- Hide Game Guardian UI initially
toggleUI()
-- Show the menu when the user interacts with Game Guardian
gg.setVisible(false)
gg.setButtonCallback("Back", toggleUI)
gg.setButtonCallback("Menu", showMenu)
This script creates a simple menu with 3 options. When the user selects an option, the Game Guardian UI and the script UI are hidden. If the user interacts with the Game Guardian icon again, the UI is shown. The toggleUI function handles the hiding and showing of the UI. The onMenuSelect function is called when an option is selected, and it hides the UI and calls the associated function for that option. The showMenu function displays the menu and sets up the necessary callbacks.