Jump to content

Check if a specific entity is null?


Recommended Posts

Posted

d22761d99b.png

Area X: 2 Trees

Area Y: 1 Tree

 

How can I make is so that if my player is in Area Y and when that tree only is null, not the ones in Area X, my player runs to stand in Area X to wait for those trees to spawn or vice versa.

 

I'm hoping there is a way to check for entities in a specific area and if they are null so that I can perform an action based off that info.

Posted

id split the two areas and tree entities if that would work, then for example

 

if (treex != null && myPlayer().getInteracting() == null){
if (!myPlayer().isMoving()){
if (treex.isVisible()) {
treex.interact("chop");
}
}
}
 
else
 
if (treey != null && myPlayer().getInteracting() == null){
if (!myPlayer().isMoving()){
if (treey.isVisible()) {
treey.interact("chop");
}
}
}
 
 
Im rather new to scripting, so ignore me if im trying to go over my knowledge 

 

Posted (edited)

 

I'm hoping there is a way to check for entities in a specific area and if they are null so that I can perform an action based off that info.

        Entity tree = getObjects().closest("Yew tree");
        Area AreaY = new Area(1, 2, 3, 4);
        Area AreaX = new Area(2, 3, 4, 2);

        if (!myPlayer.isMoving() && !myPlayer.isAnimating()) {
        if (tree != null && AreaY.contains(tree.getPosition())) { //if tree exists & is in AreaY
            if (AreaY.contains(myPlayer().getPosition())) { //if we are in AreaY
                tree.interact("chop"); //chop
                return true;
            } else getWalking().walk(AreaY.getRandomPosition());//We aren't in Area Y->walk there
        }

        else if (tree != null && AreaX.contains(tree.getPosition())) { //if tree exists & in AreaX
            if (AreaX.contains(myPlayer().getPosition())) { //if we are in AreaX
                tree.interact("chop"); // chop tree
                return true;
            } else getWalking().walk(AreaX.getRandomPosition()); //we aren't in Area X->walk there
        }
Edited by Gold Scripts
  • Like 2
Posted
        Entity tree = getObjects().closest("Yew tree");
        Area AreaY = new Area(1, 2, 3, 4);
        Area AreaX = new Area(2, 3, 4, 2);

        if (!myPlayer.isMoving() && !myPlayer.isAnimating()) {
        if (tree != null && AreaY.contains(tree.getPosition())) { //if tree exists & is in AreaY
            if (AreaY.contains(myPlayer().getPosition())) { //if we are in AreaY
                tree.interact("chop"); //chop
                return true;
            } else getWalking().walk(AreaY.getRandomPosition());//We aren't in Area Y->walk there
        }

        else if (tree != null && AreaX.contains(tree.getPosition())) { //if tree exists & in AreaX
            if (AreaX.contains(myPlayer().getPosition())) { //if we are in AreaX
                tree.interact("chop"); // chop tree
                return true;
            } else getWalking().walk(AreaX.getRandomPosition()); //we aren't in Area X->walk there
        }

 

Thanks!

 

  • Like 1

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