Jump to content
SmaTTeR

How to check if player in certain area?

Recommended Posts

What's the code to check if my player is in a certain area and if it is to walk to another? Tried couple different things and couldn't get it to not error. Making a simple walking script for my first script and this is only problem i'm having so far.

Link to post
Share on other sites
4 hours ago, Lunar said:

if (area.contains(myPosition()) {
  getWalking.webWalk(newArea);
}

area being the area that your character is currently in, newArea being the place you want your character to be.

I reccomend using Explv's Map to make areas.

I tried that and it errors because of contains. But if for say I'm in lumbridge and I want it to check if I'm there can I just put if (area.contains(myPosition()) ? or do I need to define the area that I'm asking if it contains my player?

 

Link to post
Share on other sites
1 hour ago, SmaTTeR said:

 But if for say I'm in lumbridge and I want it to check if I'm there can I just put if (area.contains(myPosition()) ? or do I need to define the area that I'm asking if it contains my player?

 

You'd have to define the area. Explv's map makes it really easy to do that, I linked it in my previous reply.

Link to post
Share on other sites
1 hour ago, SmaTTeR said:

I tried that and it errors because of contains. But if for say I'm in lumbridge and I want it to check if I'm there can I just put if (area.contains(myPosition()) ? or do I need to define the area that I'm asking if it contains my player?

 

You need to define the area. And make sure it's the OSBot Area import and not the Java Area import.

Link to post
Share on other sites
Posted (edited)

so...

Area[] lumbridgeSpawn = {
        new Area(3217, 3219, 3217, 3224),
        new Area(3217, 3226, 3226, 3212)
};

then

if (area.contains(myPosition()) {
  getWalking.webWalk(newArea);
}

would that be right?

 

And these are the imports I have...

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.api.model.Player;
import org.osbot.rs07.api.Walking;
import org.osbot.rs07.script.ScriptManifest;
import java.awt.*;
Edited by SmaTTeR
Link to post
Share on other sites
On 5/9/2021 at 3:15 PM, SmaTTeR said:

so...



Area[] lumbridgeSpawn = {
        new Area(3217, 3219, 3217, 3224),
        new Area(3217, 3226, 3226, 3212)
};

then



if (area.contains(myPosition()) {
  getWalking.webWalk(newArea);
}

would that be right?

 

And these are the imports I have...



import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.api.model.Player;
import org.osbot.rs07.api.Walking;
import org.osbot.rs07.script.ScriptManifest;
import java.awt.*;

why are you importing java.awt.*

i have used osbot for about 3 hours now and I have managed to make a fish->bank bot.. it's super simple.. 

your area is an array not really sure what you are doing there but the area should be: 

final Area MYAREA = new Area(x1,x2, x2,y2); <- this is the 2-dimensional square area, this is the grid

the areas are 2d there is no Z-axis for an area, that would be for a Position

also take a look at 

import org.osbot.rs07.api.map.constants.Banks

has some very useful default locations such as GRAND_EXCHANGE or LUMBRIDGE_UPPER for bank etc

 

then literally all you need to do is webwalk to a position.. so if(MYAREA.contains(myPosition())), then you want to 

getWalking().webWalk(Banks.LUMBRIDGE_UPPER);

for example. I don't believe you can walk to an "area" try walking to a position, which is 

import org.osbot.rs07.api.map.Position;
Edited by rawgreaze
Link to post
Share on other sites
6 hours ago, rawgreaze said:

 


final Area MYAREA = new Area(x1,x2, x2,y2); <- this is the 2-dimensional square area, this is the grid

the areas are 2d there is no Z-axis for an area, that would be for a Position

 

Area area = new Area(0,0,0,0).setPlane(0);

Plane is Z

  • Like 1
Link to post
Share on other sites
2 hours ago, Gunman said:

 


Area area = new Area(0,0,0,0).setPlane(0);

Plane is Z

yes it sets the Z for the whole area i don't think you can make a 3d box can you? like in lumbridge you cant select the whole castle and all floors? you would have to do each floor i suppose.

also i think i know what he did, on the map he used the top 2 numbers and the 2 underneath, he should only be using the top x and y

Link to post
Share on other sites
12 minutes ago, rawgreaze said:

i don't think you can make a 3d box can you?

If you wanted a 3d box you'd have to check each plane. I didn't test but probably works.

private boolean inArea() {
   final Area area = new Area(0,0,0,0);
   for (int i = 0; i < 3; i++) {
      if (area.setPlane(i).contains(myPlayer())) {
         return true;
      }
   }
   return false;
}
Link to post
Share on other sites
11 minutes ago, Malcolm said:

If you wanted a 3d box you'd have to check each plane. I didn't test but probably works.


private boolean inArea() {
   final Area area = new Area(0,0,0,0);
   for (int i = 0; i < 3; i++) {
      if (area.setPlane(i).contains(myPlayer())) {
         return true;
      }
   }
   return false;
}

You could also make an Area[]{} and pass area.contains(myPlayer()) that might work

Link to post
Share on other sites
1 hour ago, rawgreaze said:

You could also make an Area[]{} and pass area.contains(myPlayer()) that might work

If you mean like this then this will probably work as well yes.

private boolean inArea() {
    final Area[] areas = {
            new Area(0, 0, 0, 0).setPlane(0),
            new Area(0, 0, 0, 0).setPlane(1),
            new Area(0, 0, 0, 0).setPlane(2)
    };
    
    for (Area area : areas) {
        if (area.contains(myPlayer())) {
            return true;
        }
    }
    return false;
}

 

Edit: The above is really the same as my original loop, this just declares each area in a predetermined array instead of declaring the area then changing the plane through the loop.

Edited by Malcolm
Link to post
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.

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