AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugins (https://forums.alliedmods.net/forumdisplay.php?f=108)
-   -   [ANY] CVAR Randomizer (https://forums.alliedmods.net/showthread.php?t=209511)

Bittersweet 02-26-2013 12:23

[ANY] CVAR Randomizer
 
2 Attachment(s)
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 :D

IceCucumber 05-02-2013 21:38

Re: [ANY] CVAR Randomizer
 
Cool plugin! However, it seems to only do its thing if I manually load it, eg. "sm plugins load randcvar" or "sm plugins refresh" to server console. Upon a mapchange, the CVARs will remain in their default values. Is there a way around this? I'm not getting any errors logs, and am quite positive my randcvars.cfg syntax is correct.

Quote:

[randcvar 2013.02.26.11.40] - Loaded
[SM] Loaded plugin randcvar.smx successfully.
[SM] Plugin randcvar unloaded successfully.
Code:

"Randomized_Cvars"
{
    "sm_cm_nextmap"
    {
        "type"      "L"
        "count"    "3"
        "item 1"    "nt_dawn_ctg"
        "item 2"    "nt_decom_ctg"
        "item 3"    "nt_ghost_ctg"
    }
}


Bittersweet 05-02-2013 22:31

Re: [ANY] CVAR Randomizer
 
Quote:

Originally Posted by IceCucumber (Post 1944751)
Cool plugin! However, it seems to only do its thing if I manually load it, eg. "sm plugins load randcvar" or "sm plugins refresh" to server console. Upon a mapchange, the CVARs will remain in their default values. Is there a way around this? I'm not getting any errors logs, and am quite positive my randcvars.cfg syntax is correct.

Code:

"Randomized_Cvars"
{
    "sm_cm_nextmap"
    {
        "type"      "L"
        "count"    "3"
        "item 1"    "nt_dawn_ctg"
        "item 2"    "nt_decom_ctg"
        "item 3"    "nt_ghost_ctg"
    }
}


Your syntax does look correct. The plugin loading may depend on the game type. If it's not loading between maps and you need it to, just stick a sm plugins load command in your server.cfg.

edit: Remember, the plugin removes itself from memory after execution.

IceCucumber 05-03-2013 00:23

Re: [ANY] CVAR Randomizer
 
Using this with the MapCron plugin to create a timed "sm plugins load randcvar" on mapchange appears to work nicely. I'm assuming this is due to the CVAR Randomizer accessing the variables before they are read from their respective config files, which will then overwrite the randomizations. Adding a simple timer to this plugin would most likely work as well.

Bittersweet 05-03-2013 07:04

Re: [ANY] CVAR Randomizer
 
Quote:

Originally Posted by IceCucumber (Post 1944786)
Using this with the MapCron plugin to create a timed "sm plugins load randcvar" on mapchange appears to work nicely. I'm assuming this is due to the CVAR Randomizer accessing the variables before they are read from their respective config files, which will then overwrite the randomizations. Adding a simple timer to this plugin would most likely work as well.

It really depends on how and when you call the plugin. Some users might want it called on every map change, while others might want it for just certain maps/game types. A timer might work for you, and you're free to modify the code to your needs. I wouldn't go with a timer on something like that because of the complexity of my server - too many plugins loading and unloading depending on the map and gametype. You'd have to check the order of operations, but you could call randcvar from autoexec.cfg, or even from a map specific .cfg file in your game folder\maps\cfg folder.

3axap 03-02-2018 02:45

Re: [ANY] CVAR Randomizer
 
Hello, Who can fix this?

Code:

File addons/sourcemod/configs/randcvars.cfg missing, aborting...
L 03/02/2018 - 10:43:41: [randcvar.smx] File addons/sourcemod/configs/randcvars.cfg missing, aborting...
L 03/02/2018 - 10:43:41: [SM] Exception reported: Invalid key value handle dc460367 (error 3)
L 03/02/2018 - 10:43:41: [SM] Blaming: randcvar.smx
L 03/02/2018 - 10:43:41: [SM] Call stack trace:
L 03/02/2018 - 10:43:41: [SM]  [0] KvGetSectionName
L 03/02/2018 - 10:43:41: [SM]  [1] Line 68, plugin.sp::LoadKeyValues
L 03/02/2018 - 10:43:41: [SM]  [2] Line 64, plugin.sp::OnPluginStart
[SM] Plugin randcvar.smx failed to load: Error detected in plugin startup (see error logs).

Counter-Strike: Source

freak.exe_uLow 03-02-2018 06:20

Re: [ANY] CVAR Randomizer
 
Quote:

Originally Posted by 3axap (Post 2580936)
Hello, Who can fix this?

Code:

File addons/sourcemod/configs/randcvars.cfg missing, aborting...
L 03/02/2018 - 10:43:41: [randcvar.smx] File addons/sourcemod/configs/randcvars.cfg missing, aborting...
L 03/02/2018 - 10:43:41: [SM] Exception reported: Invalid key value handle dc460367 (error 3)
L 03/02/2018 - 10:43:41: [SM] Blaming: randcvar.smx
L 03/02/2018 - 10:43:41: [SM] Call stack trace:
L 03/02/2018 - 10:43:41: [SM]  [0] KvGetSectionName
L 03/02/2018 - 10:43:41: [SM]  [1] Line 68, plugin.sp::LoadKeyValues
L 03/02/2018 - 10:43:41: [SM]  [2] Line 64, plugin.sp::OnPluginStart
[SM] Plugin randcvar.smx failed to load: Error detected in plugin startup (see error logs).

Counter-Strike: Source

File addons/sourcemod/configs/randcvars.cfg missing, aborting...

you missing a cfg :D upload the randcvars.cfg

3axap 03-02-2018 06:25

Re: [ANY] CVAR Randomizer
 
I put randcvars.cfg to addons/sourcemod/configs/randcvars.cfg from 1st post. I tried not to copy it, all plugins auto create a configuration file.

Anyway an error.


All times are GMT -4. The time now is 13:30.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.