Skip to content

Instantly share code, notes, and snippets.

@KarimiM
Last active August 29, 2015 14:17
Show Gist options
  • Save KarimiM/29f9b26bca319ba1629d to your computer and use it in GitHub Desktop.
Save KarimiM/29f9b26bca319ba1629d to your computer and use it in GitHub Desktop.
OSPVP antirandom
import java.awt.Point;
import java.lang.reflect.Field;
import org.parabot.environment.api.utils.Time;
import org.parabot.environment.input.Mouse;
import org.parabot.environment.scripts.framework.SleepCondition;
import org.parabot.environment.scripts.framework.Strategy;
import org.rev317.min.Loader;
import org.rev317.min.api.methods.Game;
/**
* A anti macro class for OSVeldahar.
* @author Empathy
*
*/
public class AntiRandom implements Strategy {
private Point p1 = new Point(197, 159);
private Point p2 = new Point(258, 161);
private Point p3 = new Point(318, 160);
private final String[] optionOne = { "zamorak", "mithril dag", "bronze scim", "adamant def", "mithril 2h" };
private final String[] optionTwo = { "guthix", "adamant dag", "iron scim", "rune def", "adamant 2h" };
private final String[] optionThree = { "saradomin", "rune dag", "steel scim", "dragon def", "rune 2h" };
public static boolean randomIsActive() {
return Game.getOpenInterfaceId() == 33300;
}
@Override
public boolean activate() {
return randomIsActive();
}
@Override
public void execute() {
System.out.println("Solving Random");
String itemToClick = getText(33302);
System.out.println("Random Event: " + itemToClick);
try {
if (itemToClickContains(itemToClick, optionOne)) {
while (randomIsActive()) {
Mouse.getInstance().click(p1);
Time.sleep(new SleepCondition() {
@Override
public boolean isValid() {
return !randomIsActive();
}
}, 2000);
}
} else if (itemToClickContains(itemToClick, optionTwo)) {
while (randomIsActive()) {
Mouse.getInstance().click(p2);
Time.sleep(new SleepCondition() {
@Override
public boolean isValid() {
return !randomIsActive();
}
}, 2000);
}
} else if (itemToClickContains(itemToClick, optionThree)) {
while (randomIsActive()) {
Mouse.getInstance().click(p3);
Time.sleep(new SleepCondition() {
@Override
public boolean isValid() {
return !randomIsActive();
}
}, 2000);
}
}
} catch (NullPointerException e) {
}
if (!randomIsActive()) {
System.out.println("Random solved!");
} else {
System.out.println("Error - Please report this random to Empathy!");
}
}
private boolean itemToClickContains(String itemToClick, String[] options) {
for (int i = 0; i < options.length; i++) {
if (itemToClick.toLowerCase().contains(options[i])) {
return true;
}
}
return false;
}
public String getText(int id) {
try {
Field text = Loader.getClient().getInterfaceCache()[id].getClass().getDeclaredField("W");
text.setAccessible(true);
return (String) text.get(Loader.getClient().getInterfaceCache()[id]);
} catch (NoSuchFieldException | IllegalAccessException e) {
return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment