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
}
}