Jump to content

Script not functioning as intended


Recommended Posts

Posted (edited)

None of this is happening. Why?

 

 
Edited:
@Override
    public int onLoop() throws InterruptedException {
        
        
        if (ClanWarsChest.contains(myPlayer())) {
            
            log("At banking area");
            
            if (!getInventory().onlyContains("Jug of wine")) {
                if (bank.isOpen()) {
                    bank.depositAll();
                    sleep(random(250, 350));
                    bank.withdrawAll("Jug of wine");
                    sleep(random(300, 500));
                    bank.close();
                } else {
                    bank.open();
                }
            } else if (portalArea.contains(myPlayer())) {
                
                log("At portal area");
                
                if (objects.closest("Free-for-all portal") != null) {
                    camera.toEntity(objects.closest("Free-for-all portal"));
                    objects.closest("Free-for-all portal").interact("Enter");
                }
            } else if(portalSpawnArea.contains(myPlayer())){
                walking.walk(combatArea);
            }
            
            else {
                walking.walk(portalArea);
            }
        } else if (combatArea.contains(myPlayer())) {
            log("At combat area");
            if (getInventory().contains("Jug of wine")) {
                if (getSkills().getStatic(Skill.HITPOINTS) - getSkills().getDynamic(Skill.HITPOINTS) > 11) {
                    getInventory().getItem("Jug of wine").interact("Drink");
                    log("Healing");
                }
            }
        }


        return random(100, 200); //The amount of time in milliseconds before the loop starts over
    }

Drinking works.

Edited by sampla
Posted

 

None of this is happening. Why?

 

 

 

 

