Jump to content
Syndo

Script stops when paused or when logged back in from a dc/break

Recommended Posts

1 hour ago, Syndo said:

package test;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.util.concurrent.TimeUnit; 

import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.map.constants.Banks;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.model.Player;
import org.osbot.rs07.api.ui.Message;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(author = "Syndo", info = "", logo = "", name = "Syndo's Fishing", version = 0)
public class Aiofishing extends Script {
	
	private long timeBegan;
	private long timeRan;
	int levelsgained = 0;
	
	public void onStart() throws InterruptedException {
		
		this.getBot().addMessageListener(this);
		timeBegan = System.currentTimeMillis();
		
		getExperienceTracker().start(Skill.FISHING);
		int fishinglvl = getSkills().getStatic(Skill.FISHING);
		
		if (fishinglvl >= 21) {
			log("Level for trout");
			Position vbank = new Position (3184, 3436, 0);
			Position vbank1 = new Position (3184, 3439, 0);
			Position vbank2 = new Position (3185, 3438, 0);
			Position vbank3 = new Position (3185, 3437, 0);
			
			Position trout = new Position (3109, 3434, 0);
			Position trout1 = new Position (3109, 3433, 0);
			Position trout2 = new Position (3109, 3432, 0);
			Position trout3 = new Position (3103, 3425, 0);
			
			getWalking().webWalk(vbank, vbank1, vbank2, vbank3);
			getBank().open();
			if(getBank().isOpen()) {
				sleep(random(100,600));
				getBank().depositAll();
				if(getInventory().isEmpty()) {
					sleep(random(100,600));
					getBank().withdraw(309, 1);
					sleep(random(100,600));
					getBank().withdrawAll(314);
					sleep(random(100,600));
					getBank().close();
					if(!getBank().isOpen()) {
						if (getInventory().contains(314 , 309)) {
							sleep(random(100,600));
							getWalking().webWalk(trout,trout1,trout2,trout3);
					}
				}
			}
		}
	}
		
		
		if (fishinglvl < 20) {
			log("Level for shrimp");
			Position lumbank = new Position(3209, 3220, 2);
			Position lumbank1 = new Position(3208, 3220, 2);
			Position lumbank2 = new Position(3210, 3220, 2);
			Position lumbank3 = new Position(3208, 3219, 2);
			
			Position lumbswamp = new Position(3243, 3152, 0);
			Position lumbswamp1 = new Position(3241, 3149, 0);
			Position lumbswamp2 = new Position(3238, 3147, 0);
			Position lumbswamp3 = new Position(3240, 3143, 0);
			
			
			getWalking().webWalk(lumbank, lumbank1, lumbank2, lumbank3);
			getBank().open();
			if (getBank().isOpen()) {
				sleep(random(100,600));
				getBank().depositAll();
				if(getInventory().isEmpty()) {
					sleep(random(100,600));
					getBank().withdraw(303, 1); //small net
					sleep(random(100,600));
					getBank().close();
					if(!getBank().isOpen()) {
						if(getInventory().contains(303)) {
							sleep(random(100,600));
							getWalking().webWalk(lumbswamp,lumbswamp1,lumbswamp2,lumbswamp3);
						}
					}
				}
			}
		}
	}
	
	
	
	public int onLoop() throws InterruptedException {
		
		getExperienceTracker().start(Skill.FISHING);
		int fishinglvl = getSkills().getStatic(Skill.FISHING);
		Player player = myPlayer();
		
		if (fishinglvl >= 21) {
			//from on start player should already be at barbarian village
			NPC troutfishingspot = getNpcs().closest(1526);
			if (troutfishingspot != null) {
				if(!player.isMoving()) {
					if(!player.isAnimating()) {
						sleep(random(100,600));
						troutfishingspot.interact("Lure");
						sleep(random(1000, 3000));
						if(getInventory().isFull()) {
							sleep(random(100,600));
							getInventory().dropAllExcept(314 , 309);
						}
					}
				}
			}
			
		}
		
		if (fishinglvl < 20) {
			// from on start player should already be at swamp
			NPC fishingspot = getNpcs().closest(1530);
			if (fishingspot != null) {
				if (!player.isAnimating()) {
					if (!player.isMoving()) {
						sleep(random(100,600));
						fishingspot.interact("Net");
						sleep(random(1000,3000));
						if (getInventory().isFull()) {
							sleep(random(100,600));
							getInventory().dropAllExcept(303);
							}
						}
					}
				}
		}

		return 50;
	}
	
	public void onMessage(Message message) {
		String text = message.getMessage().toLowerCase();
		if (text.contains("just advanced your fishing level")) {
			log("You advanced a fishing level!");
			levelsgained++;
			log("You have gained "+ levelsgained +" fishing levels");
		}
	}
	
	public void onExit() {
		
	}
	
	public void onPaint(Graphics2D g) {
		
		timeRan = System.currentTimeMillis() - this.timeBegan; 
		
		g.setColor(Color.GREEN);
		g.drawString("Syndo's Fishing", 15, 50 );
		g.drawString("Runtime : "+ft(timeRan), 15, 70); 
		
		Point mP = getMouse().getPosition();

		g.drawLine(mP.x - 5, mP.y + 5, mP.x + 5, mP.y - 5); 
		g.drawLine(mP.x + 5, mP.y + 5, mP.x - 5, mP.y - 5);
	}
	
	private String ft(long duration) 
	{
		String res = "";
		long days = TimeUnit.MILLISECONDS.toDays(duration);
		long hours = TimeUnit.MILLISECONDS.toHours(duration)
		- TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(duration));
		long minutes = TimeUnit.MILLISECONDS.toMinutes(duration)
		- TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS
		.toHours(duration));
		long seconds = TimeUnit.MILLISECONDS.toSeconds(duration)
		- TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS
		.toMinutes(duration));
		if (days == 0) {
		res = (hours + ":" + minutes + ":" + seconds);
		} else {
		res = (days + ":" + hours + ":" + minutes + ":" + seconds);
		}
		return res;
	} 
	

}

 

 

You should never execute any game interaction code in the onStart method.

onStart is meant for initiliazing data. (Only runs once )
onLoop is meant to do game interaction ^^ (Keeps looping)

That will probably fix you issue already

  • Like 1
Link to post
Share on other sites
15 hours ago, Khaleesi said:

You should never execute any game interaction code in the onStart method.

onStart is meant for initiliazing data. (Only runs once )
onLoop is meant to do game interaction ^^ (Keeps looping)

That will probably fix you issue already

Thanks!

 

  • Like 1
Link to post
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.

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