Jump to content

[help] get object stat


wafihsn

Recommended Posts

my qustion is this :

how do i get object state ? i will explain , lets say i wanna chope down a tree , but if its already beeing choped or there is a player choping it i want the scrept to select another tree or wait , same this with logs , when i fire logs i want the script wait until the log is fired and then fire the next log , thank ,

i know im kind of "alot of qustion" guy but i issuer u when i get us for the work with this api ill be much more help then "need help" , waiting for replay thanx ..

Link to comment
Share on other sites

Check for players chopping around the tree. You could do a simple check of any Player within 3 tiles of the tree and if they are animating, a better check would be to check the trees perimeter and possibly if they are facing the tree (since trees can be close to eachother). Depends how specific you need to get.

 

For the fire, just keep watching the Position you are attempting to light on (not your current position as you will move) for a fire, or just check when your done animating (might not work if theres a break in the animation).

 

Sorry for no code, I'm sure someone else can help :p.

Link to comment
Share on other sites

my qustion is this :

how do i get object state ? i will explain , lets say i wanna chope down a tree , but if its already beeing choped or there is a player choping it i want the scrept to select another tree or wait , same this with logs , when i fire logs i want the script wait until the log is fired and then fire the next log , thank ,

i know im kind of "alot of qustion" guy but i issuer u when i get us for the work with this api ill be much more help then "need help" , waiting for replay thanx ..

 

For checking if your player is chopping a tree you can just check if your player is animating:

if(myPlayer().isAnimating()) // player is performing the chop animation, so is cutting a tree

For finding the tree with the fewest players chopping it, you could try doing something like:

private Optional<RS2Object> getTreeWithFewestPlayers() {
    return getObjects()
           .getAll()
           .stream()
           .filter(obj -> obj.getName().equals("Tree"))
           .min((tree1, tree2) -> Long.compare(getNumPlayersInteracting(tree1), getNumPlayersInteracting(tree2)));
}
    
private long getNumPlayersInteracting(final Entity entity) {
    return getPlayers().getAll().stream().filter(player -> player.getInteracting() == entity && player.isAnimating()).count();
}

For lighting a fire you could sleep until your position changes (because after you light a fire your player walks to another tile):

if(!isItemWithNameSelected("Tinderbox")) getInventory().interact("Use", "Tinderbox");
else lightFire();

private boolean isItemWithNameSelected(final String itemName) {
    final String selectedItemName = getInventory().getSelectedItemName();
    return selectedItemName != null && selectedItemName.equals(itemName);
}

private void lightFire() {
    if(getInventory().getItem("Logs").interact()){
        final Position playerPos = myPosition();
        new ConditionalSleep(20_000) {
            @Override
            public boolean condition() throws InterruptedException {
                return !myPosition().equals(playerPos) && !myPlayer().isMoving();
            }
        }.sleep();
    }
}
Edited by Explv
  • Like 1
Link to comment
Share on other sites

 

For chopping a tree you can just check if your player is animating:

if(myPlayer().isAnimating()) // player is performing the chop animation, so is cutting a tree

For lighting a fire you could sleep until your position changes (because after you light a fire your player walks to another tile):

if(!isItemWithNameSelected("Tinderbox")) getInventory().interact("Use", "Tinderbox");
else lightFire();

private boolean isItemWithNameSelected(final String itemName) {
    final String selectedItemName = getInventory().getSelectedItemName();
    return selectedItemName != null && selectedItemName.equals(itemName);
}

private void lightFire() {
    if(getInventory().getItem("Logs").interact()){
        final Position playerPos = myPosition();
        new ConditionalSleep(20_000) {
            @Override
            public boolean condition() throws InterruptedException {
                return !myPosition().equals(playerPos) && !myPlayer().isMoving();
            }
        }.sleep();
    }
}

great i understand the way u used it , but there is one problem , if the player get back on the same path where he connot deploy logs and fire them , how can i tell the player to change direction if there is any problem firing them ?

Link to comment
Share on other sites

great i understand the way u used it , but there is one problem , if the player get back on the same path where he connot deploy logs and fire them , how can i tell the player to change direction if there is any problem firing them ?

 

I think that when firemaking the player will always walk in one specific direction after lighting a log.

 

I can't remember if it is North, East, South or West, but it is one of those.

 

So, for example, if the player always walks South after lighting a log. Just make sure that the first position in the line where the player will light, is the Northern most position. That way, the player will never walk back over his fires.

 

However, if this is not possible, you could always check if the player can light a fire in the current position, and walk to a different one if a fire cannot be lit. Maybe something like this would work?

private boolean canPlayerLightAFire() {
    return getObjects().filter(new PositionFilter<>(myPosition())).size() == 0;
}

Alternatively, you can listen for the message "The player cannot light a fire here", or whatever it is, and move if that happens.

Edited by Explv
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...