evasivedocs
CS2 scriptingLua 5.4.9 · 25 guides · 292 API entries
Advanced

Changing evasive's settings

config lets a script read and change evasive's own settings, the ones you set in the menu, and switch between profiles.

Needs: Allow scripts to edit cfg files. While it is off, config is nil.

Paths

A setting is named by its path, the section and the key joined with dots, as they appear in your config files: "esp.enabled". config.get gives nil for a path that does not exist.

The quickest way to see what a section holds is to print it. A path that names a whole section gives a table:

Lua
if config then
    print(json.encode(config.get("esp"), true))
end

Your scripts' own values are not reachable through config. Use the ui controls for those.

Reading and changing

Lua
local on = config.get("esp.enabled")
config.set("esp.enabled", not on)

config.set gives false when the path does not exist or the new value has a different type from the old one. A number may switch between whole and decimal. A change applies at once but is not written to disk until config.save().

Profiles

Call What it does
config.active() The name of the active profile.
config.list() All profile names.
config.load(name) Switches to another profile.
config.save() Saves the active profile.

When the profile changes, for any reason, every script gets the config_change event with the new name. A profile switch made by a script applies the script values stored in it, but it never loads or unloads scripts.

Example: a key that flips the ESP

Lua
-- @name ESP toggle
-- @description A key that turns the ESP on and off.

local key = ui.keybind("Toggle ESP", vk.f7, "hold")
local was_down = false

events.on("paint", function()
    if not config then return end
    local down = key:active()
    if down and not was_down then
        local on = config.get("esp.enabled")
        if type(on) == "boolean" then
            config.set("esp.enabled", not on)
        end
    end
    was_down = down
end)

The change is not saved, so the ESP comes back the way it was the next time the profile loads. Add config.save() after config.set if you want it to stick.

Example: a profile picker

Lua
-- @name Profile picker
-- @description Pick a profile from the script's own settings.

if not config then
    print("turn on Allow scripts to edit cfg files")
    return
end

local names = config.list()
local start = 1
for i, n in ipairs(names) do
    if n == config.active() then start = i end
end

local pick = ui.combo("Profile", names, start)
ui.button("Load profile", function()
    local name = names[pick:get()]
    if name and name ~= config.active() then
        if not config.load(name) then log.warn("could not load " .. name) end
    end
end)

events.on("config_change", function(name)
    print("profile now: " .. name)
end)

The list of names is read once, when the script loads. Reload the script after you add a profile. A combo holds up to 64 names.