Lua · Examples · Settings

Settings preset switcher

Switch between your own presets with one key. Changes real program settings.

Uses: config.get, config.set, db

settings_preset_switcher.lua
-- name: Preset Switcher
-- author: Adolfjon
-- version: 1.0
-- description: Cycle settings presets with a key.
-- permissions: settings

ui.keybind("key", "Next preset", 0x77)

local presets = {
    { name = "Legit",  set = { ["aim.fov"] = 2.5, ["aim.smoothing"] = 3.0, ["aim.rcs"] = true } },
    { name = "Normal", set = { ["aim.fov"] = 4.0, ["aim.smoothing"] = 1.8, ["aim.rcs"] = true } },
    { name = "Off",    set = { ["aim.state"] = false } },
}

local current = db.get("preset") or 1

local function apply(i)
    current = i
    for path, value in pairs(presets[i].set) do
        if config.get(path) == nil then
            print("skipped unknown setting " .. path)
        elseif not config.set(path, value) then
            print("could not set " .. path)
        end
    end
    db.set("preset", i)
    notify.push("Preset: " .. presets[i].name)
end

function on_frame()
    if input.key_pressed(ui.get("key")) then
        apply(current % #presets + 1)
    end
end

function on_menu()
    menu.section("PRESETS")
    for i, p in ipairs(presets) do
        if menu.button((i == current and "> " or "") .. p.name) then apply(i) end
    end
    menu.text("Settings are applied live. Save the config to keep them.")
end

Install it

  1. Press Copy on the code above.
  2. In the menu, open Lua and press From Clipboard. The file is named from its -- name: line.
  3. Turn the script on in the list. Its settings show on its own tab.

Change anything you like and press Save (Ctrl+S) in the editor; the script reloads at once. See Getting started for the other ways to add scripts.