Skip to content

Instantly share code, notes, and snippets.

@phl0w
Created April 6, 2013 12:59
Show Gist options
  • Select an option

  • Save phl0w/5326042 to your computer and use it in GitHub Desktop.

Select an option

Save phl0w/5326042 to your computer and use it in GitHub Desktop.
import org.powerbot.core.script.ActiveScript;
import org.powerbot.core.script.job.Task;
import org.powerbot.core.script.job.state.Node;
import org.powerbot.core.script.util.Timer;
import org.powerbot.game.api.Manifest;
import org.powerbot.game.api.methods.Game;
import org.powerbot.game.api.methods.Tabs;
import org.powerbot.game.api.methods.Widgets;
import org.powerbot.game.api.methods.input.Keyboard;
import org.powerbot.game.api.util.Random;
import org.powerbot.game.api.wrappers.widget.WidgetChild;
import java.util.ArrayList;
@Manifest(name = "ClanChat Destroyer", authors = {"_phl0w"}, version = 1.0d, description = "Destroys clanchats")
public class ClanChatDestroyer extends ActiveScript {
private static String status = "n/a";
private static String text = "";
private final Node check = new Check();
private static final ArrayList<Node> nodes = new ArrayList<Node>();
private static final ArrayList<String> clans = new ArrayList<String>();
private static final ArrayList<String> names = new ArrayList<String>();
@Override
public int loop() {
if (!text.equals("")) {
nodes.remove(check);
}
for (final Node n : nodes) {
if (n.activate()) {
n.execute();
}
}
log.info("loop");
return 300;
}
public void onStart() {
if (Game.isLoggedIn()) {
status = "Starting up!";
nodes.add(check);
nodes.add(new JoinCC());
} else {
stop();
}
}
public void onStop() {
}
private class Check extends Node {
@Override
public boolean activate() {
return text.equals("");
}
@Override
public void execute() {
if (Tabs.NOTES.isOpen()) {
final WidgetChild notes = Widgets.get(34, 9);
if (notes.getChildren().length == 0) {
log.info("No spam text found! Please enter a note with the text you wish to spam.");
stop();
} else {
text = notes.getChild(0).getText();
log.info("Text found: " + text);
Tabs.INVENTORY.open();
}
} else {
Tabs.NOTES.open();
}
}
}
private class JoinCC extends Node {
@Override
public boolean activate() {
return !nodes.contains(check) && clans.size() > 0;
}
@Override
public void execute() {
if (Tabs.FRIENDS_CHAT.isOpen()) {
if (Widgets.get(1109, 1).getText().equals("Not in chat")) {
final String clan = clans.get(Random.nextInt(0, clans.size()));
clans.remove(clan);
if (Widgets.get(1109, 27).click(true)) {
waitFor(new Condition() {
@Override
public boolean validate() {
return Widgets.get(752, 4).isOnScreen();
}
}, 2000);
Keyboard.sendText(clan, true);
waitFor(new Condition() {
@Override
public boolean validate() {
return Widgets.get(1109, 1).getText().contains("Talking in");
}
}, 2000);
}
}
} else {
Tabs.FRIENDS_CHAT.open();
}
}
}
private boolean waitFor(final Condition c, final long timeout) {
final Timer t = new Timer(timeout);
while (t.isRunning() && !c.validate()) {
Task.sleep(50, 100);
}
return c.validate();
}
private interface Condition {
public boolean validate();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment