Jump to content

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


Recommended Posts

Posted

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.

Posted

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

Posted (edited)

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
Posted

 

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.

 

Posted (edited)

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
Posted

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
Posted

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.

Posted
 

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

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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