Jump to content

Two quick questions


Snowydell

Recommended Posts

Ok so here's the part of the code I need help on.

 

private State getState() 
{
if(!myPlayer().isAnimating() && !inventory.isFull())
{
return State.FISH;
}
if(inventory.isFull())
{
return State.DROP;
}
return State.WAIT;
}
 
public int onLoop() throws InterruptedException 
{
switch (getState()) 
{
case FISH:
NPC fishingspot = npcs.closest("Fishing Spot");
fishingspot.interact("Net");
break;
 
case DROP:
if(inventory.isFull())
{
inventory.dropAllExcept("Small fishing net");
}
break;
 
My first question is if it benefits or does the same thing if I put the if statement in the case. As seen in the drop case or can I just leave it out and it will execute the same way since it already declared it needed to drop.
 
Second question is for some reason my player drops the fish fairly slow then after it's all dropped stands around for 10 seconds then goes back to fishing, any fix for these?
 
Thanks :)
Link to comment
Share on other sites

If im understanding you, you are asking if its necessary to have:

 

if(inventory.isFull())
{
return State.DROP;
}

 

 

 

and then again have this: 

 

case DROP:
if(inventory.isFull())
{
inventory.dropAllExcept("Small fishing net");
}
break;

 

?

 

If that is your question, then its not really necessary. What you are doing could be called "Defensive programming". Basically its checking the crap out of everything to make sure that its what you want, which prevents any unwanted results or nulls etc. I am not a fan of state based scripting, I always use task based. Case gets too messy imo, but thats just me. ^_^

  • Like 2
Link to comment
Share on other sites

Yeah that was it, thank you for the answer smile.png, what is task based if it's not to hard to explain.

 

Also does anyone know why my character drops fish slow then stands around for 10 seconds doing nothing until it starts to fish again?

 

 

Oh yea, dropAll is a slow action. There isnt a way to fix it that I know of other than writing your own method.

  • Like 1
Link to comment
Share on other sites

 

 

 

as for the dropping you could try something like:

void dropAllExceptA(String...names) throws InterruptedException {
        if(Tab.INVENTORY.isOpen(this.bot)){
            for(int i = 1; i < 29; i++){
                Item item = inventory.getItemInSlot(i);
                if(item != null && !item.getName().equals(names)){
                    item.interact("Drop");
                    sleep((long) random(0, 0));
                }
            }
        }else{
            tabs.open(Tab.INVENTORY);
            sleep((long) random(0, 0));
        }
    }

    void dropAllExceptB(String...names) throws InterruptedException {
        if(Tab.INVENTORY.isOpen(this.bot)){
           Item[] items = inventory.getItems();
            if(items != null) {
                for (int i = 0; i < items.length; i++) {
                      Item item = items[i];
                    if (item != null && !item.getName().equals(names)) {
                        item.interact("Drop");
                        sleep((long) random(0, 0));
                    }
                }
            }
        }else{
            tabs.open(Tab.INVENTORY);
            sleep((long) random(0, 0));
        }
    }

i dont actually know if there's alot of difference between the methods but you could alter the length of sleeps to make it quicker

Yes i wrote 29.

  • Like 1
Link to comment
Share on other sites

as for the dropping you could try something like:

void dropAllExceptA(String...names) throws InterruptedException {
        if(Tab.INVENTORY.isOpen(this.bot)){
            for(int i = 1; i < 29; i++){
                Item item = inventory.getItemInSlot(i);
                if(item != null && !item.getName().equals(names)){
                    item.interact("Drop");
                    sleep((long) random(0, 0));
                }
            }
        }else{
            tabs.open(Tab.INVENTORY);
            sleep((long) random(0, 0));
        }
    }

    void dropAllExceptB(String...names) throws InterruptedException {
        if(Tab.INVENTORY.isOpen(this.bot)){
           Item[] items = inventory.getItems();
            if(items != null) {
                for (int i = 0; i < items.length; i++) {
                      Item item = items[i];
                    if (item != null && !item.getName().equals(names)) {
                        item.interact("Drop");
                        sleep((long) random(0, 0));
                    }
                }
            }
        }else{
            tabs.open(Tab.INVENTORY);
            sleep((long) random(0, 0));
        }
    }

i dont actually know if there's alot of difference between the methods but you could alter the length of sleeps to make it quicker

Yes i wrote 29.

Hm let me try that thanks :)

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...