Plugin system

From StealthBot Wiki Backup
(Redirected from Plugin System)
Jump to: navigation, search

Template:Legacy The Plugin system was a script written for version 2.6 of StealthBot's Scripting system in order to accomplish the loading of multiple scripts for versions before 2.7. Scripts written for the Plugin System were called Plugins and had a slightly modified structure in order to function.

History

The idea of the plugin system was originally from Xellos. In 2006, Swent rewrote the plugin system, later incorporating an update plugin by FiftyToo and a help plugin by Hdx into the core functionality of the system. When development for version 2.7 was opened to more people, Swent incorporated some of the plugin system into the bot itself, adding a new UI feature: the menu system. Later Eric redid the script system, making the plugin system obsolete due to the ability of the enhanced script system to do everything the plugin system could and more by using the Script Control's built-in modules. The Plugin System is still available for use on the script repository as a stand-alone script that loads plugins in the Plugins\ folder.

Details

The Plugin System used the #include directive in the script.txt file to #include pluginsystem.dat where the actual Plugin System code is found. When the Plugin System itself was made a 2.7-style script, the code is now all in the pluginsystem.txt file, and no longer uses the #include directive.

The code loads plugins directly into the current Script Control module, making all global variables, functions, and classes public to all other plugins. If any two plugins have global variables, functions or classes named the same, errors or unexpected behavior occur. Upgrading plugins to 2.7-style scripts is recommended.

Plugins

Template:Main The Plugin System loads files with the .plug or .txt extension with a comment header. Prefixes are used to keep Script events, global variables, custom functions, and classes unique from other plugins' members.

Commands

There are several plugin system commands to control plugins and updating.

List of commands

Prefix command

The prefix command allows you to enable and disable plugins or the entire system.

Syntax:

<trigger><prefix> <on/off>

Template:BotText

Updates command

The updates command shows available plugin updates. When used in-bot, this command will display more extensive information about plugin updates.

Syntax:

<trigger>updates

Template:BotText
Template:BotText

Pinitperf command

This command displays the initialization time for a plugin, in milliseconds.

Syntax:

/pinitperf

This command only works internally. Template:BotText

Functions

The plugin system provided several functions for use in plugins for standardizing plugin settings, timers, menus, and

List of functions

PluginEnabled function

This function turns the specified plugin on or off.

Syntax:

PluginEnabled <prefix>, <enabled>

Example: Turn off a plugin with the prefix "example".

PluginEnabled "example", False

GetPluginEnabled function

This function returns whether the specified plugin is enabled.

Syntax:

<enabled> = GetPluginEnabled(<prefix>)

Example: Do something specific if the timeban plugin is enabled.

If GetPluginEnabled("timeban") Then
    ' ...
End If

TimerInterval function

This function sets a plugin timer to a certain interval in seconds.

Syntax:

TimerInterval <prefix>, <timername>, <interval>

Example: Set the "example" plugin's "example" timer to fire every minute.

TimerInterval "example", "example", 60

GetTimerInterval function

This function returns the specified plugin timer's interval in seconds.

Syntax:

<interval> = GetTimerInterval(<prefix>, <timername>)

Example: Print the number of seconds between each timer tick for the "example" plugin's "example" timer.

AddChat vbCyan, "The timer will execute every " & GetTimerInterval("example", "example") & " seconds."

TimerEnabled function

This function sets a plugin timer to on or off.

Syntax:

TimerEnabled <prefix>, <timername>, <enabled>

Example: Enable the "example" plugin's "example" timer.

TimerEnabled "example", "example", True

GetTimerEnabled function

This function returns whether the specified plugin timer is enabled.

Syntax:

<enabled> = GetTimerEnabled(<prefix>, <timername>)

Example: Do something if the "example" plugin's "example" timer is enabled.

If GetTimerEnabled("example", "example") Then
    ' ...
End If

TimeLeft function

This function sets the number of seconds until a plugin timer will next execute.

Syntax:

TimeLeft <prefix>, <timername>, <seconds>

Example: Force the "example" plugin's "example" timer to execute in about one second.

TimeLeft "example", "example", 1

GetTimeLeft function

This function returns the number of seconds left until the next time the specified plugin timer executes.

Syntax:

<seconds> = GetTimeLeft(<prefix>, <timername>)

Example: Print the number of seconds until the next timer tick for the "example" plugin's "example" timer.

AddChat vbCyan, "The timer will execute in " & GetTimeLeft("example", "example") & " seconds."

GetTimerWaiting function

This function returns the number of seconds since the last time the specified plugin timer was executed.

Syntax:

<seconds> = GetTimerWaiting(<prefix>, <timername>)

Example: Print the number of seconds since the last timer tick for the "example" plugin's "example" timer.

AddChat vbCyan, "The timer was executed " & GetTimerWaiting("example", "example") & " seconds ago."

GetSetting function

This function retrieves a setting from the plugin system's setting.ini file.

Syntax:

<value> = GetSetting(<prefix>, <key>)

Example: Get the "example" plugin's "example" setting value.

AddQ "The example value is " & GetSetting("example", "example")

SetSetting function

This function saves a setting to the plugin system's setting.ini file.

Syntax:

SetSetting <prefix>, <key>, <value>, <comment>, <overwrite>

The comment value can be ommitted and the currently stored comment will be untouched. If the overwrite argument is True, the plugin system will always change the value. It was standard to set the override to False, and call SetSetting with a comment and the default <value> on plugin load, so that default values for plugins would be set, if they were not already. Example: This setting will not be set by Event_Load() unless the setting doesn't exist in which case it will be. On Event_Close(), will always be changed.

Sub example_Event_Load()
    SetSetting "example", "example", "this is the value of the example setting!", "Here is a sample comment.", False
End Sub

Sub example_Event_Close()
    SetSetting "example", "example", "this is the new value of the example setting!", vbNullString, True
End Sub

Dsp function

Template:Main The Dsp() function was originally part of the plugin system, but has since been moved to the Script Support Class.

Constants

Several color constants were globalized for the plugin system:

  • vbGrey was gray. Yes, it was incorrectly spelled. Generate with the hex &H8C8C8C or RGB(140, 140, 140).
  • vbBrown was brown. Generate with the hex &H13458B or RGB(139, 69, 19).
  • vbOrange was orange. Generate with the hex &H0099FF or RGB(255, 153, 0).
  • vbPink was pink. Generate with the hex &HCC99FF or RGB(255, 153, 204).
  • vbLightBlue was light blue. Generate with the hex &HCC6600 or RGB(0, 102, 204).

See also