AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [SM] Plugin load/unload management (https://forums.alliedmods.net/showthread.php?t=188040)

Dr. McKay 06-21-2012 13:15

[SM] Plugin load/unload management
 
These are a few stocks that a plugin can use to unload/reload itself.

PHP Code:

stock ReloadMyself() {
    
decl String:filename[256];
    
GetPluginFilename(INVALID_HANDLEfilenamesizeof(filename));
    
ServerCommand("sm plugins reload %s"filename);
}

stock UnloadMyself() {
    
decl String:filename[256];
    
GetPluginFilename(INVALID_HANDLEfilenamesizeof(filename));
    
ServerCommand("sm plugins unload %s"filename);



Starbish 06-21-2012 13:38

Re: [SM] Plugin load/unload management
 
nice

minimoney1 06-21-2012 13:56

Re: [SM] Plugin load/unload management
 
Could even support other plugins by doing this:
Code:
stock ReloadPlugin(Handle:plugin = INVALID_HANDLE) {     decl String:filename[256];     GetPluginFilename(plugin, filename, sizeof(filename));     ServerCommand("sm plugins reload %s", filename); } stock UnloadPlugin(Handle:plugin = INVALID_HANDLE) {     decl String:filename[256];     GetPluginFilename(plugin, filename, sizeof(filename));     ServerCommand("sm plugins unload %s", filename); }
But I don't know who would want to reload other plugins by their handles...
Edit: Ooops typo, thanks 11530

berni 06-22-2012 07:05

Re: [SM] Plugin load/unload management
 
Quote:

Originally Posted by Dr. McKay (Post 1733271)
These are a few stocks that a plugin can use to unload/reload itself

The question is just, why would someone do this ? Yes, this is a serious question.

Dr. McKay 06-22-2012 09:46

Re: [SM] Plugin load/unload management
 
Quote:

Originally Posted by berni (Post 1733730)
The question is just, why would someone do this ? Yes, this is a serious question.

I'm using a self-unloader on a game mode that I'm working on. It unloads the plugin if it detects an unsupported map. SourceMod automatically loads it again when the map changes.

Thrawn2 06-22-2012 10:07

Re: [SM] Plugin load/unload management
 
Quote:

Originally Posted by Dr. McKay (Post 1733790)
I'm using a self-unloader on a game mode that I'm working on. It unloads the plugin if it detects an unsupported map. SourceMod automatically loads it again when the map changes.

ouch. don't do something like this, it's an ugly workaround.
Plugins that can only be disabled by unloading them should be unapproved right away IMHO.

Rather add a bUsable variable or sth like that, set it in OnMapStart and check its value everytime your plugin does something.

psychonic 06-22-2012 10:30

Re: [SM] Plugin load/unload management
 
Quote:

Originally Posted by Thrawn2 (Post 1733804)
ouch. don't do something like this, it's an ugly workaround.
Plugins that can only be disabled by unloading them should be unapproved right away IMHO.

Rather add a bUsable variable or sth like that, set it in OnMapStart and check its value everytime your plugin does something.

QFT

berni 06-22-2012 10:54

Re: [SM] Plugin load/unload management
 
or use SetFailState, this pauses the plugin until it is reloaded.

Quote:

Originally Posted by Sourcemod API
Causes the plugin to enter a failed state. An error will be thrown and the plugin will be paused until it is unloaded or reloaded

but the best way is to just add a mapcheck OnMapStart(), yeah.


Quote:

Originally Posted by Dr. McKay (Post 1733790)
I'm using a self-unloader on a game mode that I'm working on. It unloads the plugin if it detects an unsupported map. SourceMod automatically loads it again when the map changes.

No, sourcemod only does that if it is configured to do so, if someone changes this settings your plugin will simply fail.

Dr. McKay 06-22-2012 10:57

Re: [SM] Plugin load/unload management
 
Quote:

Originally Posted by Thrawn2 (Post 1733804)
ouch. don't do something like this, it's an ugly workaround.
Plugins that can only be disabled by unloading them should be unapproved right away IMHO.

Rather add a bUsable variable or sth like that, set it in OnMapStart and check its value everytime your plugin does something.

Might as well unapprove Prophunt, it does this.
Quote:

Originally Posted by berni (Post 1733839)
or use SetFailState, this pauses the plugin until it is reloaded.



but the best way is to just add a mapcheck OnMapStart(), yeah.

Why? I don't really want to spew the error logs if no real error occurs.



Quote:

Originally Posted by berni (Post 1733839)
No, sourcemod only does that if it is configured to do so, if someone changes this settings your plugin will simply fail.

Where's the option to change this?

berni 06-22-2012 11:13

Re: [SM] Plugin load/unload management
 
Quote:

Originally Posted by Dr. McKay (Post 1733841)
Why? I don't really want to spew the error logs if no real error occurs.

That really depends on your needs. If the plugin was made for servers only running gungame maps, you want to show the serveradmin the reason why the plugin suddenly dissapears from the plugin list on a capturetheflag map.

At least keep sure that the serveradmin knows why the plugin isn't doing anything.


Quote:

Originally Posted by Dr. McKay (Post 1733841)
Where's the option to change this?

plugin_settings.cfg
Code:

/**
 *  Each sub-section of "Plugins" should have a title which specifies a plugin filename.
 * Filenames have a wildcard of *.  Appending .smx is not required.
 * If the filename has no explicit path, it will be patched to any sub-path in the plugins folder.
 *
 *  Available properties for plugins are:
 * "pause"                        - Whether or not the plugin should load paused - "yes" or "no" (default)
 * "lifetime"                - Lifetime of the plugin.  Options:
* "mapsync"                - Plugins should be reloaded on mapchange if changed (default)
 * "global"                        - Plugin will never be unloaded or updated
 * "blockload"                - Plugin will always be blocked from loading.  Implicit (automatic) loads
 *                                          produce no error, but explicit (manual) loads will show an error message.
 *                                          (Options are one of "yes" or "no")
 *
 * You can also have an "Options" section declaring options to pass onto the JIT:
 * "profile"        - Bit flags for profiling level.  Add flags together to reach a value.
 *                                  WARNING: Profiler is _ALPHA_ software!  Use it at your own risk for
 *                                  development cycles only (not production setups).
 *                                  See the wiki article "SourceMod Profiler" for more information.
 *                                  1 - Profile natives
 *                                  2 - Profile callbacks
 *                                  4 - Profile internal plugin function calls
 */
       
"Plugins"
{
        "*"
        {
                "pause"                        "no"
                "lifetime"                "mapsync"
               
                "Options"
                {
                }
        }
}



All times are GMT -4. The time now is 18:33.

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