Description:
Randomizes
existing cvars as defined in ...addons\sourcemod\configs\randcvars.cfg file,
and then removes itself from memory. Plugin
will not create new cvars at this time.
I've had a need for something like this and couldn't find anything close enough worth tailoring.
Installation:
Installation depends on how you want to use the plugin.
If you want it called for every map, just put randcvar.smx in ...addons\sourcemod\plugins
and randcvars.cfg in ...\addons\sourcemod\configs.
Remember that the plugin removes itself from memory after it executes.
Configuration:
Without a correctly configured cfg file, the plugin does nothing
The plugin recognizes 3 different types of definitions in the cfg file: F (float), I (integer),
and L (list). The F type returns a float between the defined low and high values,
to the defined precision.
The I type returns an integer between the defined low and high values.
The L type returns a random string from the listed items.
Example cfg file:
Below is an example.cfg, which is also attached as randcvars.cfg.
The first entry is for the cvar mp_roundtime.
It's a type F, so it will return a float value between 2.00 (lo) and 3.50 (hi),
with 2 decimal places (prec).
The second entry is for the cvar bot_difficulty.
It's a type I, so it will return an integer value between 0 (lo) and 3 (hi).
The third and last entry is for the cvar sm_gg_cfgdirname.
It's a type L, so it will return a string value from the listed item.
The items are read into key values per the count, so if the count is
less than the number of items, items numbered greater than count
will be disregarded. In other words if you have 8 list items, but only
specify a count of 2, only the first 2 items will be considered. If
count is greater then the number of listed items, the returned string
will either be the last listed item, or an empty string. For best
results, your count should always match the number of listed items.
This is just an example file to illustrate how the plugin is used.
It is important to note that
the plugin aborts and removes itself from memory upon
the first error in the cfg file. In other words, if all of the key values are set
correctly for the first cvar, but incorrect for the second (or 3rd, or 4th, etc.)
cvar, the first cvar will be changed, but the second (or 3rd, or 4th, etc.)
cvar won't be changed.
Code:
//Rename this file to randcvars.cfg and place in ...\addons\sourcemod\configs
//If there are any errors in the structure, the plugin will abort at that point
"Randomized_Cvars"
{
"mp_roundtime" //cvar name. Cvar must already exist, plugin does not create new Cvars
{
"type" "F" //Valid types are F (float), I (integer), and L (list)
"prec" "2" //Precision - an integer value representing the number of digits to return
// to the right of the decimal point (used only for type F) 1-99 are valid
"lo" "2.00" //Lowest possible value to return (used only for types F and I)
"hi" "3.50" //Highest possible value to return (used only for types F and I)
}
"bot_difficulty" //cvar name. Cvar must already exist, plugin does not create new Cvars
{
"type" "I" //Valid types are F (float), I (integer), and L (list)
"lo" "0" //Lowest possible value to return (used only for types F and I)
"hi" "3" //Highest possible value to return (used only for types F and I)
}
"sm_gg_cfgdirname" //cvar name. Cvar must already exist, plugin does not create new Cvars
{
"type" "L" //Valid types are F (float), I (integer), and L (list)
"count" "3" //Number of items in the list (used only in type L).
"item 1" "gungame1\" //A list item (used only in type L)
"item 2" "gungame2\" //A list item (used only in type L)
"item 3" "gungame3\" //A list item (used only in type L)
}
}
It is open source, so tailor to your needs at will