:override is a feature in gamesense pui version that allows you to override values of elements and easily revert them like in neverlose.
local enable_aa = pui.reference("AA", "Anti-aimbot angles", "Enabled")
-- disabling aa:
enable_aa:override(false)
-- don't leave a mess behind you
defer(function()
enable:override() -- or enable:override(nil)
end)
if you need the original value while the element is overridden, use :get_original()
:depend(...)
Sometimes you want to hide certain elements to not mess up the menu. It might look simple but actually it's rather difficult and complicated. But pui can make this as easy as pie.
:depend(...) is a method of a pui element, which creates a dependence on elements passed as arguments.
Its arguments can be either elements themselves (generally switches), or tables, which contain ref, condition, ....
In most of the cases, it looks like this: :depend( {ref, condition}, {ref2, condition2}, ... )
You can also invert conditions like this: {ref, condition, true}
If you want to lock elements instead of hiding them: :depend(true, ...)
Study these examples:
This is a common example of the use of :depend(...). As you can see, there are two labels showing statuses of a switch.
local checkbox = group:checkbox("Master switch")
local status1 = group:label("...is enabled!")
local status2 = group:label("...is disabled!")
status1:depend( {checkbox, true} )
status2:depend( {checkbox, false} )
If you want to show your elements when a certain value is selected in a combobox, this can be done as well.
local combo = group:combobox("Author of Pride and Prejudice:", {"Leo Tolstoy", "Charles Dickens", "Jane Austen"})
local correct = group:label("Yes! Jane Austen is")
local wrong = group:label("No! Try again")
correct:depend( {combo, "Jane Austen"} )
wrong:depend( {combo, "Leo Tolstoy", "Charles Dickens"} )
-- or {combo, "Jane Austen", true}
You can add multiple variants for comboboxes
You can define ranges for sliders like this:
local jitter = group:slider("Jitter degree", 0, 100)
local good = group:depend("Good choice")
good:depend( {jitter, 40, 60} ) -- range from 40 to 60
Sometimes the condition may be too complicated. In this case, you can use a function:
local slider = group:slider("Body temperature", 16, 42, 36)
local normal = group:label("You are healthy")
local cold = group:label("You are rather cold!")
local hot = group:label("You are quite hot!")
normal:depend( {slider, function()
return slider.value >= 35 and slider.value <= 37
end} )
cold:depend( {slider, function()
return slider.value <= 34
end} )
hot:depend( {slider, function()
return slider.value > 37
end} )
Yes, you can add more conditions calling :depend(..) multiple times. But you don't have to.
Study this example of a password puzzle:
local a = group:combobox("A", {"1", "2", "3", "4"} )
local b = group:combobox("B", {"1", "2", "3", "4"} )
local c = group:combobox("C", {"1", "2", "3", "4"} )
local answer = group:label("yes! 241 is correct")
answer:depend( {a, "2"}, {b, "4"}, {c, "1"} )
There are a lot of ways to use :depend() that I can't even imagine.
:set_callback(func, once*)
It's pretty much the same as the built-in ui.set_callback(), but pui allows you to add multiple callbacks and execute them at least once. You can also unset them by using :unset_callback(func) . You can't unset anonymous functions.
local checkbox = pui.checkbox("LUA", "A", "Enable")
checkbox:set_callback(function(self)
printf("Hello, %s is my name, %s is my value", self.name, self.value)
end, true)
checkbox:set_callback(function(self)
printf("I was changed to %s!", self.value)
end)
local checkbox = pui.checkbox("LUA", "A", "Enable")
local function callback (self)
print "Free invites for everyone if this prints"
end
checkbox:set_callback(callback)
checkbox:unset_callback(callback)
local checkbox = pui.checkbox("LUA", "A", "Your ex")
local function callback (self)
print "Don't call me again."
self:unset_callback(callback)
end
checkbox:set_callback(callback)
:set_event(event, func, condition*)
This methods is used to call functions in events when a certain condition is met. You can unset this behavior via :unset_event(event, func). You can't unset anonymous functions.
local checkbox = pui.checkbox("CONFIG", "Presets", "Name")
local painter = function (cmd)
print(cmd.chokedcommands)
end
checkbox:set_event("setup_command", painter)
local combobox = pui.combobox("CONFIG", "Presets", "Event", {"Off", "paint_ui", "setup_command"})
local paint_ui = function (cmd)
print "paint_ui"
end
local setup_command = function (cmd)
print "setup_command"
end
combobox:set_event("paint_ui", paint_ui, "paint_ui")
combobox:set_event("setup_command", setup_command, "setup_command")
local multiselect = pui.multiselect("CONFIG", "Presets", "Events", {"paint_ui", "setup_command"})
local paint_ui = function ()
print "paint_ui"
end
local setup_command = function (cmd)
print "setup_command"
end
multiselect:set_event("paint_ui", paint_ui, function (this)
return this:get("paint_ui")
end)
multiselect:set_event("setup_command", setup_command, function (this)
return this:get("setup_command")
end)
local checkbox = pui.checkbox("CONFIG", "Presets", "Enabled")
local func = function (cmd)
print(cmd.chokedcommands)
end
checkbox:set_event("setup_command", func)
checkbox:set_callback(function (this)
if not this.value then
-- will unset the event after you disable the checkbox for the second time
checkbox:unset_event("setup_command", func)
end
end)
local checkbox = pui.checkbox("CONFIG", "Presets", "Enabled")
checkbox:set_event("setup_command", function (cmd)
print(cmd.chokedcommands)
end)
-- this won't work because the function is anonymous
checkbox:unset_event("setup_command", function (cmd)
print(cmd.chokedcommands)
end)
:get_color() and :get_hotkey()
These will return the value of an additional elements.
Hotkeys states in .value are only updated when activating settings a keybind. Use :get_hotkey() to always get the actual key.
local c1 = pui.checkbox("LUA", "A", "Checkbox", {120, 160, 80})
local r, g, b, a = { c1:get_color() } -- 120, 160, 80, 255
local color = c1.color.value -- { 120, 160, 80, 255 }
local color2 = { c1.color:get() } -- 120, 160, 80, 255
local c2 = pui.checkbox("LUA", "A", "Checkbox", 1)
local is_active, key = { c2:get_hotkey() } -- true, 1
local hotkey = { c2.hotkey:get() } -- true, 1
local hotkey2 = c1.hotkey.value -- { true, 1 }