September 14, 201510 yr 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
September 14, 201510 yr 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
September 14, 201510 yr Author 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 September 14, 201510 yr by herojord
September 14, 201510 yr 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 September 14, 201510 yr by Joseph
September 14, 201510 yr Author 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 September 14, 201510 yr by herojord
September 14, 201510 yr 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 September 14, 201510 yr by Volta
September 14, 201510 yr Author 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 September 14, 201510 yr by herojord
September 15, 201510 yr 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
September 15, 201510 yr Author 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!
Create an account or sign in to comment