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

need help finding a good way to make a if statement to a state more reliable.

Featured Replies

My whole script works fine, it's just this

if(SMITH.contains(myPlayer())&&inventory.contains(2353)&&!myPlayer().isAnimating()&&!inventory.contains("Cannonball"))

everything works all fine and dandy until an event comes in the middle of smithing, because when it goes to dismiss a random event, it will have cannon balls and won't go back to smithing, What would be abetter way to do this.

My whole script works fine, it's just this

if(SMITH.contains(myPlayer())&&inventory.contains(2353)&&!myPlayer().isAnimating()&&!inventory.contains("Cannonball"))

everything works all fine and dandy until an event comes in the middle of smithing, because when it goes to dismiss a random event, it will have cannon balls and won't go back to smithing, What would be abetter way to do this.

 

maybe instead of checking if the inventory has cannonballs, check when you have no supplies left to make cannonballs in your inventory? :)

 

Precise

More than likely you're doing this because the player stops animating in between smelting and the bot goes and attempts to smelt again? Just monitor your last smithing xp gain and if it was over a certain threshold then you know you have to smith.

  • Author

maybe instead of checking if the inventory has cannonballs, check when you have no supplies left to make cannonballs in your inventory? smile.png

 

Precise

 

I think I already have that there with the inventory.contains(2353)//2353 is steel bar id

When I had it without the cannonballs, it would constantly go back and redo the entire process of selecting the steel bar, furnace, then clicking on steel bars and making all again. and it would do this after every 3 or 4 cannon balls.

 

case SMITH:
			Entity furnace = objects.closest("Furnace");
			sleep(random(1000,2000));
			inventory.interact("Use", 2353);
				sleep(random(500,1000));
				furnace.interact("Use");
				sleep(random(2000,3000));
				if(!inventory.isItemSelected())
				{
					this.interfaces.interactWithChild(309, 2, "Make All");
					
					sleep(random(10000,20000));
					break;
				}

that's my smith state if that helps

Edited by twin 763

maybe instead of checking if the inventory has cannonballs, check when you have no supplies left to make cannonballs in your inventory? smile.png

 

Precise

 

  • Author

what do you do after that if statement?

 

The one that this thread was about or the if statement in my state? The one my thread is talking is return State.SMITH; the one in the code I linked just breaks after a little bit

Pseudocode:

if !got steel bars -> bank
if animating -> idle
else -> smith

Edited by Botre

Pseudocode:

 

if !got steel bars -> bank

else {

 

}

 

this^^

 

what is should be:

 if(SMITH.contains(myPlayer()) && inventory.contains(2353) && !myPlayer().isAnimating()) {
   //smith
 }
  • Author

 

Pseudocode:

if !got steel bars -> bank
if animating -> idle
else -> smith

I had animating originally, but the smithing animation stops for about 2 seconds or so inbetween, so it goes back and does it all over again. I'm going to try an idea I had to see if that works i'll report back.

 

Why not do something like;

		// Check the distance on how close we are
		if ((myPlayer().getX() - objects.closest("Furnace").getX()) < 3 && (myPlayer().getY() - objects.closest("Furnace").getY()) < 3){
			// Check if we're doing anything
			if (myPlayer().getInteracting() == null && myPlayer().isAnimating() == false){
				// Check if we have steel bars or whatever in our inventory still
				if (inventory.contains("Steel Bar")){
					return somethingSmithingGoesHere;
					// Return to make it start smithing
				}
			}
			
		}

Edit; I'm bored I'll make a c-ball maker.

Edited by 7331337

I had animating originally, but the smithing animation stops for about 2 seconds or so inbetween, so it goes back and does it all over again. I'm going to try an idea I had to see if that works i'll report back.

 

You could track the time since you last animated;

variable t = time since last animation
constant x = duration of the smithing animation

if t exceeds x  ->
           if you still have supplies -> smith
           else -> bank
else -> idle
  • Author

Why not do something like;

		// Check the distance on how close we are
		if ((myPlayer().getX() - objects.closest("Furnace").getX()) < 3 && (myPlayer().getY() - objects.closest("Furnace").getY()) < 3){
			// Check if we're doing anything
			if (myPlayer().getInteracting() == null && myPlayer().isAnimating() == false){
				// Check if we have steel bars or whatever in our inventory still
				if (inventory.contains("Steel Bar")){
					return somethingSmithingGoesHere;
					// Return to make it start smithing
				}
			}
			
		}

Edit; I'm bored I'll make a c-ball maker.

Had no idea getInteracting was a method, that should fix this actually.

 

declare steelBar variable locally or globally depending on where you need it. 

int steelBar;

//assign steelBar a value - find osbot getID method in api - I don't remember it exactly;
if(SMITH.contains(myPlayer())&&inventory.contains(steelBar)&&!myPlayer().isAnimating()) { smith your shit }

So if you have a steel bar, proceed to smith it to cannonballs - else do something else.

 

That's how I'd do it anyway ^^ although I'm new so maybe there are better ways

 

 

 

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

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.