-
-
Notifications
You must be signed in to change notification settings - Fork 136
Added Python-API to build Plugins with Python. #965
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Great. Needed following functions to make useful plugins: And in addition to send_server(opcode, data): |
|
I have that already implemented but forgot to mention them! Handle Packets
Send Packets
Example to log all Packetsdef on_packet_from_client(opcode,data): def on_packet_from_server(opcode,data): Example Plugin |
|
It'd be better to pull the necessary embeddable Python runtime at build time. This PR currently introduces ~40MB of binary files that we don't need source controlled via git. |
|
You are right. Would be better to change that! |
Added Python download during build; Updated Python to 3.13.11
Added Pythonnet to RSBot Project
|
The necessary embeddable Python runtime will now be pulled at build time. I hope this now better :) |
| Directory.CreateDirectory(pluginDir); | ||
| } | ||
|
|
||
| string[] pythonFiles = Directory.GetFiles(pluginDir, "*.py", SearchOption.TopDirectoryOnly); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is okay for simple one file plugins but to house more complex plugins a better structure could be:
Data/Python/Plugins
├── Example-Plugin-1
│ ├── lib/...
│ ├── file.py
│ └── __main__.py (where the main gui file goes)
└── Example-Plugin-2
└── __main__.py
Plugins/RSBot.Python/Bootstrap.cs
Outdated
| public string InternalName => "RSBot.Python"; | ||
|
|
||
| /// <inheritdoc /> | ||
| public string DisplayName => "Plugins"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the name to PyPlugins
| public string DisplayName => "Plugins"; | ||
|
|
||
| /// <inheritdoc /> | ||
| public bool DisplayAsTab => true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be toggleable from the Menubar > Plugins, similiar to how sidebar works but for this tab specifically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added it to the same menu as the sidebar. You can now toggle it on and off and save the settings.
|
|
||
| <Exec Command="powershell -Command "Invoke-WebRequest -Uri '$(PythonZipUrl)' -OutFile '$(PythonRuntimeDir)python_temp.zip'"" Condition="!Exists('$(PythonExePath)')" /> | ||
|
|
||
| <Exec Command="powershell -Command "Expand-Archive -Path '$(PythonRuntimeDir)python_temp.zip' -DestinationPath '$(PythonRuntimeDir)' -Force"" Condition="!Exists('$(PythonExePath)')" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if this was an issue on my end or a small misconfiguration but the archive was unable to extracted even though it was downloaded correctly. I extracted manually and it worked.
I took a build via the build script, maybe there's something going wrong with that ¯\_(ツ)_/¯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried it a few times and different machines and worked fine for me so far
| @@ -0,0 +1,257 @@ | |||
| using System.Drawing; | |||
| using System.Windows.Forms; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the Windows Controls to the available SDUI Controls.
Somehow the SDUI ListView is somehow bugged for me?
Maybe someone else can change the DataGridView to the SDUI ListView for the Plugins
|
Looks good, just needs a few touch ups. Thanks for your work! |
Changed UI-Controls to SDUI Controls where possible
PyPlugins can now be toggled on and off just like the sidebar
|
I think this should be fine for now? Anything else i should change? |



Added Python-Plugins Support.
Added an API to use with Python.
Added Python.Runtime.dll and \Python\PyRuntime to Dependencies folder.
Python.Runtime.dll needs to be copied to \Build\Data\Plugins.
\Python\PyRuntime needs to be copied to \Build\Data
To create Plugins, import the RSBot Module ("from rsbot import *")
A .pyi file will always be created so your ide supports autocomplete
Small Example
from RSBot import *
NAME = "Example Plugin"
DESCRIPTION = "Simple RSBot Plugin as an example"
AUTHOR = "DayDate"
VERSION = "1.0.0"
gui = GUI(NAME)
x = 40
y = 20
gui.TextBox("This is a simple RSBot plugin template.", x, y,100,20)
y += 30
a = gui.CheckBox("This is a checkbox", x, y,50,30)
y += 40
gui.ComboBox("This is a combo box", x, y,100,30)
y += 40
lv = gui.ListBox("listview",x+100, y,100,200)
lv.add_item("Item 1")
lv.add_item("Item 2")
lv.add_item("Item 3")
y += 40
gui.Label("This is a label", x, y,100,20)
y += 30
def on_click():
log(get_inventory())
def on_click_2():
log(get_character())
gui.Button("Start Bot", x, y,100,30,handler=on_click)
y += 40
gui.Button("Data", x, y,100,30,handler=on_click_2)
RSBot Python API Documentation
This document outlines the available modules and functions exposed to the Python scripting engine within RSBot.
1. Core Module (
core)General bot control, logging, and networking functions.
Functions
log(*args): Logs messages to the bot's main console. Accepts multiple arguments.start_bot(): Starts the bot logic. ReturnsTrueif successful.stop_bot(): Stops the bot logic. ReturnsTrueif successful.send_server(opcode, data): Injects a raw packet to be sent to the server.2. Entity Module (
entity)Provides access to game objects like the player, monsters, NPCs, and skills.
Functions
get_character(): Returns a dictionary with player data (Name, HP, MP, Level, EXP, etc.).get_position(): Returns a dictionary withx,y,z, andregion.get_monsters(): Returns a list of dictionaries for all monsters in range.get_npcs(): Returns a list of dictionaries for all NPCs in range.get_skills(): Returns a list of all learned skills.get_active_skills(): Returns a list of currently active buffs/skills.get_mastery(): Returns the player's mastery levels.3. Inventory Module (
inventory)Manages items, inventory, storage, and gold.
Functions
get_inventory(): Returns current gold and lists of items (Inventory, Equipped, Avatar).get_storage(): Returns items in the personal storage.get_guild_storage(): Returns items in the guild storage.get_pet_storage(): Returns items in the active pet's inventory.4. Training Module (
training)Manages the bot's training area and script settings.
Functions
set_training_area(name): Loads a saved training area by its name.set_training_position(x, y, region, radius): Manually defines the training spot.get_training_position(): Returns the currently active training coordinates.5. Quest Module (
quest)Provides access to the quest log.
Functions
get_quests(): Returns a list of active quests, including status, NPCs, and objectives.6. GUI Module (
gui)Allows the creation of custom tabs and visual controls within the RSBot interface.
Initialization
GUI(plugin_name): Initializes a new tab page. Returns a GUI instance.Common Control Methods
set_visible(bool): Shows or hides the control.set_enabled(bool): Enables or disables the control.set_text(string): Sets the display text.move_position(x, y): Moves the control.Controls
Label(text, x, y, width, height): Simple text display.Button(text, x, y, width, height, handler): Clickable button.CheckBox(text, x, y, width, height, handler): Checkbox withget_checked()andset_checked().TextBox(text, x, y, width, height, handler): Input field withget_text()andset_text_value().ComboBox(text, x, y, width, height, handler): Dropdown menu.ListBox(text, x, y, width, height, handler): Scrollable list.7. Config Module (
config)Helper functions for file paths.
Functions
get_config_dir(): Returns the path to the User directory.get_config_path(): Returns the path to the character-specific config.get_log_dir(): Returns the path to the log directory.