Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Checking if player is within an area

Featured Replies

New member here, mainly c developer, newer to java, looking to make a cow killing script to warm up. I have read the API.

Using state based scripting, my question is how do I get to check if my character is within a define area assuming I have an area defined.

 

psuedo code for attacking:

if( in cow pen area ) {
    if( not in combat ) {
        if( cow is not in combat) {
	    return State.ATTACK;
	}
    }
}

Edited by namtatehtmit

New member here, mainly c developer, newer to java, looking to make a cow killing script to warm up. I have read the API.

Using state based scripting, my question is how do I get to check if my character is within a define area assuming I have an area defined.

psuedo code for attacking:

if( in cow pen area ) {
    if( not in combat ) {
        if( cow is not in combat) {
	    return State.ATTACK;
	}
    }
}

if (area.contains(myPosition())

Edited by Explv

  • Author

if (area.contains(myPosition())

 

That works, but why do I not need to initialize a player object or anything?

 

Like i just need to call the myposition() method and i get my characters position, where does that information come from?

 

Also where do i look in the API to find other methods that pertain to my character?

Edited by namtatehtmit

That works, but why do I not need to initialize a player object or anything?

 

Like i just need to call the myposition() method and i get my characters position, where does that information come from?

 

Also where do i look in the API to find other methods that pertain to my character?

 

The player object for your own player can be accessed with:

Player player = myPlayer();

The method:

myPosition()

Just does:

myPlayer().getPosition()

Edited by Explv

That works, but why do I not need to initialize a player object or anything?

 

Like i just need to call the myposition() method and i get my characters position, where does that information come from?

 

Also where do i look in the API to find other methods that pertain to my character?

He's giving you pseudo code, you still need to reference the class that deals with the player object.

He's giving you pseudo code, you still need to reference the class that deals with the player object.

 

No, i'm not.

No, i'm not.

I lol'd.

 

Are there benefits doing it your way instead of just doing

if(area.contains(myPlayer()) { 

}

 

I lol'd.

 

Are there benefits doing it your way instead of just doing

if(area.contains(myPlayer()) { 

}

 

No, pretty much the exact same thing.

 

I assume myPosition() calls myPlayer().getPosition()

 

I lol'd.

 

Are there benefits doing it your way instead of just doing

if(area.contains(myPlayer()) { 

}

 

tl;dr It's all the same shit.

 

The Area class has several contains methods:

public boolean contains(Entity entity) {
    return contains(entity.getX(), entity.getY()) && plane == entity.getZ();
}
public boolean contains(Position position) {
    return contains(position.getX(), position.getY()) && plane == position.getZ();
}
public boolean contains(int x, int y, int z) {
    return contains(x, y) && plane == z;
}
public boolean contains(int x, int y) {
    return (new java.awt.geom.Area(polygon)).contains((double)x, (double)y);
}

So, when you call:

area.contains(myPlayer())

That will call the contains(Entity entity) method, because the Player is an Entity, which will then call the contains(int x, int y) method with the x coordinate and y coordinate of that entity, and also check if the z vlaues are the same.

 

When you call:

area.contains(myPosition())

That will call the contains(Position position) method, which will then call the contains(int x, int y, int z) method using the x, y and z coordinates of that Position, which then will call the contains(int x, int y) method, and also check the z values are the same.

 

Either way, they both end up calling the same method contains(int x, int y) which checks that the polygon of the Area contains those coordinates, and also check that the z value is the same.

Closing this, Thanks Explv for posting your detailed response! 

Guest
This topic is now closed to further replies.

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.