Zenbot Wiki Difference between revisions of "Plugins"

Difference between revisions of "Plugins"

From Zenbot Wiki
(Created page with "=== Plugin Definition === A plugin is defined as a folder, or (encrypted) archive that contains the following: ## info.lua [required] - name - the name by which it can be module.load-ed - if two with the same name exist the newer one will be loaded - if one exist in core and in plugin folder with the same name, the one from plugin will be loaded - version - for example "0.0.1" - title - this will get displayed in loader/menu - author - this will g...")
 
 
(55 intermediate revisions by the same user not shown)
Line 1: Line 1:
=== Plugin Definition ===
=== Definition ===
A plugin is defined as a folder, or (encrypted) archive that contains the following:
 
## info.lua [required]
==== Content ====
- name
A plugin is defined as a folder, or [encrypted] archive that contains the following:
     - the name by which it can be module.load-ed
 
    - if two with the same name exist the newer one will be loaded
===== header.lua <code>[required]</code> =====
     - if one exist in core and in plugin folder with the same name, the one from plugin will be loaded
    - id
- version
        the unique identifier for this plugin
     - for example "0.0.1"
    - name
- title
        this will get displayed in menu
    - description [optional]
        this will get displayed in menu as tooltip
     - icon [optional]
        this will get displayed in menu
    - dependencies [optional]
        - required
            plugin needs those libraries to work and will not load if one or more is missing/not available
            example: { "SomeOrbwalkerLib", "SomeHealthPredictionLib" }
        - optional
            plugin integrates those libraries but will load regardless if they are missing/not available
            example: { "? SomeEvadeLib" }
        - conflicts
            plugin cannot work if one or more of those is loaded, plugin will not load if they are loaded
            example: { "! SomeAatroxPlugin" }
     - library [optional]
        boolean to indicate if submodules should be loadable outside of this plugin
    - load [optional]
        (lambda) function returning a boolean that indicates if the plugin should show up ingame
            function() return player.charName == "Aatrox" end
            `player.charName == 'Aatrox'`
    - encrypt [optional]
        table containing every single file to be added to the encrypted file
          encrypt = {    -- main.lua and header.lua can be omitted
            "menu",      -- //scripts//yourfolder//menu.lua
            "logic",     -- //scripts//yourfolder//logic.lua
            "sprite.png" -- //scripts//yourfolder//sprite.png
          }
    - strip [optional]
        boolean to indicate if debug information should be omitted when encrypting, increases security slightly but removes any error information
 
===== thumbnail.png <code>[optional]</code> =====
     - this will get displayed in loader/menu
     - this will get displayed in loader/menu
- author
 
     - this will get displayed in loader
===== main.lua <code>[required]</code> =====
- description
     - this is the entry to your plugin
     - this will get displayed in loader/menu
 
- dependencies
==== Example ====
    - required
header.lua:
         - plugin needs those libraries to work and will not load if one or more is missing/not available
<pre>
         - example: { "Orbwalker", "HealthPrediction" }
return {
     - optional
    id = "my_plugin_id",
         - plugin integrates those libraries but will load regardless if they are not missing/available
    name = "My Plugin",
         - example: { "Evade" }
    description = "Does plugin things",
     - conflicts
     icon = "\xef\xa3\xbf", -- font awesome
        - plugin cannot work if one or more of those is loaded, plugin will not load if they are loaded
    dependencies = {
        - example: { "Aatrox" }
        "some_ts_lib_id", -- required
- library
         "? some_pred_lib_id", -- optional
     - boolean to indicate if submodules should be loadable outside of this plugin
         "! some_other_plugin" -- conflicts
- load
    },
    - (lambda) function returning a boolean that indicates if the plugin should show up ingame
    load = `()=> player.charName == "Aatrox"`,
        - function() return GameData.champion == "Aatrox" end
     encrypt = {
        - "GameData.champion == 'Aatrox'"
         "hud/main",
    - only GameData will be available inside the function with the following properties:
        "hud/overlay",
        - champion            : string
        "hud.png",
        - mapID              : number
         "font.ttf"
        - gameMode            : string
    },
        - isMatchmadeGame    : boolean
     strip = true
## thumbnail.png [optional]
}
- this will get displayed in loader/menu
</pre>
## init.lua [optional]
 
- this will get loaded during loading screen
=== Loading/Importing ===
- you can pre-create menu here
 
- most objects and instances are not available
==== Importing Plugins ====
## main.lua [required]
Libraries and internals can be loaded by using module api
- this is the entry to your plugin
 
local mylib = module.lib("mylib")
    or
local mylib_maybe = module.seek("mylib")
     or
local orb = module.internal("orb")
 
