liverare Posted September 23, 2017 Share Posted September 23, 2017 Find people wearing stuff. Note: doesn't work with ammo and rings. Example code: import java.util.List; import org.osbot.rs07.api.def.ItemDefinition; import org.osbot.rs07.api.model.Player; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import com.liverare.api.AppearanceAPI; @ScriptManifest(author = "", info = "", logo = "", name = "Test", version = 0) public class Test extends Script { AppearanceAPI appearance; @Override public void onStart() throws InterruptedException { appearance = new AppearanceAPI(); appearance.exchangeContext(bot); } @Override public int onLoop() throws InterruptedException { pesterRichPeopleForFreeStuff(); return 100; } private void pesterRichPeopleForFreeStuff() { List<Player> richPeople = appearance.findPlayersWielding(Test::isExpensiveItem); if (richPeople != null && !richPeople.isEmpty()) { // rich people spotted! // prepare for pestering // in 3... } } private static boolean isExpensiveItem(ItemDefinition itemDefinition) { String itemName = itemDefinition.getName(); return itemName.equals("Twisted bow") || itemName.equals("3rd age longsword") || itemName.equals("3rd age pickaxe") || itemName.equals("3rd age axe") || itemName.equals("3rd age cloak") || itemName.equals("Elysian spirit shield") || itemName.equals("3rd age bow"); } } Methods: public List<Player> findPlayersWielding(List<Player> players, Predicate<ItemDefinition> itemDefinitionFilter) public List<Player> findPlayersWielding(Predicate<ItemDefinition> itemDefinitionFilter) public Player findPlayerWielding(List<Player> players, Predicate<ItemDefinition> itemDefinitionFilter) public Player findPlayerWielding(Predicate<ItemDefinition> itemDefinitionFilter) public static boolean isDefined(Player player, Predicate<ItemDefinition> itemDefinitionFilter) private static boolean isDefined(int[] appearance, Predicate<ItemDefinition> itemDefinitionFilter) Source: package com.liverare.api; import java.util.ArrayList; import java.util.List; import java.util.function.Predicate; import org.osbot.rs07.api.def.ItemDefinition; import org.osbot.rs07.api.model.Player; import org.osbot.rs07.script.API; /** * Appearance API * * @author LiveRare * */ public class AppearanceAPI extends API { @Override public void initializeModule() { } /** * Find players wielding specific items * * Note: rings are not retrieved * * @param players * - Players to filter * @param itemDefinitionFilter * - Filter * @return List of filtered players * @see {@link AppearanceAPI#isDefined(Player, Predicate)} */ public List<Player> findPlayersWielding(List<Player> players, Predicate<ItemDefinition> itemDefinitionFilter) { List<Player> results = null; if (players != null && !players.isEmpty() && itemDefinitionFilter != null) { results = new ArrayList<>(); for (Player player : players) { if (isDefined(player, itemDefinitionFilter)) { results.add(player); } } } return results; } /** * Find players wielding specific items * * Note: rings are not retrieved * * @param itemDefinitionFilter * - Filter * @return List of filtered players * @see {@link AppearanceAPI#findPlayersWielding(List, Predicate)} */ public List<Player> findPlayersWielding(Predicate<ItemDefinition> itemDefinitionFilter) { return findPlayersWielding(players.getAll(), itemDefinitionFilter); } /** * Find first player wielding specific items * * Note: rings are not retrieved * * @param players * - Players to filter * @param itemDefinitionFilter * - Filter * @return List of filtered players * @see {@link AppearanceAPI#findPlayersWielding(List, Predicate)} */ public Player findPlayerWielding(List<Player> players, Predicate<ItemDefinition> itemDefinitionFilter) { Player result = null; List<Player> filtered = findPlayersWielding(players, itemDefinitionFilter); if (filtered != null && !filtered.isEmpty()) { result = filtered.get(0); } return result; } /** * Find first player wielding specific items * * Note: rings are not retrieved * * @param itemDefinitionFilter * - Filter * @return List of filtered players * @see {@link AppearanceAPI#findPlayerWielding(List, Predicate)} */ public Player findPlayerWielding(Predicate<ItemDefinition> itemDefinitionFilter) { return findPlayerWielding(players.getAll(), itemDefinitionFilter); } /** * Test whether player is wielding a particular item * * @param player * - Player * @param itemDefinitionFilter * - Item filter * @return <tt>Item found on player</tt> * @see {@link AppearanceAPI#isDefined(int[], Predicate)} */ public static boolean isDefined(Player player, Predicate<ItemDefinition> itemDefinitionFilter) { return isDefined(player.getDefinition().getAppearance(), itemDefinitionFilter); } /** * Gets item definitions for the items IDs in 'appearance' and tests them * against the ItemDefinition filter * * @param appearance * - Item IDs * @param itemDefinitionFilter * - Filter * @return <tt>Item found</tt> */ private static boolean isDefined(int[] appearance, Predicate<ItemDefinition> itemDefinitionFilter) { boolean result = false; ItemDefinition itemDefinition = null; if (appearance != null && appearance.length > 0) { for (int itemId : appearance) { if (itemId > 0) { itemId -= 512; itemDefinition = ItemDefinition.forId(itemId); if (itemDefinition != null && itemDefinitionFilter.test(itemDefinition)) { result = true; break; } } } } return result; } } 8 Quote Link to comment Share on other sites More sharing options...
Explv Posted September 23, 2017 Share Posted September 23, 2017 8 minutes ago, liverare said: Find people wearing stuff. Note: doesn't work with ammo and rings. Example code: import java.util.List; import org.osbot.rs07.api.def.ItemDefinition; import org.osbot.rs07.api.model.Player; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import com.liverare.api.AppearanceAPI; @ScriptManifest(author = "", info = "", logo = "", name = "Test", version = 0) public class Test extends Script { AppearanceAPI appearance; @Override public void onStart() throws InterruptedException { appearance = new AppearanceAPI(); appearance.exchangeContext(bot); } @Override public int onLoop() throws InterruptedException { pesterRichPeopleForFreeStuff(); return 100; } private void pesterRichPeopleForFreeStuff() { List<Player> richPeople = appearance.findPlayersWielding(Test::isExpensiveItem); if (richPeople != null && !richPeople.isEmpty()) { // rich people spotted! // prepare for pestering // in 3... } } private static boolean isExpensiveItem(ItemDefinition itemDefinition) { String itemName = itemDefinition.getName(); return itemName.equals("Twisted bow") || itemName.equals("3rd age longsword") || itemName.equals("3rd age pickaxe") || itemName.equals("3rd age axe") || itemName.equals("3rd age cloak") || itemName.equals("Elysian spirit shield") || itemName.equals("3rd age bow"); } } Methods: public List<Player> findPlayersWielding(List<Player> players, Predicate<ItemDefinition> itemDefinitionFilter) public List<Player> findPlayersWielding(Predicate<ItemDefinition> itemDefinitionFilter) public Player findPlayerWielding(List<Player> players, Predicate<ItemDefinition> itemDefinitionFilter) public Player findPlayerWielding(Predicate<ItemDefinition> itemDefinitionFilter) public static boolean isDefined(Player player, Predicate<ItemDefinition> itemDefinitionFilter) private static boolean isDefined(int[] appearance, Predicate<ItemDefinition> itemDefinitionFilter) Source: Reveal hidden contents package com.liverare.api; import java.util.ArrayList; import java.util.List; import java.util.function.Predicate; import org.osbot.rs07.api.def.ItemDefinition; import org.osbot.rs07.api.model.Player; import org.osbot.rs07.script.API; /** * Appearance API * * @author LiveRare * */ public class AppearanceAPI extends API { @Override public void initializeModule() { } /** * Find players wielding specific items * * Note: rings are not retrieved * * @param players * - Players to filter * @param itemDefinitionFilter * - Filter * @return List of filtered players * @see {@link AppearanceAPI#isDefined(Player, Predicate)} */ public List<Player> findPlayersWielding(List<Player> players, Predicate<ItemDefinition> itemDefinitionFilter) { List<Player> results = null; if (players != null && !players.isEmpty() && itemDefinitionFilter != null) { results = new ArrayList<>(); for (Player player : players) { if (isDefined(player, itemDefinitionFilter)) { results.add(player); } } } return results; } /** * Find players wielding specific items * * Note: rings are not retrieved * * @param itemDefinitionFilter * - Filter * @return List of filtered players * @see {@link AppearanceAPI#findPlayersWielding(List, Predicate)} */ public List<Player> findPlayersWielding(Predicate<ItemDefinition> itemDefinitionFilter) { return findPlayersWielding(players.getAll(), itemDefinitionFilter); } /** * Find first player wielding specific items * * Note: rings are not retrieved * * @param players * - Players to filter * @param itemDefinitionFilter * - Filter * @return List of filtered players * @see {@link AppearanceAPI#findPlayersWielding(List, Predicate)} */ public Player findPlayerWielding(List<Player> players, Predicate<ItemDefinition> itemDefinitionFilter) { Player result = null; List<Player> filtered = findPlayersWielding(players, itemDefinitionFilter); if (filtered != null && !filtered.isEmpty()) { result = filtered.get(0); } return result; } /** * Find first player wielding specific items * * Note: rings are not retrieved * * @param itemDefinitionFilter * - Filter * @return List of filtered players * @see {@link AppearanceAPI#findPlayerWielding(List, Predicate)} */ public Player findPlayerWielding(Predicate<ItemDefinition> itemDefinitionFilter) { return findPlayerWielding(players.getAll(), itemDefinitionFilter); } /** * Test whether player is wielding a particular item * * @param player * - Player * @param itemDefinitionFilter * - Item filter * @return <tt>Item found on player</tt> * @see {@link AppearanceAPI#isDefined(int[], Predicate)} */ public static boolean isDefined(Player player, Predicate<ItemDefinition> itemDefinitionFilter) { return isDefined(player.getDefinition().getAppearance(), itemDefinitionFilter); } /** * Gets item definitions for the items IDs in 'appearance' and tests them * against the ItemDefinition filter * * @param appearance * - Item IDs * @param itemDefinitionFilter * - Filter * @return <tt>Item found</tt> */ private static boolean isDefined(int[] appearance, Predicate<ItemDefinition> itemDefinitionFilter) { boolean result = false; ItemDefinition itemDefinition = null; if (appearance != null && appearance.length > 0) { for (int itemId : appearance) { if (itemId > 0) { itemId -= 512; itemDefinition = ItemDefinition.forId(itemId); if (itemDefinition != null && itemDefinitionFilter.test(itemDefinition)) { result = true; break; } } } } return result; } } Good job kid I'm proud of you 1 Quote Link to comment Share on other sites More sharing options...
Chris Posted September 23, 2017 Share Posted September 23, 2017 xd 1 Quote Link to comment Share on other sites More sharing options...
progamerz Posted September 24, 2017 Share Posted September 24, 2017 Really important thank you veryy much! and really u saved many lives of bots Quote Link to comment Share on other sites More sharing options...