Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Try asking for help in the chatbox
  • loop seems to be skipping


    Jagg3d
     Share

    Recommended Posts

    Hey guys,

     

    I tried to make my first script today, as I had farmed a load of Unblessed Symbols (through crafting), but then I couldn't find a script which blesses them in the monastery.

     

    As such, I had a go at making the script myself, having a background in C# made my first java experience fairly easy (all things considered).

     

    The script works, for the most part, however it seems to be doing some weird stuff.

     

    For example, in this snippet:

     

     

     

    private void BlessSymbols() {
    	NPC brother = getNpcs().closest(npc -> npc != null && npc.getName().equals("Brother Jered"));
    	Dialogues dialogues = new Dialogues(getClient());
    	if (!getInventory().isEmpty()){
    		int invCount = getInventory().size();
    		for (int i = 0;i<invCount;i++){
    			if (sleepUntil(()->brother.interact("Talk-to"),5000)){
    				sleep(300);
    				if (dialogues.inDialogue()){
    					sleep(300);
    					if (sleepUntil(()->dialogues.clickOption(1),5000)){
    						sleep(300);
    						if (sleepUntil(()->dialogues.clickContinue(),5000)){
    							sleep(300);
    							if (sleepUntil(()->dialogues.clickContinue(),5000)){
    								sleep(300);
    								if (sleepUntil(()->dialogues.clickOption(1),5000)){
    									sleep(300);
    									if (sleepUntil(()->dialogues.clickContinue(),5000)){
    										sleep(300);
    										sleepUntil(()->dialogues.clickContinue(),5000);
    										sleep(300);
    										log("Blessed symbol #" + String.valueOf(i) + " of " + invCount);
    									}
    								}
    							}
    						}
    					}
    				}
    			}
    			sleep(750);
    		}
    	}
    	else {
    		GameObject door = getGameObjects().closest(gameObject -> gameObject != null && gameObject.getName().contains("Door") && gameObject.hasAction("Open") && gameObject.getID() == 1535);
    		sleepUntil(() -> door.interact("Open"), 5000);
    		GoStairs("down");
    	}
    }
    

    (if required I can make a pastebin of this instead, just say the word)

     

     

     

    Because of the log and visual confirmation, I could see that the script doesn't always properly talk to the NPC, sometimes simply not clicking the required option/continues, because of that, it skips that value for "i", simply moving on to the next value.

     

    Of course, as you can imagine, this causes the script to simply keep looping through the exact same code, even though it's only supposed to have to run once.

     

    Any ideas on how I can improve this bit of code to make sure it doesn't skip iterations?

     

    Also, if anyone wants to help out making this, feel free to message me, if I don't get a repo from here, I'll upload it onto github myself & make sure you get permissions for it.

     

    Stuff I still could use some help on:

    • Anti-ban features
    • Paint
    • Other stuff I haven't thought of yet

     

    PS: As I have said, this is my first Java project, so it's my first Dreambot script as well.

    As such, if you have any tips pertaining to "do's and don'ts", feel free to share =)

     

    PPS: If anyone feels like looking at the entire code out of curiosity, I'm not really a hoarder, so here you go (I'll try to keep it updated) Pastebin

    Edited by Jagg3d
    Link to comment
    Share on other sites

    Hey guys,

     

    I tried to make my first script today, as I had farmed a load of Unblessed Symbols (through crafting), but then I couldn't find a script which blesses them in the monastery.

     

    As such, I had a go at making the script myself, having a background in C# made my first java experience fairly easy (all things considered).

     

    The script works, for the most part, however it seems to be doing some weird stuff.

     

    For example, in this snippet:

     

     

     

    private void BlessSymbols() {
    	NPC brother = getNpcs().closest(npc -> npc != null && npc.getName().equals("Brother Jered"));
    	Dialogues dialogues = new Dialogues(getClient());
    	if (!getInventory().isEmpty()){
    		int invCount = getInventory().size();
    		for (int i = 0;i<invCount;i++){
    			if (sleepUntil(()->brother.interact("Talk-to"),5000)){
    				sleep(300);
    				if (dialogues.inDialogue()){
    					sleep(300);
    					if (sleepUntil(()->dialogues.clickOption(1),5000)){
    						sleep(300);
    						if (sleepUntil(()->dialogues.clickContinue(),5000)){
    							sleep(300);
    							if (sleepUntil(()->dialogues.clickContinue(),5000)){
    								sleep(300);
    								if (sleepUntil(()->dialogues.clickOption(1),5000)){
    									sleep(300);
    									if (sleepUntil(()->dialogues.clickContinue(),5000)){
    										sleep(300);
    										sleepUntil(()->dialogues.clickContinue(),5000);
    										sleep(300);
    										log("Blessed symbol #" + String.valueOf(i) + " of " + invCount);
    									}
    								}
    							}
    						}
    					}
    				}
    			}
    			sleep(750);
    		}
    	}
    	else {
    		GameObject door = getGameObjects().closest(gameObject -> gameObject != null && gameObject.getName().contains("Door") && gameObject.hasAction("Open") && gameObject.getID() == 1535);
    		sleepUntil(() -> door.interact("Open"), 5000);
    		GoStairs("down");
    	}
    }
    

    (if required I can make a pastebin of this instead, just say the word)

     

     

     

    Because of the log and visual confirmation, I could see that the script doesn't always properly talk to the NPC, sometimes simply not clicking the required option/continues, because of that, it skips that value for "i", simply moving on to the next value.

     

    Of course, as you can imagine, this causes the script to simply keep looping through the exact same code, even though it's only supposed to have to run once.

     

    Any ideas on how I can improve this bit of code to make sure it doesn't skip iterations?

     

    Also, if anyone wants to help out making this, feel free to message me, if I don't get a repo from here, I'll upload it onto github myself & make sure you get permissions for it.

     

    Stuff I still could use some help on:

    • Anti-ban features
    • Paint
    • Other stuff I haven't thought of yet

     

    PS: As I have said, this is my first Java project, so it's my first Dreambot script as well.

    As such, if you have any tips pertaining to "do's and don'ts", feel free to share =)

    How to improve? Don't nest that much code. I know this is your first script, so good job, but nesting this deep into code is probably one of the worst things you can do.

     

    Instead, try a long list of if/else statements...

     

    if(condition1)

    else if(condition2)

    else if(condition3)

    else condition4

     

    if(condition5)

     

    and so on...

     

     

    Especially for dialogues, you could do this:

            if(getDialogues().canContinue()){
                getDialogues().continueDialogue();
            }
    
    

    Try this:

        private void BlessSymbols() {
            NPC brother = getNpcs().closest(npc -> npc != null && npc.getName().equals("Brother Jered"));
            Dialogues dialogues = getDialogues(); //This is really not needed, you can just call the "getDialogues" everywhere you want to use dialogues.
            if (!getInventory().isEmpty()){
                if(dialogues.inDialogue()){ //If we're in a dialogue
                    if(dialogues.canContinue()) { //And we can continue the dialogue
                        dialogues.continueDialogue(); //Go through the dialogue
                    }else{ //Else, we can't continue, so we're going to see what option to choose.
                        for(String s : dialogues.getOptions()){ //for every available string...
                            if(s.contains("Dialogue text here") || s.contains("Another dialogue text") || s.contains("another dialogue text")) { //check if it's a good string=
                                dialogues.clickOption(s); //if it is, click it.
                            }
                        }
                    }
                }else{ //else we know we're not in a dialogue, so we should talk to the brother
                    if(brother.interact("Talk-to")) { //if we successfully talk to him...
                        sleepUntil(dialogues::inDialogue, 5000); //then sleep until we're in a dialogue with him
                    }
                }
            }
            else {
                GameObject door = getGameObjects().closest(gameObject -> gameObject != null && gameObject.getName().contains("Door") && gameObject.hasAction("Open") && gameObject.getID() == 1535);
                sleepUntil(() -> door.interact("Open"), 5000);
                GoStairs("down");
            }
        }
    
    Edited by Calculus
    Link to comment
    Share on other sites

    How to improve? Don't nest that much code. I know this is your first script, so good job, but nesting this deep into code is probably one of the worst things you can do.

     

    Instead, try a long list of if/else statements...

     

    if(condition1)

    else if(condition2)

    else if(condition3)

    else condition4

     

    if(condition5)

     

    and so on...

    Well, the thing is all those nestings are interactions of some sort, so I need the if-check on them anyways.

    I'm not entirely sure, but I don't think it's possible to be using if (condition1 && condition2) (for example) with these statements.

    I know nesting this deep is bad, but frankly I didn't know how else I could get through the entire NPC dialogue

    Link to comment
    Share on other sites

    Well, the thing is all those nestings are interactions of some sort, so I need the if-check on them anyways.

    I'm not entirely sure, but I don't think it's possible to be using if (condition1 && condition2) (for example) with these statements.

    I know nesting this deep is bad, but frankly I didn't know how else I could get through the entire NPC dialogue

    I edited my comment above, check that out XD

    Link to comment
    Share on other sites

    I edited my comment above, check that out XD

    Looks a lot better than mine, that's for sure :')

    I'd imagine I have to put the if(inDialogue)/else part in the for-loop to make sure it does the entire inventory?

     

    Also, any chance you can recommend anything to use on the 4th line (if (!getInventory().isEmpty()){}) to check if the inventory still contains an "Unblessed symbol"?

    Everything I've tried so far has either thrown an exception, or given fake true values :|

    Link to comment
    Share on other sites

    How to improve? Don't nest that much code. I know this is your first script, so good job, but nesting this deep into code is probably one of the worst things you can do.

     

    Instead, try a long list of if/else statements...

     

    if(condition1)

    else if(condition2)

    else if(condition3)

    else condition4

     

    if(condition5)

     

    and so on...

     

     

    Especially for dialogues, you could do this:

            if(getDialogues().canContinue()){
                getDialogues().continueDialogue();
            }
    
    
    Try this:

        private void BlessSymbols() {
            NPC brother = getNpcs().closest(npc -> npc != null && npc.getName().equals("Brother Jered"));
            Dialogues dialogues = getDialogues(); //This is really not needed, you can just call the "getDialogues" everywhere you want to use dialogues.
            if (!getInventory().isEmpty()){
                if(dialogues.inDialogue()){ //If we're in a dialogue
                    if(dialogues.canContinue()) { //And we can continue the dialogue
                        dialogues.continueDialogue(); //Go through the dialogue
                    }else{ //Else, we can't continue, so we're going to see what option to choose.
                        for(String s : dialogues.getOptions()){ //for every available string...
                            if(s.contains("Dialogue text here") || s.contains("Another dialogue text") || s.contains("another dialogue text")) { //check if it's a good string=
                                dialogues.clickOption(s); //if it is, click it.
                            }
                        }
                    }
                }else{ //else we know we're not in a dialogue, so we should talk to the brother
                    if(brother.interact("Talk-to")) { //if we successfully talk to him...
                        sleepUntil(dialogues::inDialogue, 5000); //then sleep until we're in a dialogue with him
                    }
                }
            }
            else {
                GameObject door = getGameObjects().closest(gameObject -> gameObject != null && gameObject.getName().contains("Door") && gameObject.hasAction("Open") && gameObject.getID() == 1535);
                sleepUntil(() -> door.interact("Open"), 5000);
                GoStairs("down");
            }
        }
    

     

    That still looks like buns dude

    i think this would work? TLporC8.png

    Link to comment
    Share on other sites

    That still looks like buns dude

    i think this would work?

     

    Left the image out just so this topic doesn't grow TOO massive :P

    Anyways, considering it's a dialogue consisting of 3-4 continues (can't count them atm) and 2 options, I'm guessing a while (d.inDialogue()) would be better, no?

     

    Is the final keyword really necessary here btw?

    Link to comment
    Share on other sites

    Left the image out just so this topic doesn't grow TOO massive :P

    Anyways, considering it's a dialogue consisting of 3-4 continues (can't count them atm) and 2 options, I'm guessing a while (d.inDialogue()) would be better, no?

     

    Is the final keyword really necessary here btw?

     

    You want try to keep as much of your logic directing back to my main loop as you can, this will avoid alot of problems in the future, which some loops not ever ending etc.

     

    final isnt necessary, it just shows im not going to change the value of it to something different

    Link to comment
    Share on other sites

    That still looks like buns dude

    i think this would work? TLporC8.png

    lmfao that's worse than mine. You're returning true after talking to the dude...? That's not the purpose of this loop. "BlessSymbols" is. Yours is more like "continueDialogueOrInteractDoorOrInteractBrother".....crap

    Link to comment
    Share on other sites

     Share

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.