Settings
Hooks
swatch_config_setting_changed
Called whenever a setting has changed.
Arguments
(String) settingKey
(Any) value
(Any) oldValue
Example
hook.Add("swatch_config_setting_changed", "onsettingchanged", function(key, value, oldValue)
sWatch.log("d", string.format("Setting %q changed from %q to %q", key, tostring(oldValue), tostring(value)))
end)
To add a description to your setting, create a new language entry identical to your setting key.
Functions
sWatch.setSetting
Can be used to change a setting or create a new one. Als see lua\swatch\modules\config\defaultsettings.lua
on how to use this function. This is a bit messed up.
Arguments
(String) key - Name like modulename_whateveryouwant
(Any) value - Can be string, number or table
(Boolean) showInUI (optional) -
true
to display in admin menu(Boolean) ifNotExists (optional) -
true
to only create/change if setting does not exist(Table) options (optional) - All allowed values
(Boolean) advancedSetting (optional) -
true
to only show when advanced mode is enbaled in admin menu
Returns
(Any) newValue -
nil
if function failed
Example
Create new setting that is visible inside admin menu
sWatch.setSetting(
"networking_concommand_logging", // key
true, // value
true, // show in UI
true, // only if it does not already exist
nil, // all values accepted
true // it is a advanced setting
)
Create new setting that stores internal values
sWatch.setSetting(
"server_maps",
{"gm_construct", "gm_anything"}, // store a table in the setting
false, // don't show in admin menu
true // only if setting does not exist
)
Change above setting
sWatch.setSetting("server_maps", {"another_map"})
sWatch.getSetting
Arguments
(String) key
(Any) defaultValue - will get returned if setting does not exist
Returns
(Any) setting - the setting you requested or
defaultValue
Example
Get value of a setting
local val = sWatch.getSetting("modulename_any_setting", "nothing")
Check if a setting exist and create if not
local secret = sWatch.getSetting("devicecookie_serverSecret", false)
if cookieServerSecret == false then
cookieServerSecret = sWatch.setSetting("devicecookie_serverSecret", sWatch.generateString(32))
end
Last updated