Skip to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[Getting started] Rust Project Setup - RustRover IDE

Featured Replies

  • Developer

Requirements:
OSBot VIP C++ rank or higher is required to run local scripts.

Rust project setup

I will be using Rustrover as IDE, feel free to use VSCode or whatever you feel comfortable with.
So make sure you have rustrover installed (Free license): https://www.jetbrains.com/rust/

1. Start a new project
2. Give the project a proper name ("test_setup" for my case)

  • Should be your scripters name

  • No capital letters

  • No spaces, replace spaces with an underscore

3. Toolchain = stable-x86_64-pc-windows-msvc
4. Project template = Library
ARTps-Ck.png

Result should be something like this:
u-KSd7e-L.png

5. Remove the "src" folder
6. Create a new folder with your script name (test_script)

  • No capital letters

  • No spaces, replace spaces with an underscore

     6.1 Create a new folder called “src” in this folder
          6.1.1.  Create a new Rust file called “lib” inside the script “src” folder
     6.2 Create a “Cargo.toml” file inside the script folder (or copy paste it from below)

FDf-Kak-B.png


7. Open up the Root “Cargo.toml” file (Bottom one in the image)
     7.1 Empty the file and insert this code block:

[workspace]
members = [
    "test_script"]

8. Open up the scripts “Cargo.toml” file (the one under test_script)
     8.1 Insert this code block:

[package]
name = "test_script"
version = "0.1.0"
edition = "2021"

[dependencies]
osbot_api = { git = "https://github.com/OSBotNative/stub_api", features = ["script"] }

[lib]
crate-type = ["cdylib"]

   
     8.2 Refresh your Cargo, this should look like this
           (If this is not the case remove all in there and add your project, “test_setup” in this case and press refresh)

B4z-PXJK.png

9. Adding a skeleton to your script, Open up the “lib.rs” file in your scripts folder and add this code block:

use osbot_api::api::script::script::Script;
use osbot_api::api::script::script_metadata::{ScriptCategory, ScriptMetadata};
use osbot_api::log::info;

#[no_mangle]
pub extern "C" fn metadata() -> ScriptMetadata {
    ScriptMetadata {
        name: "Test Script".to_string(),
        author: "Khaleesi".to_string(),
        version: 1.00,
        info: "Test script - My First Script".to_string(),
        logo: "https://i.imgur.com/QkTUq3l.png".to_string(),
        category: ScriptCategory::Other,
    }
}

#[osbot_api::script_exports]
pub struct KhalTest {}

impl Script for KhalTest {
    //Constructor in case you want to initialize some variables defined in the struct
    fn new() -> Self {
        Self {}
    }

    //Method called on script start
    fn on_start(&mut self, params: Option<String>) {
        info!("Starting {} V{:.2} - {}", metadata().name, metadata().version, metadata().author);
    }

    //main script loop
    fn on_loop(&mut self) -> i32 {
        info!("Running {}", metadata().name);
        50
    }

    //Method called on script start
    fn on_stop(&mut self) {
        info!("Stopping {}", metadata().name);
    }

    //Required for Message listener, you can define what messageTypes to listen for
    fn get_chat_message_types(&self) -> Vec<ChatMessageType> {
        vec![ChatMessageType::Game, ChatMessageType::Spam]
    }

    //Message listener if needed
    fn on_chat_message(&mut self, chat_message_type: ChatMessageType, chat_message: &RSChatMessage) {

    }
}

10. Using dependencies between your scripts to minimize code duplication
     10.1 Create a new folder on root level "script_dependencies" (No other names allowed)
     10.2 Create a "src" and "Cargo.toml" file just like your script setup

v-Tll-Eu-E.png

     11.3 Open up the "Cargo.toml" and add this code block:

[package]
name = "script_dependencies"
version = "0.1.0"
edition = "2021"

[dependencies]
osbot_api = { git = "https://github.com/OSBotNative/stub_api", features = ["script"] }

     11.4 Open up the Root level "Cargo.toml" and add "script_dependencies" to the members block:

[workspace]
members = [
    "test_script",
    "script_dependencies"
]

12 How to use the dependencies folder
     12.1 create some folder to group certain helper functions, utils, ...
     12.2 Rust is using a module system (kind of like maven) so you will have to some mod.rs files inside those folder to expose your modules
     12.3 Inside the mod.rs files, expose your helper files inside that folder

pub mod interation_utils;

     12.4 Update the lib.rs file inside the "script_dependencies" folder to expose your modules you just created

pub mod interaction;
pub mod inventory;
pub mod utils;

rdnfu-Zf.png

     12.5 Update scripts "Cargo.toml" to use the dependencies project
             Add the script_dependencies under [dependencies] together with the osbot_api

[package]
name = "test_script"
version = "0.1.0"
edition = "2021"

[dependencies]
osbot_api = { git = "https://github.com/OSBotNative/stub_api", features = ["script"] }
script_dependencies = { path = "../script_dependencies" }

[lib]
crate-type = ["cdylib"]


13. so if you want to start creating a new script, create a folder just like before

  • Create scripts folder. src folder with lib.rs and Cargo.toml file

  • Add the script module to [workspace] Cargo.toml file 

14. Building your script, this will be done on a build server that runs in the cloud:
      If you do not have an builder account yet, make a request here: https://osbot.org/forum/forum/253-builder-access-requests/

14.1 The whoe process explained below can be automated by reading this: https://osbot.org/forum/topic/203533-native-automated-compiler/

     14.2 To be able to build your script or scripts we will need a zip file of your project, target folder excluded!
           
There is a maximum set on the server so it should fail automatically when you try this, but don't! :mald:
            What to include: every script folder + script_dependecies folder + cargo.toml (the top layer one)

            image.png
            image.png

     14.3 go to the script builder website and login with your account.

image.png
     14.4 Here you will be able to upload the zip file you just created, after uploading press the rebuild button and it should start rebuilding.
     14.5 You can also see how busy the server is by check the Queue.
     14.6 While the build is running you can click on the Logs button to check what's going on.
     14.7 Refresh the page, your script will show up soon if your build was successfull, else you can check the logs why the build failed
     14.8 After that just download your script or all of them with the download all button
     14.9 Places the dll files in your osbot/scripts folder and it should be visible inside the client after a refresh

  • Khaleesi changed the title to [Getting started] Rust Project Setup - RustRover IDE
  • Khaleesi pinned this topic
  • Khaleesi locked this topic
Guest
This topic is now closed to further replies.

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.