There is no native way to unload a plugin via a switch. The reason is, upon adding as a script element, the parser will parse through all functions in the plugin and define them. There's no way to unparse a function or revert it to previous change except via a redefinition. However, in order to redefine a function you need to operate on a top level.
So that means there is pretty much only one workaround.
Having a .js file inside the game js/plugins folder. It would contain this code:
Code:Game_SelfSwitches.prototype.value = Yanfly.SSV.Game_SelfSwitches_value;
Game_SelfSwitches.prototype.setValue = Yanfly.SSV.Game_SelfSwitches_setValue;
Game_SelfSwitches.prototype.onChange = Yanfly.SSV.Game_SelfSwitches_setValue;
in other words it contains code to revert Yanfly's changes.
Then you'd have another file, which contains these functions:
Code:Yanfly.SSV.Game_SelfSwitches_value = Game_SelfSwitches.prototype.value;
Game_SelfSwitches.prototype.value = function(key) {
if (key[2].match(/SELF[ ]VAR/i)) {
this._data[key] = this._data[key] || 0;
return this._data[key];
}
return Yanfly.SSV.Game_SelfSwitches_value.call(this, key);
};
Yanfly.SSV.Game_SelfSwitches_setValue = Game_SelfSwitches.prototype.setValue;
Game_SelfSwitches.prototype.setValue = function(key, value) {
if (key[2].match(/SELF[ ]VAR/i)) {
this._data[key] = value;
this.onChange();
} else {
Yanfly.SSV.Game_SelfSwitches_setValue.call(this, key, value)
}
};
Yanfly.SSV.Game_SelfSwitches_onChange = Game_SelfSwitches.prototype.onChange;
Game_SelfSwitches.prototype.onChange = function() {
Yanfly.SSV.Game_SelfSwitches_onChange.call(this);
if ($gameTemp.getSelfSwVarEventOneTimeClear()) {
$gameTemp.setSelfSwVarEventOneTimeClear(false);
$gameTemp.clearSelfSwVarEvent();
}
};
In other words it implements Yanfly's changes back.
Then you'd have a plugin file that loads whatever plugin is necessary on demand. I'm including the base of this plugin in this reply, however since I have absolutely no idea when you use self switches, I don't know where should I even plant the functions necessary to call. So I kind of hope you figure that out
:D
Btw. using these functions it would be possible to make it possible to load/unload the plugin via switch.