Jump to content
Ragboys is back

Any way to "speed-up" my script?

Recommended Posts

I've been working on a wine grabber to learn more about programming, the tools from API and so on.

However, I realized there are some wine grabber scripts that will react to wine respawn and grab it faster than mine, about 1-2 ticks or so. This means I can NEVER grab the wine before the other bot, making my script useless.

Are there any ways that I can optimize the 'reaction time/speed' of my script? Is the structure of my code wrong? Let me know, taking any suggestions & constructive criticism.

A part of the code:

 

Spoiler

 private void safeZoneProccess() throws InterruptedException{
        if (haveMageLevel()){
            log("Have enough mage level");
         if (!isInventoryFull()){
             log("Inventory is not full");
                if(haveLawrunes()) {
                    log("Have law runes");
                    if (haveWaterRunes()) {
                        log("Have water runes");
                        if (isWearingAirStaff()) {
                            log("Is wearing air staff");
                            if (isInSafeZoneRoom()) {
                                log("Is in wine room");
                                if(!isInCorrectPosition()) {
                                    getWalking().walk(correctPosition);
                                    log("Just walked to correct position l0l");
                                }
                            if(magic.isSpellSelected()) {
                                log("The telekinetic spell is selected");
                                mouse.move(418, 164);
                                camera.moveYaw(186);
                                camera.movePitch(67);

                                if (haveWineInTable()) {
                                    log("Have wine in table. Casting spell now");
                                    status = "Casting spell";
                                    castTelekinetic();
                                    sleep(random(1000, 1672));

                                } else {
                                    log("There's no wine in the table");
                                    status = "Waiting respawn";
                                }

                            }
                            else{
                                selectTelekinetic();
                            }
                            } else {
                                log("Walking to the wine room");
                                status = "Walking to the wine room";
                                walking.webWalk(safeZoneRoom);
                                //getWalking().walk(correctPosition);

                            }
                        } else {
                            log("Wielding air staff");
                            wearAirStaff();
                            status = "Wearing air staff";
                        }
                    }
                    else{
                        log("Getting water runes");
                        getWaterRunes();
                        status = "Getting water runes";
                    }
                }
                else{
                    log("Getting law runes");
                    getLawRunes();
                    status = "Getting law runes";
                }
            }
            else{
                log("Inventory is full. Banking items now");
                status = "Banking";
                if(magic.isSpellSelected()){
                    magic.deselectSpell();
                }
                bankItemsSafeZone();
            }
        }
        else{
            log("Don't have enough mage level. Logging out now");
            logoutTab.logOut();
        }
    }

 @Override
    public final int onLoop() throws InterruptedException {
        safeZoneProccess();



        return random(300, 450);
    }

 

I also need some tips on using conditional sleep, tried using it but couldn't make it work/don't understand it all. Yes, I've read tutorials about them but for somehow I still can't be able to implement it within my script.

Edited by Ragboys is back
Link to comment
Share on other sites

Based off your script, it seems like the spell is selected while waiting which is good. What you can do next is make the cursor hover over the area where the wine gets spawned.

On top of that, you could save the time when the wine was last available and then take that time + spawn rate time + 50 ms and just click in that area. (Try it, not sure how well it works)

Edit:

Look at my post for an explanation on conditional sleep

https://osbot.org/forum/topic/142349-how-do-i-stopprevent-an-action/?tab=comments#comment-1659505

Edited by dreameo
  • Like 1
Link to comment
Share on other sites

7 minutes ago, D Bolter said:

i think it's because you're performing so many checks in a loop before the grab wine is executed.

your script is continuously checking for runes  (since its on a loop) and logging it before it checks if it should grab the wine.

I could be wrong though. I have yet to start scripting.

Those small checks are done in nanoseconds so they're irrelevant in the timing.

 

8 minutes ago, Burundanga said:

ping is a huge factor in who gets first to the wine

This is a major determining factor.

You can also check if the mouse and camera angels are where you want them instead of always setting them prior to checking if a wine is on a table. Also you can have a conditional sleep after your spell is selected that sleeps until the wine appears and instantly clicks without iterating through everything to click.

  • Like 2
Link to comment
Share on other sites

2 minutes ago, dreameo said:

Based off your script, it seems like the spell is selected while waiting which is good. What you can do next is make the cursor hover over the area where the wine gets spawned.

On top of that, you could save the time when the wine was last available and then take that time + spawn rate time + 50 ms and just click in that area. (Try it, not sure how well it works)

Yeah, I thought my script's speed performance would've been fixed once I had the spell selected & mouse hovered over the spawn, and that's what I did in those lines:

  if(magic.isSpellSelected()) {
                                log("The telekinetic spell is selected");
                                mouse.move(418, 164);
                                camera.moveYaw(186);
                                camera.movePitch(67);

Couldn't find a better way to hover the mouse but the code I wrote seems to be working just fine. 

I didn't think about using the respawn time to instant grab the wine, but it's definetely a great suggestion. I'll for sure check that out, thanks.

Link to comment
Share on other sites

Hope that by now you understood conditional sleeps, so I won't say anything about that.

I would recommend to rewrite your code from scratch and consider some things like not checking if you have law and water runes in two steps. This won't improve performance drastically, but will keep the code cleaner and easier to work with. e.g.

private boolean hasRunes() {
	return inventory.contains("Law rune") && inventory.contains("Air rune");
}

I would also rewrite this

log("The telekinetic spell is selected");
                                mouse.move(418, 164);
                                camera.moveYaw(186);
                                camera.movePitch(67);

To something like if the wine or counter or certain position is not visible, then and only then move the camera around. Would put this in the topmost code block whenever you are sure that you are in the right place.

You can leave the mouse.move(418, 164); after you select the spell.

  • Like 1
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.

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