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 43 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 } } Link to comment Share on other sites More sharing options...
Neffarion 485 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 } Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.