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
  • Get character into screen view?


    Tweeboy

    Recommended Posts

    While testing a WC script I notice that sometimes my compass is set to a position that hides my character behind a tree (specificaly, an Oak tree). Was currently going to approach it with something like:

    			while (Oak.getCenterPoint().distance(getLocalPlayer().getCenterPoint()) < 50) //Whatever works
    				getCamera().rotateToYaw(getCamera().getYaw()+50);
    

    (I kept trying a getLocalPlayer().isHidden > getCamera().mouseRotateToEntity(getLocalPlayer()) approach but that did nothing, probably cause I'm technically on main screen, my model is just hidden by leaves)

     

    But, if I'm not mistaken, that'd continue to rotate in increments instead to a smooth camera rotation to a view with me on screen. Please tell me I'm just missing something

     

    Any advice is greatly appreciated  :D

    Link to comment
    Share on other sites

    While testing a WC script I notice that sometimes my compass is set to a position that hides my character behind a tree (specificaly, an Oak tree). Was currently going to approach it with something like:

    			while (Oak.getCenterPoint().distance(getLocalPlayer().getCenterPoint()) < 50) //Whatever works
    				getCamera().rotateToYaw(getCamera().getYaw()+50);
    

    (I kept trying a getLocalPlayer().isHidden > getCamera().mouseRotateToEntity(getLocalPlayer()) approach but that did nothing, probably cause I'm technically on main screen, my model is just hidden by leaves)

     

    But, if I'm not mistaken, that'd continue to rotate in increments instead to a smooth camera rotation to a view with me on screen. Please tell me I'm just missing something

     

    Any advice is greatly appreciated  :D

     

    If I understand correctly, the whole problem stems from your camera moving inadvertently when it shouldn't.

     

       boolean customInteract(String action, Entity name) {
            EntityDestination ed = new EntityDestination(getClient(), name);
            InteractionEvent ie = new InteractionEvent(ed);
            if (ie.interact(action, InteractionSetting.MOVE))
                return true;
            return false;
        }
     
    Example usage: customInteract("Chop", tree); //tree is a predefined tree object
     
    This will prevent your camera from moving when interacting with objects, just make sure they're on screen before interacting with them.
     
    That's a strange issue because isOnScreen() doesn't take into account things (walls, trees) blocking the entity from view, only whether it is in the bounds of the main screen.
     
    Let me know if I can be of more help.
    Link to comment
    Share on other sites

     

    If I understand correctly, the whole problem stems from your camera moving inadvertently when it shouldn't.

     

       boolean customInteract(String action, Entity name) {
            EntityDestination ed = new EntityDestination(getClient(), name);
            InteractionEvent ie = new InteractionEvent(ed);
            if (ie.interact(action, InteractionSetting.MOVE))
                return true;
            return false;
        }
     
    Example usage: customInteract("Chop", tree); //tree is a predefined tree object
     
    This will prevent your camera from moving when interacting with objects, just make sure they're on screen before interacting with them.
     
    That's a strange issue because isOnScreen() doesn't take into account things (walls, trees) blocking the entity from view, only whether it is in the bounds of the main screen.
     
    Let me know if I can be of more help.

     

     

    Thanks for the suggestion, will try implementing next time I run script. So far it happens at random; some inventories I'll never be behind a tree, some inventories I'm stuck behind an oak for the entirety of, sometimes it fixes itself or happens multiple times an inventory. 

     

    What I currently have:

     

    case Chop:

    if (Oak != null){
    	if (!Oak.isOnScreen())
    		getCamera().mouseRotateToTile(Oak.getTile()); 
    	Oak.interact("Chop down"); 
    }

    So I'd use custominteract("Chop", Oak) instead?

     

    case Wait:

    if (getCamera().getPitch() < 300)
    	getCamera().mouseRotateToPitch(Calculations.random(300, 380));
    if (getMouse().isMouseInScreen())
    	getMouse().moveMouseOutsideScreen();
    

    This could possibly cause it to line up Oak and my character. Though I would like to keep this.

     

     

     

     

     

    I also just wrote this up. Will calculateModelArea() give me a 2D "Visible on screen" Area? If so, this should work if all else fails.

    while (Oak.getModel().calculateModelArea().contains(getLocalPlayer().getCenterPoint())){
    	switch (getCamera().getYaw()){
    		case 0-1200:
    			getCamera().mouseRotateToYaw(getCamera().getYaw()+Calculations.random(400,600));
    			break;
    		case 1025-2048:	
    			getCamera().mouseRotateToYaw(getCamera().getYaw()-Calculations.random(400,600));
    			break;
    	}
    }
    Link to comment
    Share on other sites

     

    Thanks for the suggestion, will try implementing next time I run script. So far it happens at random; some inventories I'll never be behind a tree, some inventories I'm stuck behind an oak for the entirety of, sometimes it fixes itself or happens multiple times an inventory. 

     

    What I currently have:

     

    case Chop:

    if (Oak != null){
    	if (!Oak.isOnScreen())
    		getCamera().mouseRotateToTile(Oak.getTile()); 
    	Oak.interact("Chop down"); 
    }

    So I'd use custominteract("Chop", Oak) instead?

     

    case Wait:

    if (getCamera().getPitch() < 300)
    	getCamera().mouseRotateToPitch(Calculations.random(300, 380));
    if (getMouse().isMouseInScreen())
    	getMouse().moveMouseOutsideScreen();
    

    This could possibly cause it to line up Oak and my character. Though I would like to keep this.

     

     

     

     

     

    I also just wrote this up. Will calculateModelArea() give me a 2D "Visible on screen" Area? If so, this should work if all else fails.

    while (Oak.getModel().calculateModelArea().contains(getLocalPlayer().getCenterPoint())){
    	switch (getCamera().getYaw()){
    		case 0-1200:
    			getCamera().mouseRotateToYaw(getCamera().getYaw()+Calculations.random(400,600));
    			break;
    		case 1025-2048:	
    			getCamera().mouseRotateToYaw(getCamera().getYaw()-Calculations.random(400,600));
    			break;
    	}
    }

     

    So I'd use custominteract("Chop", Oak) instead?

     
    Yes that is correct.
     
    Also I think you might be looking for getModel().getBoundingBox().
     
    Can you post a screenshot with what the issue is? I'd be happy to help you fix it but I'm not quite sure where/how you're getting stuck.
    Link to comment
    Share on other sites

     

    So I'd use custominteract("Chop", Oak) instead?

     
    Yes that is correct.
     
    Also I think you might be looking for getModel().getBoundingBox().
     
    Can you post a screenshot with what the issue is? I'd be happy to help you fix it but I'm not quite sure where/how you're getting stuck.

     

     

    YyvTGOd.png

     

    From the above, I'd like to turn the camera (preferably with middle mouse) to put me into view.

     

    Also I do not see Oak.getModel().getBoundingBox(), would Oak.getModel().getHullShape() work?

     

    EDIT: getHullShape will not work. I just want to grab the boundaries of those leaves, and if my player's center point on screen is within the boundary, to turn the camera

    Link to comment
    Share on other sites

    YyvTGOd.png

     

    From the above, I'd like to turn the camera (preferably with middle mouse) to put me into view.

     

    Also I do not see Oak.getModel().getBoundingBox(), would Oak.getModel().getHullShape() work?

     

    EDIT: getHullShape will not work. I just want to grab the boundaries of those leaves, and if my player's center point on screen is within the boundary, to turn the camera

     

    This is untested, but it should at least point you in the right direction.

     

    Edit: For testing try painting the oak bounding box and the player center point. The method pretty much rotates the screen ~45 degrees at a time until the point is no longer in the bounding box. 

        private void handleCamera() {
            GameObject oak = getGameObjects().closest(g -> g != null && g.getName().equals("Oak tree"));
            if (oak.getBoundingBox().contains(getLocalPlayer().getCenterPoint())) {
                if (getCamera().getYaw() > 1800) {
                    getCamera().mouseRotateToYaw(Calculations.random(1400, 1600));
                } else if (getCamera().getYaw() > 1400) {
                    getCamera().mouseRotateToYaw(Calculations.random(850, 1150));
                } else if (getCamera().getYaw() > 850) {
                    getCamera().mouseRotateToYaw(Calculations.random(350, 600));
                } else {
                    switch(Calculations.random(0,2)) {
                        case 0: 
                            getCamera().mouseRotateToYaw(Calculations.random(1850, 2037));
                            break;
                        case 1:
                            getCamera().mouseRotateToYaw(Calculations.random(0, 150));
                            break;
                    }
                }
            }
        }
    
    Link to comment
    Share on other sites

     

    This is untested, but it should at least point you in the right direction.

     

    Edit: For testing try painting the oak bounding box and the player center point. The method pretty much rotates the screen ~45 degrees at a time until the point is no longer in the bounding box. 

        private void handleCamera() {
            GameObject oak = getGameObjects().closest(g -> g != null && g.getName().equals("Oak tree"));
            if (oak.getBoundingBox().contains(getLocalPlayer().getCenterPoint())) {
                if (getCamera().getYaw() > 1800) {
                    getCamera().mouseRotateToYaw(Calculations.random(1400, 1600));
                } else if (getCamera().getYaw() > 1400) {
                    getCamera().mouseRotateToYaw(Calculations.random(850, 1150));
                } else if (getCamera().getYaw() > 850) {
                    getCamera().mouseRotateToYaw(Calculations.random(350, 600));
                } else {
                    switch(Calculations.random(0,2)) {
                        case 0: 
                            getCamera().mouseRotateToYaw(Calculations.random(1850, 2037));
                            break;
                        case 1:
                            getCamera().mouseRotateToYaw(Calculations.random(0, 150));
                            break;
                    }
                }
            }
        }

    (oak.getBoundingBox().contains(getLocalPlayer().getCenterPoint())) is not coming back as true  :( does it include the leaves or just the trunk?

    Link to comment
    Share on other sites

    Working on a fix right now. Will get back to you shortly  :)

     

    edit: all of the photos were removed. It returned true when expected, And the bounding box contained all of the leaves and the trunk.

     

    It appears you just have to declare a rectangle and point object. So try this:

      private void handleCamera() {
            Point p = getLocalPlayer().getCenterPoint();
            Rectangle bb = getGameObjects().closest("Oak").getBoundingBox();
            if (p != null && bb != null && bb.contains(p)) {
                if (getCamera().getYaw() > 1800) {
                    getCamera().mouseRotateToYaw(Calculations.random(1400, 1600));
                } else if (getCamera().getYaw() > 1400) {
                    getCamera().mouseRotateToYaw(Calculations.random(850, 1150));
                } else if (getCamera().getYaw() > 850) {
                    getCamera().mouseRotateToYaw(Calculations.random(350, 600));
                } else {
                    switch(Calculations.random(0,2)) {
                        case 0: 
                            getCamera().mouseRotateToYaw(Calculations.random(1850, 2037));
                            break;
                        case 1:
                            getCamera().mouseRotateToYaw(Calculations.random(0, 150));
                            break;
                    }
                }
            }
        }
    
    Link to comment
    Share on other sites

     

    Working on a fix right now. Will get back to you shortly  :)

     

    edit: all of the photos were removed. It returned true when expected, And the bounding box contained all of the leaves and the trunk.

     

    It appears you just have to declare a rectangle and point object. So try this:

      private void handleCamera() {
            Point p = getLocalPlayer().getCenterPoint();
            Rectangle bb = getGameObjects().closest("Oak").getBoundingBox();
            if (p != null && bb != null && bb.contains(p)) {
                if (getCamera().getYaw() > 1800) {
                    getCamera().mouseRotateToYaw(Calculations.random(1400, 1600));
                } else if (getCamera().getYaw() > 1400) {
                    getCamera().mouseRotateToYaw(Calculations.random(850, 1150));
                } else if (getCamera().getYaw() > 850) {
                    getCamera().mouseRotateToYaw(Calculations.random(350, 600));
                } else {
                    switch(Calculations.random(0,2)) {
                        case 0: 
                            getCamera().mouseRotateToYaw(Calculations.random(1850, 2037));
                            break;
                        case 1:
                            getCamera().mouseRotateToYaw(Calculations.random(0, 150));
                            break;
                    }
                }
            }
        }
    

    What I currently am trying to use:

    case WAIT:
    	p = getLocalPlayer().getCenterPoint().getLocation();
    	b = getGameObjects().closest("Oak").getBoundingBox();
    	if (if p != null && b != null && b.contains(p)) {
    		switch (getCamera().getYaw()) {
    		case 0 - 1200:
    			getCamera().mouseRotateToYaw(
    					getCamera().getYaw()
    							+ Calculations.random(400, 600));
    			break;
    		case 1025 - 2048:
    			getCamera().mouseRotateToYaw(
    					getCamera().getYaw()
    							- Calculations.random(400, 600));
    			break;
    		}
    	}
    	if (getCamera().getPitch() < 300)
    		getCamera().mouseRotateToPitch(Calculations.random(300, 380));
    	if (getMouse().isMouseInScreen())
    		getMouse().moveMouseOutsideScreen();
    	sleep(Calculations.random(3000, 5000));
    	break;
    }
    

    Will not rotate me when I'm behind a tree :( . I've got to run out right now but I'll try implementing as its own void instead of being within the main loop and see if that changes anything

    Link to comment
    Share on other sites

    What I currently am trying to use:

    case WAIT:
    	p = getLocalPlayer().getCenterPoint().getLocation();
    	b = getGameObjects().closest("Oak").getBoundingBox();
    	if (if p != null && b != null && b.contains(p)) {
    		switch (getCamera().getYaw()) {
    		case 0 - 1200:
    			getCamera().mouseRotateToYaw(
    					getCamera().getYaw()
    							+ Calculations.random(400, 600));
    			break;
    		case 1025 - 2048:
    			getCamera().mouseRotateToYaw(
    					getCamera().getYaw()
    							- Calculations.random(400, 600));
    			break;
    		}
    	}
    	if (getCamera().getPitch() < 300)
    		getCamera().mouseRotateToPitch(Calculations.random(300, 380));
    	if (getMouse().isMouseInScreen())
    		getMouse().moveMouseOutsideScreen();
    	sleep(Calculations.random(3000, 5000));
    	break;
    }
    

    Will not rotate me when I'm behind a tree :( . I've got to run out right now but I'll try implementing as its own void instead of being within the main loop and see if that changes anything

     

    Your problem lies in the switch I believe. For cases you can't use a range of integers in a traditional way like in C. I think it might be reading those as case -1200 and case -1023, and the yaw can't be negative, thus your code would never execute.

     

    If you want to use states, just try my code down below and see how it goes: 

    case WAIT:
                        Point p = getLocalPlayer().getCenterPoint();
                        Rectangle bb = getGameObjects().closest("Oak").getBoundingBox();
                        if (p != null && bb != null) {
                            if (bb.contains(p)) {    
                                if (getCamera().getYaw() > 1800) {
                                    getCamera().mouseRotateToYaw(Calculations.random(1400, 1600));
                                } else if (getCamera().getYaw() > 1400) {
                                    getCamera().mouseRotateToYaw(Calculations.random(850, 1150));
                                } else if (getCamera().getYaw() > 850) {
                                    getCamera().mouseRotateToYaw(Calculations.random(350, 600));
                                } else {
                                    switch(Calculations.random(0,2)) {
                                        case 0: 
                                            getCamera().mouseRotateToYaw(Calculations.random(1850, 2037));
                                            break;
                                        case 1:
                                            getCamera().mouseRotateToYaw(Calculations.random(0, 150));
                                            break;
                                    }
                                }
                            }  
                        }
                        break;
        
    
    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

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