PrimoFernando 7 Share Posted March 9, 2015 Hey, I defined a area on my scipt, how can i make the script store only trees inside that area? Thanks. Link to comment Share on other sites More sharing options...
Vlad 216 Share Posted March 9, 2015 private final Filter<GameObject> tree_filter = new Filter<GameObject>() { @Override public boolean match(GameObject go) { if (go == null) { return false; } if (!cutArea.contains(go)) { return false; } return true; } }; GameObject tree = getGameObjects().closest(tree_filter); Link to comment Share on other sites More sharing options...
Fran 99 Share Posted March 9, 2015 Lets say you hypothetically defined your Area as, cuttingArea. Your hatchet as Axe & stored values for the trees, this workaround code might help: if (!cuttingArea.contains(getPlayers().myPlayers().getTile()) && getInventory().contains(Axe)) { Tile[] tiles = cuttingArea.getTiles(); Tile cuttingAreaTiles = tiles[Calculations.random(0, tiles.length - 1)]; if (cuttingAreaTiles != null) { getWalking().walk(cuttingAreaTiles); //If you're not in the Area defined, this will //walk you to a random tile inside it else { //else, if you certainly are in the wcing Area, then execute your chopping actions if (tree != null && tree.isOnScreen()) { tree.interact("Chop down"); } } } Link to comment Share on other sites More sharing options...
Pandemic 2469 Share Posted March 10, 2015 private final Filter tree_filter = new Filter() { @Override public boolean match(GameObject go) { if (go == null) { return false; } if (!cutArea.contains(go)) { return false; } return true; } }; GameObject tree = getGameObjects().closest(tree_filter); You can simplify that filter a lot with just this: return go != null && cutArea.contains(go); Vlad 1 Link to comment Share on other sites More sharing options...
PrimoFernando 7 Author Share Posted March 11, 2015 thank you guys. Link to comment Share on other sites More sharing options...
Nuclear Nezz 1995 Share Posted March 11, 2015 Moved to correct section. Link to comment Share on other sites More sharing options...
Recommended Posts