Similarly your Lua files can be loaded by using module api
 
local mymenu = module.load(header.id, "menu")
 
==== Example ====
rectangle.lua
local rectangle = class()
function rectangle:__init(x, y, w, h)
    self.x = x
    self.y = y
    self.w = w
    self.h = h
end
function rectangle:__tostring()
    return string.format("rectangle(%d, %d, %d, %d)", self.x, self.y, self.w, self.h)
end
function rectangle:__eq(other)
    return self.x == other.x and self.y == other.y and self.w == other.w and self.h == other.h
end
function rectangle:contains(x, y)
    return x >= self.x and x <= self.x + self.w and y >= self.y and y <= self.y + self.h
end
function rectangle:draw(color, var)
    graphics.draw_rect(vec2(self.x, self.y), vec2(self.w, self.h), color, true)
end
return rectangle
 
main.lua
local rectangle = module.load(header.id, "rectangle")
local rect1 = rectangle(100, 100, 400, 200)
cb.add(cb.draw, function()
    rect1:draw(0xff7f7f7f, rect1:contains(cursorPos.x, cursorPos.y) or 4)
end)

Latest revision as of 16:12, 1 April 2023

Definition

Content

A plugin is defined as a folder, or [encrypted] archive that contains the following:

header.lua [required]
   - id
       the unique identifier for this plugin
   - name
       this will get displayed in menu
   - description [optional]
       this will get displayed in menu as tooltip
   - icon [optional]
       this will get displayed in menu
   - dependencies [optional]
       - required
           plugin needs those libraries to work and will not load if one or more is missing/not available
           example: { "SomeOrbwalkerLib", "SomeHealthPredictionLib" }
       - optional
           plugin integrates those libraries but will load regardless if they are missing/not available
           example: { "? SomeEvadeLib" }
       - conflicts
           plugin cannot work if one or more of those is loaded, plugin will not load if they are loaded
           example: { "! SomeAatroxPlugin" }
   - library [optional]
       boolean to indicate if submodules should be loadable outside of this plugin
   - load [optional]
       (lambda) function returning a boolean that indicates if the plugin should show up ingame
           function() return player.charName == "Aatrox" end
           `player.charName == 'Aatrox'`
   - encrypt [optional]
       table containing every single file to be added to the encrypted file
         encrypt = {    -- main.lua and header.lua can be omitted
           "menu",      -- //scripts//yourfolder//menu.lua
           "logic",     -- //scripts//yourfolder//logic.lua
           "sprite.png" -- //scripts//yourfolder//sprite.png
         }
   - strip [optional]
       boolean to indicate if debug information should be omitted when encrypting, increases security slightly but removes any error information
thumbnail.png [optional]
   - this will get displayed in loader/menu
main.lua [required]
   - this is the entry to your plugin

Example

header.lua:

return {
    id = "my_plugin_id",
    name = "My Plugin",
    description = "Does plugin things",
    icon = "\xef\xa3\xbf", -- font awesome
    dependencies = {
        "some_ts_lib_id", -- required
        "? some_pred_lib_id", -- optional
        "! some_other_plugin" -- conflicts 
    },
    load = `()=> player.charName == "Aatrox"`,
    encrypt = {
        "hud/main",
        "hud/overlay",
        "hud.png",
        "font.ttf"
    },
    strip = true
}

Loading/Importing

Importing Plugins

Libraries and internals can be loaded by using module api

local mylib = module.lib("mylib")
   or
local mylib_maybe = module.seek("mylib")
   or
local orb = module.internal("orb")

Similarly your Lua files can be loaded by using module api

local mymenu = module.load(header.id, "menu")

Example

rectangle.lua

local rectangle = class()

function rectangle:__init(x, y, w, h)
    self.x = x
    self.y = y
    self.w = w
    self.h = h
end

function rectangle:__tostring()
    return string.format("rectangle(%d, %d, %d, %d)", self.x, self.y, self.w, self.h)
end

function rectangle:__eq(other)
    return self.x == other.x and self.y == other.y and self.w == other.w and self.h == other.h
end

function rectangle:contains(x, y)
    return x >= self.x and x <= self.x + self.w and y >= self.y and y <= self.y + self.h
end

function rectangle:draw(color, var)
    graphics.draw_rect(vec2(self.x, self.y), vec2(self.w, self.h), color, true)
end

return rectangle

main.lua

local rectangle = module.load(header.id, "rectangle")
local rect1 = rectangle(100, 100, 400, 200)

cb.add(cb.draw, function()
    rect1:draw(0xff7f7f7f, rect1:contains(cursorPos.x, cursorPos.y) or 4)
end)