Jump to content

Check if a specific entity is null?


Rhetoric

Recommended Posts

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.

Link to comment
Share on other sites

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 

 

Link to comment
Share on other sites

 

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
Link to comment
Share on other sites

        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
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.
Note: Your post will require moderator approval before it will be visible.

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