Void Animates
Just a guy who loves... EVERYTHING!
I want to make a menu appear to toggle things. If you press custom 3 and tossflag it opens the menu. How do I do that?
addHook("PlayerThink", function(player)
-- Short circuit
-- If the variable holds any truthy value (anything that isn't "0", "nil" nor "false"), set to the same value ($).
-- Otherwise, set to false.
player.wasToggling == $ or false
local toggleBtns = BT_CUSTOM3|BT_TOSSFLAG -- Buttons to check
-- Comparisons can be done within variable assignment.
-- This will set "isToggling" to the result of "Are these two buttons being pressed?"
local isToggling = (player.cmd.buttons & buttonChk) == buttonChk
-- Check whether the toggle was performed, that is, on a tap.
-- A "tap" is "the button was not pressed before but is pressed now"
if isToggling and not player.wasToggling then
-- toggle the menu
end
-- Remember if we were toggling before, for use in next frame.
player.wasToggling = isToggling
end)
addHook("PlayerThink", function(player)
if player.wasToggling == nil then
-- Initialize the player variable,
-- in case it wasn't already
player.wasToggling = false
end
-- The buttons we want to check.
local toggleBtns = BT_CUSTOM3|BT_TOSSFLAG
local isToggling -- No value - But that's okay, we will give it one soon
-- Check if we are pressing the toggle buttons
if (player.cmd.buttons & toggleBtns) == toggleBtns then
isToggling = true
else
isToggling = false
end
-- Check whether the toggle was performed, that is, on a tap.
-- A "tap" is "the button was not pressed before but is pressed now"
if isToggling and not player.wasToggling then
-- toggle the menu
end
-- Remember if we were toggling before, for use in next frame.
player.wasToggling = isToggling
end)
Okay! I will try it!How do you do what? The toggling?
You can perform a button check like so:
Lua:addHook("PlayerThink", function(player)) -- Short circuit -- If the variable holds any truthy value (anything that isn't "0", "nil" nor "false"), set to the same value ($). -- Otherwise, set to false. player.wasToggling == $ or false local toggleBtns = BT_CUSTOM3|BT_TOSSFLAG -- Buttons to check -- Comparisons can be done within variable assignment. -- This will set "isToggling" to the result of "Are these two buttons being pressed?" local isToggling = (player.cmd.buttons & buttonChk) == buttonChk -- Check whether the toggle was performed, that is, on a tap. -- A "tap" is "the button was not pressed before but is pressed now" if isToggling and not player.wasToggling then -- toggle the menu end -- Remember if we were toggling before, for use in next frame. player.wasToggling = isToggling end
Lua:addHook("PlayerThink", function(player)) if player.wasToggling == nil then -- Initialize the player variable, -- in case it wasn't already player.wasToggling = false end -- The buttons we want to check. local toggleBtns = BT_CUSTOM3|BT_TOSSFLAG local isToggling -- No value - But that's okay, we will give it one soon -- Check if we are pressing the toggle buttons if (player.cmd.buttons & toggleBtns) == toggleBtns then isToggling = true else isToggling = false end -- Check whether the toggle was performed, that is, on a tap. -- A "tap" is "the button was not pressed before but is pressed now" if isToggling and not player.wasToggling then -- toggle the menu end -- Remember if we were toggling before, for use in next frame. player.wasToggling = isToggling end
Whichever menu script you're using should have a function to show it on screen, right?how do I make the menu spawn on the screen?
toggle the menu
comment with such function.I don't have any code but I'm thinking i should use this right? I mean it's re-usable...Whichever menu script you're using should have a function to show it on screen, right?
You just have to replace thetoggle the menu
comment with such function.
addHook("PlayerThink", function(player))
-- Short circuit
-- If the variable holds any truthy value (anything that isn't "0", "nil" nor "false"), set to the same value ($).
-- Otherwise, set to false.
player.wasToggling == $ or false
local toggleBtns = BT_CUSTOM3|BT_TOSSFLAG -- Buttons to check
-- Comparisons can be done within variable assignment.
-- This will set "isToggling" to the result of "Are these two buttons being pressed?"
local isToggling = (player.cmd.buttons & buttonChk) == buttonChk
-- Check whether the toggle was performed, that is, on a tap.
-- A "tap" is "the button was not pressed before but is pressed now"
if isToggling and not player.wasToggling then
addHook("PlayerSpawn", function(player)
player.menu = {}
player.menu.pointer = 1
player.menu.pagepointer = 1
player.menu.pagename = "Page 1"
player.menu.show = false
player.menu.timer = 0
player.menu.contents = { --you can delete these elements of the menu or use them as reference, info to make yours is below!
[1] = {
{value = 0, name = "Slider 1", description = "This slider has 10 different values", maxvalue = 10, slider = true},
{value = 1, name = "Boolean 1", description = "A boolean (ON/OFF) setting"},
{value = 0, name = "Slider 2", description = "This slider has 4 different options\n and the text is green when selected!", maxvalue = 4, slider = true, selectedvflags = V_GREENMAP},
{value = 1, name = "Value 9", description = "This setting can have different values,\nand it can be toggled by Slider 2", maxvalue = 5, options = {"OPTION 1", "OPTION 2", "ANOTHER OPTION", "4TH OPTION", "5TH"}, toggledby = 3},
{value = 1, name = "Say hi", description = "This setting calls a function!", func = sayHi},
{value = 1, name = "Boolean 2", description = "A boolean (TRUE/FALSE) setting", options = {"FALSE", "TRUE"}},
{value = 0, name = "Slider 3", description = "This slider has 100 different values", maxvalue = 100, flags = MNF_SLIDER|MNF_NOSAVE},
{value = 1, name = "Colorized setting", description = "This setting is red! (when not selected)", flags = MNF_NOSAVE, vflags = V_REDMAP},
{value = 2, name = "Go to page 2", description = "Go to page 2!", flags = MNF_CHANGEPAGE|MNF_NOSAVE, pagename = "Page 2!"}},
[2] = {
{value = 0, name = "Slider", description = "This slider in page 2 has 10 different values", maxvalue = 10, slider = true},
{value = 1, name = "Back", description = "Go back to page 1", flags = MNF_CHANGEPAGE|MNF_NOSAVE, pagename = "Page 1"}}
}
io.openlocal("client/Name.dat", "a+"):close() --you can change "Name" to something else, change it for the line below too if you do
local file = io.openlocal("client/Name.dat", "r+")
for e = 1,#player.menu.contents
for i = 1,#player.menu.contents[e]
if not player.menu.contents[e][i].flags then player.menu.contents[e][i].flags = 0 end
if not player.menu.contents[e][i].selectedvflags then player.menu.contents[e][i].selectedvflags = V_YELLOWMAP end
if not player.menu.contents[e][i].pagename then player.menu.contents[e][i].pagename = "Page "..player.menu.contents[e][i].value end
if player.menu.contents[e][i].func then continue end
if not player.menu.contents[e][i].maxvalue
player.menu.contents[e][i].maxvalue = 2
elseif player.menu.contents[e][i].maxvalue == 1
CONS_Printf(player, "\133ERROR IN PAGE "..e.."\nSetting "..i.."'s maxvalue is 1! Are you sure it's intentional?")
player.menu.contents[e][i].maxvalue = 2
CONS_Printf(player, "\133Maxvalue was set to 2.")
elseif player.menu.contents[e][i].maxvalue < 1
CONS_Printf(player, "\133ERROR IN PAGE "..e.."\nSetting "..i.."'s maxvalue("..player.menu.contents[e][i].maxvalue..") is too small! Are you sure it's intentional?")
player.menu.contents[e][i].maxvalue = 2
CONS_Printf(player, "\133Maxvalue was set to 2.")
end
if not player.menu.contents[e][i].options
player.menu.contents[e][i].options = {"OFF", "ON"}
elseif #player.menu.contents[e][i].options < player.menu.contents[e][i].maxvalue and not (player.menu.contents[e][i].slider or player.menu.contents[e][i].flags & MNF_SLIDER)
CONS_Printf(player, "\133ERROR IN PAGE "..e.."\nSetting "..i.."'s options can't be fewer than maxvalue("..player.menu.contents[e][i].maxvalue..")!")
for a =1,player.menu.contents[e][i].maxvalue
if player.menu.contents[e][i].options[a] then continue end
player.menu.contents[e][i].options[a] = "Missing!"
end
end
if player.menu.contents[e][i].flags & MNF_NOSAVE then continue end
local text = file:read("*l")
if text
player.menu.contents[e][i].value = tonumber(text)
end
end
end
end)
--[[player.menu.contents is the main part of the menu, every key in this table will refer to a page, if you only want a single page make a single key [1],
you can put the elements of the menu pages inside these keys, you can have as many elements as you want, but it might be best not to have more than 10 for each page
"value" sets their value, starting from 0, set this value to the setting's default value
use this for your checks in your Lua, an example is at the end of this Lua
"name" is the name of the setting that will appear on the menu
"description" is the small text that will appear on the bottom of the screen
"toggledby" is an extra parameter for subsections, set it to the number of the setting which your subsection setting should be depending on
do note that if the setting that controls the subsecton is off, it will make the subsection not modifiable, but it will NOT set it to false automatically, remember that when making the checks in your other Luas
"func" is an extra parameter for function setting, these settings can't be toggled on/off, selecting them will call the given function instead
"maxvalue" is for a setting with more than 2 options, set this parameter to the amount of options your setting can be
do note that "value" starts from 0, so if for example you want a 3 option setting "value" will start from 0 and reach it's max at 2 (maxvalue would still have to be set to 3 though)
if this parameter is omitted it will be set to 2 (equivalent to an ON/OFF setting)
"options" must be a table containing the names of all the possible setting's options, this table should be as long as maxvalue (example: if maxvalue is 3 the table should contain 3 strings)
if this parameter is omitted it will be set to {"OFF", "ON"}
"slider" is a boolean parameter that when set to true it displays a slider instead of a string, thus "options" can be omitted
this parameter is deprecated since MNF_SLIDER now exists, but it can still be used and it will work the same way
"flags" is the parameter for menu flags (MNF_*), you can see them and what they do near the start of the file
"vflags" is the parameter for video flags (V_*), you could use this for example to give the text a different color when not selected,
this parameter accepts any video flags, but it's primarely meant for color flags (V_*MAP) and it might break with other video flags
"selectedvflags" is a parameter that gives the specified video flags (V_*) when the setting is selected, this default to V_YELLOWMAP if omitted
this parameter accepts any video flags, but it's primarely meant for color flags (V_*MAP) and it might break with other video flags
"pagename" is a parameter that sets the name of the page, this defaults to "Page " + the "value" parameter if omitted
this paramter will only work with MNF_CHANGEPAGE settings
]]
end
-- Remember if we were toggling before, for use in next frame.
player.wasToggling = isToggling
end
it didn't work...Oh, you made me notice a misplaced parenthesis in my original reply (I forgot to move the closing one that is in line 1 to the end of the script).
Other than that, I'm not sure. I've never used it myself.
Try using the script and see what happens?