Jump to content

Smelting with banking


herojord

Recommended Posts

Hey guys,

Recently I started scripting, I've got a decent level with PHP and web developing so the java basics are easy for me.

 

My problem is : 

I'm making a smithing script for al kharid, I've got the backbone basicly but im kinda stuck with the conditions.

 

Like when the player has 9 iron and 19 coal it needs to walk to the furnace (case smithing) then it needs to make steel bars until it can no longer make them, then it needs to bank. But my brain thinks way to complex so I'm not able to get it to work flawlessly.

 

 private State getState() {
        if (inventory.getAmount("Coal") > 1 && inventory.getAmount("Iron ore") > 0 ){
            return State.SMITH;
            }
        return State.BANK;
    }

^ This is one method I used.

 

Can somebody please make it clear how to condition this the right way :)

 

 

Link to comment
Share on other sites

I'm not sure what you mean by "condition it the right way", is it the logic or java / the API you're having difficulties with?

The logic is quite simple:
 

if we have enough ores and near furnace then SMELT
if we have enough ores and not near furnace then WALK_TO_FURNACE
 
if we don't have enough ores and near bank then BANK
if we don't have enough ores and not near bank then WALK_TO_BANK
Link to comment
Share on other sites

I think it's a logic problem.

I make things to difficult for myself I guess.

 

So if I'm right:

 

This:

private State getState() {
        if (inventory.getAmount("Coal") > 1 && inventory.getAmount("Iron ore") > 0 ){
            return State.SMITH;
            }
        return State.BANK;
    }

Should be:

private State getState() {
        if ( got ores && not close to furnace){
            Walk to furnace
         }
   
        if ( got ores && close to furnace){
            Smelt
         }

        if ( got no ores && not close to bank ){ 
            walk to bank
         }

        if ( got no ores && close to bank){
            bank
         } 

The problem I have is that in this situation what should I compare with, should I use the iron ores or coal or both?

 

 

btw Thanks for the fast respone!

 

Edited by herojord
Link to comment
Share on other sites

I think it's a logic problem.

I make things to difficult for myself I guess.

So if I'm right:

This:

private State getState() {        if (inventory.getAmount("Coal") > 1 && inventory.getAmount("Iron ore") > 0 ){            return State.SMITH;            }        return State.BANK;    }
Should be:

private State getState() {        if ( got ores && not close to furnace){            Walk to furnace         }           if ( got ores && close to furnace){            Smelt         }        if ( got no ores && not close to bank ){             walk to bank         }        if ( got no ores && close to bank){            bank         }
The problem I have is that in this situation what should I compare with, should I use the iron ores or coal or both?

btw Thanks for the fast respone!

Use both because without one you can't make what you need. I say make a boolean that check both supplies. And use that as one of the conditions. Edited by Joseph
  • Like 1
Link to comment
Share on other sites

Use both because without one you can't make what you need. I say make a boolean that check both supplies. And use that as one of the conditions.

 

I know this is a kinda dumb question but how can I use an integer to create a boolean. I mean the variable creation. PHP is not that strict on var types.

 

 

Edited by herojord
Link to comment
Share on other sites

I know this is a kinda dumb question but how can I use an integer to create a boolean. I mean the variable creation. PHP is not that strict on var types.

The function type is boolean. Within the function, you have it return if you have got enough ores, like so:

 

  boolean gotOres() {
       return getInventory().getAmount("Coal") >= 2 && getInventory().getAmount("Iron ore") >= 1;
    }

Then call gotOres() in your getState() like you already have it written.

Edited by Volta
Link to comment
Share on other sites

The function type is boolean. Within the function, you have it return if you have got enough ores, like so:

 

  boolean gotOres() {
       return getInventory().getAmount("Coal") >= 2 && getInventory().getAmount("Iron ore") >= 1;
    }

Then call gotOres() in your getState() like you already have it written.

I've got this atm:

private Position[] pathto = {
            new Position(3276, 3171, 0),new Position(3280, 3181, 0)
    };

	private Position[] pathback = {
            new Position(3280, 3181, 0), new Position(3276, 3171, 0)
    };
		
	boolean gotOres() {
       return getInventory().getAmount("Coal") >= 2 && getInventory().getAmount("Iron ore") >= 1;
    }
	
	
	boolean gotFurnace() {
	       return objects.closest("Furnace").isVisible();
	}
	
	boolean gotBankbooth() {
	       return objects.closest("Bank booth").isVisible();
	}
	
	
	

 private enum State {
  SMITH, BANK, WALKTO, WALKBACK
 };

 private State getState() {
        if (gotOres() == true && gotFurnace() == true){
            return State.SMITH;
         }
        
        if(gotFurnace() == false && gotOres() == true ){
        	return State.WALKTO;
        }
     
        
        if(gotBankbooth() == false && gotOres() == false){	
        	return State.WALKBACK;
        }
        
        
        	return State.BANK;
        

    } 

This is not working because getstate needs a default so whats the best approach for this situation?

I've added the boolean variables. (thanks for that)

Edited by herojord
Link to comment
Share on other sites

You got the ore boolean which works. But the other two methods you are using them wrong. The furnace and bank booth are entitys. You should rather compare the distance between you and the entity that you are Looking for.

Use this same logic.

I'm not sure what you mean by "condition it the right way", is it the logic or java / the API you're having difficulties with?

The logic is quite simple:

 

if we have enough ores and near furnace then SMELT

if we have enough ores and not near furnace then WALK_TO_FURNACE

 

if we don't have enough ores and near bank then BANK

if we don't have enough ores and not near bank then WALK_TO_BANK

Link to comment
Share on other sites

You got the ore boolean which works. But the other two methods you are using them wrong. The furnace and bank booth are entitys. You should rather compare the distance between you and the entity that you are Looking for.

Use this same logic.

 

 

Yeah I kinda figured that out but thanks, makes things clear for me!

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