Aap Posted January 25, 2016 Share Posted January 25, 2016 Hello scripters, yesterday i decided to start learning the basic of scripting, to build some easy scripts. I am starting to make a script for the quest goblin diplomacy. i am not done yet, but maybe can you guy's look up ad me code and give some advice on things that i can do better. also i got some questions. package test6; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.api.map.Area; import org.osbot.rs07.api.map.Position; import org.osbot.rs07.api.model.NPC; import org.osbot.rs07.api.model.RS2Object; import org.osbot.rs07.utility.ConditionalSleep; import org.osbot.rs07.api.webwalk.*; import org.osbot.rs07.api.webwalk.map.*; import org.osbot.rs07.api.webwalk.impl.*; import org.osbot.rs07.api.Walking; import java.awt.*; @ScriptManifest(name = "Skeleton2", author = "Alek", version = 1.0, info = "", logo = "") public class main extends Script { private final Area GOBLIN_AREA = new Area (2956, 3512, 2957, 3512); private enum State{ WALK_TO_GOBLIN, BANK, START_QUEST } private State getState(){ if(inventory.contains("goblin mail")) { return State.WALK_TO_GOBLIN; } return State.BANK; } @Override public void onStart() { //Code here will execute before the loop is started } @Override public void onExit() { //Code here will execute after the script ends } @Override public int onLoop() throws InterruptedException { switch (getState()){ case BANK: if (!getInventory().contains("goblin mail")) { /// kijken voor quest items RS2Object bankBooth = (RS2Object) this.objects.closest("Bank booth"); if (bankBooth != null) { if (bankBooth.interact("Bank")) { new ConditionalSleep(10000) { @Override public boolean condition() throws InterruptedException { return getBank().isOpen(); } }.sleep(); if (this.getBank().isOpen()) { this.getBank().bank.withdraw("goblin mail", 3); sleep(random(677, 854)); bank.withdraw("blue dye", 1); sleep(random(377, 544)); bank.withdraw("orange dye", 1); sleep(random(977, 1056)); } } this.bank.close(); } } break; case WALK_TO_GOBLIN: walking.webWalk(GOBLIN_AREA); break; case START_QUEST: NPC npc = npcs.closest("General Bentnoze"); if (npc != null) { npc.interact("Talk-to"); } } break; return 100; //The amount of time in milliseconds before the loop starts over } @Override public void onPaint(Graphics2D g) { //This is where you will put your code for paint(s) } } Here are my questions. 1. is it possible to check you have more then 1 item in your inv? inventory.contains("goblin mail") this is whas i used to check if the player got a goblin mail in hes inv otherwise he will bank to get it. but i want to check it with multiple items. also can you check if more then 1 of the same item? like inventory.contains("goblin mail" ,3) ore something?(because inventory.contains("goblin mail" ,3) doenst work. second question is: walking.webWalk(GOBLIN_AREA); will walk to the specific area, but do i need to close this action if its in the area? because now when he is at the GOBLIN_AREA it keep spamming this in de logger([iNFO][bot #1][01/25 01:48:28 PM]: WebWalkingEvent; We have arrived![iNFO][bot #1][01/25 01:48:28 PM]: WebWalkingEvent; We have arrived![iNFO][bot #1][01/25 01:48:28 PM]: WebWalkingEvent; We have arrived!) and it doenst talk to General Bentnoze( is this because i need to close the webwalkingevent or something? so that its stop spamming. and go futher with the script. and if something is wrong, dont give me the good methode without explain why it whas wrong, because i want to learn Greetz jaap23 and many thx Quote Link to comment Share on other sites More sharing options...
iJodix Posted January 25, 2016 Share Posted January 25, 2016 1. getInventory().getAmount("Goblin mail") 2. Pls show your code. 1 Quote Link to comment Share on other sites More sharing options...
Aap Posted January 25, 2016 Author Share Posted January 25, 2016 1. getInventory().getAmount("Goblin mail") 2. Pls show your code. Do you not see the code? Quote Link to comment Share on other sites More sharing options...
Rudie Posted January 25, 2016 Share Posted January 25, 2016 (edited) 1: getInventory().getItem(item).getAmount() 2: if(!GOBLIN_AREA.contains(myPlayer())) { getWalking().webWalk(GOBLIN_AREA); } if(inventory.contains("goblin mail")) {return State.WALK_TO_GOBLIN;}You keep walking while you have Goblin mail in inventory. Edited January 25, 2016 by Rudie 1 Quote Link to comment Share on other sites More sharing options...
Precise Posted January 25, 2016 Share Posted January 25, 2016 (edited) @ second question, if you are in the goblin area, why would it attempt to walk to the goblin area since you are in it? That is why it is saying it has arrived since you have. Edited January 25, 2016 by Precise 1 Quote Link to comment Share on other sites More sharing options...
iJodix Posted January 25, 2016 Share Posted January 25, 2016 Do you not see the code? Sorry, for some odd reason i somehow missed the code, but anyways, this is the reason why it keeps walking; if(inventory.contains("goblin mail")) { return State.WALK_TO_GOBLIN; } You keep walking while you have Goblin mail in inventory. 1 Quote Link to comment Share on other sites More sharing options...
Aap Posted January 25, 2016 Author Share Posted January 25, 2016 1: getInventory().getItem(item).getAmount() 2: if(!GOBLIN_AREA.contains(myPlayer())) { getWalking().webWalk(GOBLIN_AREA); } if i use getInventory().getItem("goblin mail").getAmount("3") its say that The method getAmount() in the type Item is not applicable for the arguments (String) @ second question, if you are in the goblin area, why would it attempt to walk to the goblin area since you are in it? That is why it is saying it has arrived since you have. i know, but this whas the only way for now that i can get it run from the bank to the goblin area, i will try the methode rudie says Quote Link to comment Share on other sites More sharing options...
Rudie Posted January 25, 2016 Share Posted January 25, 2016 (edited) if i use getInventory().getItem("goblin mail").getAmount("3") its say that The method getAmount() in the type Item is not applicable for the arguments (String) i know, but this whas the only way for now that i can get it run from the bank to the goblin area, i will try the methode rudie says getAmount() returns an integer, meaning you can check if the value equals the amount you want or is higher than the amount you want with basic operators: if(inventory.getItem(item).getAmount() >= 3) { //if inventory contains 3 or more of item, returns true //code to execute when true } Edited January 25, 2016 by Rudie 1 Quote Link to comment Share on other sites More sharing options...
Aap Posted January 25, 2016 Author Share Posted January 25, 2016 getAmount() returns an integer, meaning you can check if the value equals the amount you want or is higher than the amount you want with basic operators: if(inventory.getItem(item).getAmount() >= 3) { //if inventory contains 3 or more of item, returns true //code to execute when true } so correct me if i am wrong( and i am) private State getState(){ if(inventory.getItem("goblin mail").getAmount() >= 3) { return State.WALK_TO_GOBLIN; } return State.BANK; } will check if it got 3 or more in the inv so not it will return false and go to the bank. and if its true it will go to the state.walk_T0_GOBLIN.( i know it will keep walk to the area like you and other said before, but i am doing 1 part at the time) or do i need check it in de state.bank? getting this error now Quote Link to comment Share on other sites More sharing options...
Rudie Posted January 25, 2016 Share Posted January 25, 2016 (edited) so correct me if i am wrong( and i am) private State getState(){ if(inventory.getItem("goblin mail").getAmount() >= 3) { return State.WALK_TO_GOBLIN; } return State.BANK; } will check if it got 3 or more in the inv so not it will return false and go to the bank. and if its true it will go to the state.walk_T0_GOBLIN.( i know it will keep walk to the area like you and other said before, but i am doing 1 part at the time) or do i need check it in de state.bank? getting this error now Try doing just: getInventory().getAmount("Goblin mail") You should actually also check if you aren't already in the area: private State getState(){ if(getInventory().getAmount("Goblin mail") >= 3 && !GOBLIN_AREA.contains(myPlayer())) { return State.WALK_TO_GOBLIN; } return State.BANK; } Plus you check the inventory for "goblin mail", not sure if getting an item from inventory is case sensitive but it should be "Goblin mail". Edited January 25, 2016 by Rudie 1 Quote Link to comment Share on other sites More sharing options...
Aap Posted January 25, 2016 Author Share Posted January 25, 2016 (edited) Try doing just: getInventory().getAmount("Goblin mail") You should actually also check if you aren't already in the area: private State getState(){ if(getInventory().getAmount("Goblin mail") >= 3 && !GOBLIN_AREA.contains(myPlayer())) { return State.WALK_TO_GOBLIN; } return State.BANK; } Plus you check the inventory for "goblin mail", not sure if getting an item from inventory is case sensitive but it should be "Goblin mail". Thank you! i got it is there a easy way to to go to the next case ? now can talk to the goblin and finnish the first dialogues, but when its done i want to move to the next part in case MAKE_GOBLIN_MAIL. and return State.MAKE_GOBLIN_MAIL doenst work in theloop i think? like this http://osbot.org/forum/topic/89816-free-cooks-assistant-quest-completer/ there every new handeling is in the next case Edited January 25, 2016 by jaap23 Quote Link to comment Share on other sites More sharing options...
Explv Posted January 25, 2016 Share Posted January 25, 2016 Thank you! i got it is there a easy way to to go to the next case ? now can talk to the goblin and finnish the first dialogues, but when its done i want to move to the next part in case MAKE_GOBLIN_MAIL. and return State.MAKE_GOBLIN_MAIL doenst work in theloop i think? like this http://osbot.org/forum/topic/89816-free-cooks-assistant-quest-completer/ there every new handeling is in the next case Use configs Quote Link to comment Share on other sites More sharing options...
Aap Posted January 26, 2016 Author Share Posted January 26, 2016 Just try a other way like lisabe used in there cook's assistant quester. package goblin_d; import java.awt.Color; import java.awt.Graphics2D; import java.awt.RenderingHints; import org.osbot.rs07.api.map.Area; import org.osbot.rs07.api.map.Position; import org.osbot.rs07.api.model.GroundItem; import org.osbot.rs07.api.model.NPC; import org.osbot.rs07.api.model.RS2Object; import org.osbot.rs07.api.ui.Message; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.utility.ConditionalSleep; import org.osbot.rs07.api.webwalk.*; import org.osbot.rs07.api.webwalk.map.*; import org.osbot.rs07.api.webwalk.impl.*; import org.osbot.rs07.api.Walking; @ScriptManifest(author = "jappa", info = "goblin", name = "Goblin", version = 1.0, logo = "") public class main extends Script { private final Area GOBLIN_AREA = new Area (2956, 3512, 2957, 3512); private String status = "Starting..."; private int stage = -1; private long startTime; private void updateStage(int stage, String status) { this.stage = stage; this.status = status; } @Override public int onLoop() throws InterruptedException { log("stage: " + stage); switch (stage) { case -1: startTime = System.currentTimeMillis(); updateStage(stage + 1, "Banking."); break; case 0: RS2Object bankBooth = (RS2Object) this.objects.closest("Bank booth"); if (bankBooth != null) { if (bankBooth.interact("Bank")) { new ConditionalSleep(10000) { @Override public boolean condition() throws InterruptedException { return getBank().isOpen(); } }.sleep(); if (this.getBank().isOpen()) { this.getBank().bank.withdraw("goblin mail", 3); sleep(random(677, 854)); bank.withdraw("blue dye", 1); sleep(random(377, 544)); bank.withdraw("orange dye", 1); sleep(random(977, 1056)); } } this.bank.close(); } updateStage(stage + 1, "banking"); break; case 1: getWalking().webWalk(GOBLIN_AREA); updateStage(stage + 1, "walk to Goblins"); break; case 2: NPC Bentnoze = npcs.closest("General Bentnoze"); if (!dialogues.inDialogue()) { if (Bentnoze != null) { if (Bentnoze.isVisible()) { if (Bentnoze.interact("Talk-to")) { new ConditionalSleep(random(1000, 2000)) { public boolean condition() throws InterruptedException { return dialogues.inDialogue(); } }.sleep(); } } else { getCamera().toEntity(Bentnoze); } } } else { if (dialogues.isPendingOption()) { dialogues.completeDialogue("yes, wartface looks fat", "Do you want me to pick an armour colour for you?", "what about a different colour?"); sleep(random(400, 900)); } if (dialogues.isPendingContinuation()) { dialogues.clickContinue(); } } updateStage(stage + 1, "Starting quest"); break; case 3: getInventory().interact("Use", "Blue dye"); sleep(random(400, 900)); getInventory().interact("Use", "Goblin mail"); sleep(random(600, 900)); getInventory().interact("Use", "Orange dye"); sleep(random(400, 900)); getInventory().interact("Use", "Goblin mail"); sleep(random(1100, 1900)); updateStage(stage + 1, "fixing goblin mails"); break; case 4: NPC npc = npcs.closest("General Bentnoze"); if (!dialogues.inDialogue()) { if (npc != null) { if (npc.isVisible()) { if (npc.interact("Talk-to")) { new ConditionalSleep(random(1000, 2000)) { public boolean condition() throws InterruptedException { return dialogues.inDialogue(); } }.sleep(); } } else { getCamera().toEntity(npc); } } } else { if (dialogues.isPendingOption()) { dialogues.completeDialogue("I have some orange armour here"); sleep(random(400, 900)); } if (dialogues.isPendingContinuation()) { dialogues.clickContinue(); } } updateStage(stage + 1, "next dialog"); break; } return 600; } @Override public void onPaint(Graphics2D graphics) { Graphics2D g = (Graphics2D) graphics; g.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF)); g.setColor(Color.CYAN); g.drawString("Status: " + status, 10, 310); g.drawString("Running: " + formatTime(System.currentTimeMillis() - startTime), 10, 330); } private String formatTime(long ms){ long s = ms / 1000, m = s / 60, h = m / 60; s %= 60; m %= 60; h %= 24; return String.format("%02d:%02d:%02d", h, m, s); } } but now it, bank,walk to the goblin,mixs the dye's. and click to npc General Bentnoze but it doenst do the dialogue with him. Quote Link to comment Share on other sites More sharing options...