snailmail12 0 Share Posted December 3, 2020 Can someone help me check a tile to see if it is empty and if so make a fire? I cant get my head round it. I tried to check if there is a fire on the tile i am standing on but it doesnt worlk can anyone help me out? GameObject logOnFire =GameObjects.closest(Fire); if (!logOnFire.getTile().equals(Players.localPlayer().getTile())){ Link to comment Share on other sites More sharing options...
Aeon 41 Share Posted December 3, 2020 I'm sure there's a more elegant way to do this, but for my Firemaking script I just checked to see if there is a fire on my tile: GameObject fire = GameObjects.closest(FIRE); if (fire != null) { if(fire.distance(getLocalPlayer()) == 0) { // There is a fire on the player's tile } else { // There is NOT a fire on the player's tile } } TheCloakdOne 1 Link to comment Share on other sites More sharing options...
Neffarion 456 Share Posted December 3, 2020 I recommend you do something like this. You can use GameObject#getObjectsOnTile() instead as it uses less resources than having it try to find the closest every time private static final Filter<GameObject> FIRE_FILTER = x -> x != null && x.getName() != null && x.getName().toLowerCase().contains("fire"); public static GameObject getFireOnPlayer(){ GameObject[] objs = GameObjects.getObjectsOnTile(Players.localPlayer().getTile()); if(objs != null){ return Arrays.stream(objs).filter(FIRE_FILTER::match).findFirst().orElse(null); } return null; } // Then just use it like this GameObject fire = getFireOnPlayer(); if(fire != null){ // There is a fire underneath the player }else{ // No fire } Aeon 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now