@Override
    public int onLoop() throws InterruptedException {
        Player player = myPlayer();
        
        if (area1.contains(player)) {
            
            log("At area1");
            
            if (!getInventory().onlyContains("item")) {
                if (bank.isOpen()) {
                    bank.depositAll();
                    sleep(random(250, 350));
                    bank.withdrawAll("item");
                    sleep(random(300, 500));
                    bank.close();
                } else {
                    bank.open();
                }
            } else if (area2.contains(player)) {
                
                log("At area2");
                
                if (objects.closest("object") != null) {
                    camera.toEntity(objects.closest("object"));
                    objects.closest("object").interact("action");
                }
            } else if(area3.contains(player)){
                walking.walk(area3);
            }
            
            else {
                walking.walk(area2);
            }
        } else if (area3.contains(player)) {
            log("At area3");
 
 
the part after this is working.

 

 

In the future, when posting to the scripting help section, please use the code tags. It is the blue button that looks like: < >

 

Are you sure your player is in one of those areas?

 

What is the code after, that does work?

Posted (edited)

don't make an instance of myplayer :p

 

area.contains(myPlayer())

 

does it do anything else , or just that onloop ?

Edited to show the whole thing.

 

In the future, when posting to the scripting help section, please use the code tags. It is the blue button that looks like: < >

 

Are you sure your player is in one of those areas?

 

What is the code after, that does work?

Edited it to show the whole thing, I don't care.

I got the banking area from the snippets here.

Edited by sampla
Posted

None of this is happening. Why?

 

 
Edited:
@Override
    public int onLoop() throws InterruptedException {
        
        
        if (ClanWarsChest.contains(myPlayer())) {
            
            log("At banking area");
            
            if (!getInventory().onlyContains("Jug of wine")) {
                if (bank.isOpen()) {
                    bank.depositAll();
                    sleep(random(250, 350));
                    bank.withdrawAll("Jug of wine");
                    sleep(random(300, 500));
                    bank.close();
                } else {
                    bank.open();
                }
            } else if (portalArea.contains(myPlayer())) {
                
                log("At portal area");
                
                if (objects.closest("Free-for-all portal") != null) {
                    camera.toEntity(objects.closest("Free-for-all portal"));
                    objects.closest("Free-for-all portal").interact("Enter");
                }
            } else if(portalSpawnArea.contains(myPlayer())){
                walking.walk(combatArea);
            }
            
            else {
                walking.walk(portalArea);
            }
        } else if (combatArea.contains(myPlayer())) {
            log("At combat area");
            if (getInventory().contains("Jug of wine")) {
                if (getSkills().getStatic(Skill.HITPOINTS) - getSkills().getDynamic(Skill.HITPOINTS) > 11) {
                    getInventory().getItem("Jug of wine").interact("Drink");
                    log("Healing");
                }
            }
        }


        return random(100, 200); //The amount of time in milliseconds before the loop starts over
    }

Drinking works.

and it doesn't do

log("At banking area");
?
Posted

None of this is happening. Why?

 

 
Edited:
@Override
    public int onLoop() throws InterruptedException {
        
        
        if (ClanWarsChest.contains(myPlayer())) {
            
            log("At banking area");
            
            if (!getInventory().onlyContains("Jug of wine")) {
                if (bank.isOpen()) {
                    bank.depositAll();
                    sleep(random(250, 350));
                    bank.withdrawAll("Jug of wine");
                    sleep(random(300, 500));
                    bank.close();
                } else {
                    bank.open();
                }
            } else if (portalArea.contains(myPlayer())) {
                
                log("At portal area");
                
                if (objects.closest("Free-for-all portal") != null) {
                    camera.toEntity(objects.closest("Free-for-all portal"));
                    objects.closest("Free-for-all portal").interact("Enter");
                }
            } else if(portalSpawnArea.contains(myPlayer())){
                walking.walk(combatArea);
            }
            
            else {
                walking.walk(portalArea);
            }
        } else if (combatArea.contains(myPlayer())) {
            log("At combat area");
            if (getInventory().contains("Jug of wine")) {
                if (getSkills().getStatic(Skill.HITPOINTS) - getSkills().getDynamic(Skill.HITPOINTS) > 11) {
                    getInventory().getItem("Jug of wine").interact("Drink");
                    log("Healing");
                }
            }
        }


        return random(100, 200); //The amount of time in milliseconds before the loop starts over
    }

Drinking works.

 

I think that your portal area checks should not be inside the bank area check.

 

Perhaps if you cleaned up the script a bit, you could more easily identify the issues:

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;

@ScriptManifest(author = "Explv", name = "Wine Drinker", info = "Drinks Wine", logo = "", version = 0.1)
public class WineDrinker extends Script {

    private enum State { BANKING, DRINKING, WALKING_TO_BANK, WALKING_TO_PORTAL, WALKING_TO_COMBAT, TELEPORTING }
    
    private final Area portalArea = new Area(0, 0, 0, 0),
                       bankArea   = new Area(0, 0, 0, 0),
                       spawnArea  = new Area(0, 0, 0, 0),
                       combatArea = new Area(0, 0, 0, 0);
    
    @Override
    public int onLoop() throws InterruptedException {
        switch (getState()){
            case BANKING:
                bank();
                break;
            case DRINKING:
                drink();
                break;
            case WALKING_TO_BANK:
                getWalking().webWalk(bankArea);
                break;
            case WALKING_TO_PORTAL:
                getWalking().webWalk(portalArea);
                break;
            case WALKING_TO_COMBAT:
                getWalking().webWalk(combatArea);
                break;
            case TELEPORTING:
                teleport();
                break;
        }
        return random(200, 300);
    }
    
    private State getState() {
        if(!getInventory().contains("Jug of wine")){
            return bankArea.contains(myPosition()) ? State.BANKING : State.WALKING_TO_BANK;
        }
        if(spawnArea.contains(myPosition())) return State.WALKING_TO_COMBAT;
        if(combatArea.contains(myPosition())) return State.DRINKING;
        return portalArea.contains(myPosition()) ? State.TELEPORTING : State.WALKING_TO_PORTAL;
    }
    
    private void teleport(){
        if(getObjects().closest("Free-for-all portal").interact("Enter")){
            new ConditionalSleep(5000) {
                @Override
                public boolean condition() throws InterruptedException {
                    return !portalArea.contains(myPosition());
                }
            }.sleep();
        }
    }
    
    private void bank() throws InterruptedException {
        if(!getBank().isOpen()) {
            openBank();
        } else if(!getInventory().isEmptyExcept("Jug of wine")) {
            getBank().depositAllExcept("Jug of wine");
        } else if(!getInventory().contains("Jug of wine")){
            if(getBank().contains("Jug of wine")) getBank().withdrawAll("Jug of wine");
            else stop();
        }
    }
    
    private void openBank() throws InterruptedException {
        if(getBank().open()){
            new ConditionalSleep(5000) {
                @Override
                public boolean condition() throws InterruptedException {
                    return getBank().isOpen();
                }
            }.sleep();
        }
    }
    
    private void drink() {
        if (getSkills().getStatic(Skill.HITPOINTS) - getSkills().getDynamic(Skill.HITPOINTS) > 11) {
            getInventory().getItem("Jug of wine").interact("Drink");
        }
    }
}

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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