Jump to content

Noob (me) can't get script to be recognized by Osbot


CoffeeNow

Recommended Posts

Hey! First attempt at developing scripts and I've worked through most issues:

1. The code compiles without errors.

2. When building the artifact, I have it set up correctly so that the import features from osbot work properly. 
3. The jar file does appear in the OSbot script folder but does not appear in the OsBot's script list. 

Here is the code. Any suggestions are greatly appreciated!

PS: my goal is to make a script function, then I will return and actually make it a good script. Therefore, don't worry too much about the code logic but rather that it will load in osbot.

 

BeggingScript.java

Edited by CoffeeNow
I believe I linked the code wrong. Sorry, first time!
Link to comment
Share on other sites

Code if I didn't like it properly. My bad!

 

import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.util.concurrent.TimeUnit;
import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(author = "You", info = "Begging Script", name = "BeggingScript", version = 0, logo = "")
public class Main extends Script {

    private static final Position START_POSITION = new Position(3200, 3200, 0);  // replace with actual coordinates
    private long lastMessageTime = System.currentTimeMillis();
    private static final long MESSAGE_INTERVAL = TimeUnit.SECONDS.toMillis(30); // send a message every 30 seconds
    private boolean isInTrade = false;

    @Override
    public void onStart() {
        log("Begging Script Started!");
    }

    @Override
    public int onLoop() throws InterruptedException {
        if (!isInTrade) {
            checkAndSendMessage();
        }
        checkForTrade();
        handleInventory();
        return random(200, 300);
    }

    // Sends a begging message at intervals
    private void checkAndSendMessage() {
        if (System.currentTimeMillis() - lastMessageTime > MESSAGE_INTERVAL) {
            getKeyboard().typeString("Can anyone spare 5k?", true); // type the begging message
            lastMessageTime = System.currentTimeMillis();
        }
    }

    // Check if we are in a trade, handle it
    private void checkForTrade() throws InterruptedException {
        if (getTrade().isCurrentlyTrading()) {
            isInTrade = true;
            log("Trade detected, handling trade...");
            handleTrade();
        } else {
            isInTrade = false;
        }
    }

    // Handles the trade interaction
    private void handleTrade() throws InterruptedException {
        long tradeStartTime = System.currentTimeMillis();
        while (getTrade().isCurrentlyTrading()) {
            if (getTrade().isFirstInterfaceOpen()) {
                getTrade().acceptTrade();  // click accept in the first trade window
            } else if (getTrade().isSecondInterfaceOpen()) {
                getTrade().acceptTrade();  // click accept in the second trade window
            }

            // If the trade takes too long, decline it
            if (System.currentTimeMillis() - tradeStartTime > 60000) {
                log("Trade taking too long, declining...");
                getTrade().declineTrade();
                break;
            }

            // Check if the player is dragged more than 3 tiles away and cancel the trade
            if (myPlayer().getPosition().distance(START_POSITION) > 3) {
                log("Trade dragging detected, cancelling trade...");
                getTrade().declineTrade();
                getWalking().webWalk(START_POSITION);
                break;
            }
        }
    }

    // Handle full inventory, banking, and returning to start position
    private void handleInventory() throws InterruptedException {
        if (getInventory().isFull()) {
            log("Inventory full, heading to bank...");
            getBank().open();
            if (getBank().isOpen()) {
                getBank().depositAll();
                getKeyboard().pressKey(KeyEvent.VK_ESCAPE);  // exit the bank
            }
        }
        // Return to start position if moved away
        if (myPlayer().getPosition().distance(START_POSITION) > 3) {
            log("Returning to start position...");
            getWalking().webWalk(START_POSITION);
        }
    }

    @Override
    public void onExit() {
        log("Thanks for running the Begging Script!");
    }

    @Override
    public void onPaint(Graphics2D g) {
        // You can add any on-screen painting here for debugging
    }
}


 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...