Procedure Step 1: hi guys, my 2nd release of the afkbot, it is now fully working, future updates will include mage, ranging and others
now you're probly like wtf is this and what's it do? so here's a video i took of the afkbot in action:
link: [Only registered and activated users can see links. ]
updates include:
-forceWalk() method
-run() method
-modified startBot() method: new thread
-getNextMove() method
-teleportTo() method
-modified attackNPCS() and attackNPC() methods: basic AI
-xp for hits
-stopBot works now
open notepad
Step 2: paste all this code into notepad:
Code:
// MacroHandler.java
// created by Endar
//
// version 1.02
//
// updates:
//
// 1.02
// -forceWalk() method
// -run() method
// -modified startBot() method: new thread
// -getNextMove() method
// -teleportTo() method
// -modified attackNPCS() and attackNPC() methods: basic AI
// -xp for hits
// -stopBot works now
public class MacroHandler implements Runnable {
public MacroHandler macroHandler = null;
public Thread t = null;
public static void main(String args[]) {
misc.println("afkbot can't be run as a standalone class");
}
public void startBot() {
try {
macroHandler = new MacroHandler();
t = new Thread(macroHandler);
t.start();
} catch(Exception e) {
e.printStackTrace();
}
}
public void stopBot() {
try {
t.stop(); // lol dangerous so what
} catch(Exception e) {
e.printStackTrace();
}
}
public void attackNPCS(int range) {
// multiple npcs, basically continually fighting everything around you
try {
for(Player p : server.playerHandler.players) {
if(p != null){
client c = (client) p;
for(int i = 0; i < server.npcHandler.maxNPCs; i++) {
if(server.npcHandler.npcs[i] != null) {
if(c.distanceToPoint(server.npcHandler.npcs[i].absX, server.npcHandler.npcs[i].absY) <= range && !server.npcHandler.npcs[i].IsDead) {
c.faceNPC(i);
c.CalculateMaxHit();
teleportTo((server.npcHandler.npcs[i].absX + 1), (server.npcHandler.npcs[i].absY)); // tele right next to them for realism
c.sendMessage("Found npc: " + i + " at " + server.npcHandler.npcs[i].absX + ", " + server.npcHandler.npcs[i].absY + ".");
for(int j = 0; j <= 999; j++) {
// npc should be dead in 999 hits right? lol
int damage = misc.random(c.playerMaxHit) + 1;
// need + 1 or loop screws up if u hit a 0
if(damage > server.npcHandler.npcs[i].MaxHP) damage = server.npcHandler.npcs[i].MaxHP;
// so u dont hit above the npc's max hp, ex hitting 20s on a man
server.npcHandler.npcs[i].StartKilling = c.playerId;
server.npcHandler.npcs[i].RandomWalk = false;
server.npcHandler.npcs[i].IsUnderAttack = true;
server.npcHandler.npcs[i].hitDiff = damage;
server.npcHandler.npcs[i].updateRequired = true;
server.npcHandler.npcs[i].hitUpdateRequired = true;
double TotalExp = 0;
if (c.FightType != 3) {
TotalExp = (double)(12 * damage);
TotalExp = (double)(TotalExp * c.CombatExpRate);
c.addSkillXP((int)(TotalExp), c.SkillID);
} else {
TotalExp = (double)(12 * damage);
TotalExp = (double)(TotalExp * c.CombatExpRate);
c.addSkillXP((int)(TotalExp), c.playerAttack);
c.addSkillXP((int)(TotalExp), c.playerDefence);
c.addSkillXP((int)(TotalExp), c.playerStrength);
}
TotalExp = (double)(10 * damage);
TotalExp = (double)(TotalExp * c.CombatExpRate);
c.addSkillXP((int)(TotalExp), c.playerHitpoints);
//c.sendMessage("Hit npc: " + i + " for " + damage + " damage.");
if(server.npcHandler.npcs[i].MaxHP - server.npcHandler.npcs[i].HP == 0) j = 999;
try {
Thread.sleep(1000);
} catch(Exception e) {
e.printStackTrace();
}
}
}
}
}
}
}
} catch(Exception e) {
e.printStackTrace();
}
}
public void attackNPC(int npcID, int range) {
// single npc
try {
for(Player p : server.playerHandler.players) {
if(p != null){
client c = (client) p;
if(server.npcHandler.npcs[npcID] != null) {
if(c.distanceToPoint(server.npcHandler.npcs[npcID].absX, server.npcHandler.npcs[npcID].absY) <= range && !server.npcHandler.npcs[npcID].IsDead) {
c.faceNPC(npcID);
c.CalculateMaxHit();
teleportTo((server.npcHandler.npcs[npcID].absX + 1), (server.npcHandler.npcs[npcID].absY)); // tele right next to them for realism
c.sendMessage("Found npc: " + npcID + " at " + server.npcHandler.npcs[npcID].absX + ", " + server.npcHandler.npcs[npcID].absY + ".");
for(int j = 0; j <= 999; j++) {
// npc should be dead in 999 hits right? lol
int damage = misc.random(c.playerMaxHit) + 1;
// need + 1 or loop screws up if u hit a 0
if(damage > server.npcHandler.npcs[npcID].MaxHP) damage = server.npcHandler.npcs[npcID].MaxHP;
// so u dont hit above the npc's max hp, ex hitting 20s on a man
server.npcHandler.npcs[npcID].StartKilling = c.playerId;
server.npcHandler.npcs[npcID].RandomWalk = false;
server.npcHandler.npcs[npcID].IsUnderAttack = true;
server.npcHandler.npcs[npcID].hitDiff = damage;
server.npcHandler.npcs[npcID].updateRequired = true;
server.npcHandler.npcs[npcID].hitUpdateRequired = true;
double TotalExp = 0;
if (c.FightType != 3) {
TotalExp = (double)(12 * damage);
TotalExp = (double)(TotalExp * c.CombatExpRate);
c.addSkillXP((int)(TotalExp), c.SkillID);
} else {
TotalExp = (double)(12 * damage);
TotalExp = (double)(TotalExp * c.CombatExpRate);
c.addSkillXP((int)(TotalExp), c.playerAttack);
c.addSkillXP((int)(TotalExp), c.playerDefence);
c.addSkillXP((int)(TotalExp), c.playerStrength);
}
TotalExp = (double)(10 * damage);
TotalExp = (double)(TotalExp * c.CombatExpRate);
c.addSkillXP((int)(TotalExp), c.playerHitpoints);
//c.sendMessage("Hit npc: " + npcID + " for " + damage + " damage.");
if(server.npcHandler.npcs[npcID].MaxHP - server.npcHandler.npcs[npcID].HP == 0) j = 999;
try {
Thread.sleep(1000);
} catch(Exception e) {
e.printStackTrace();
}
}
}
}
}
}
} catch(Exception e) {
e.printStackTrace();
}
}
public void forceWalk(int x, int y) {
// ty to Whitey for this, modded a bit for use in MacroHandler
for(Player p : server.playerHandler.players) {
if(p != null) {
int i = 0;
client c = (client) p;
c.newWalkCmdSteps = Math.abs((x + y));
if(c.newWalkCmdSteps % 2 != 0) c.newWalkCmdSteps /= 2;
if(++c.newWalkCmdSteps > c.walkingQueueSize) {
c.newWalkCmdSteps = 0;
}
int firstStepX = c.absX;
int tmpFSX = firstStepX;
firstStepX -= c.mapRegionX * 8;
for(i = 1; i < c.newWalkCmdSteps; i++) {
c.newWalkCmdX[i] = x;
c.newWalkCmdY[i] = y;
c.tmpNWCX[i] = c.newWalkCmdX[i];
c.tmpNWCY[i] = c.newWalkCmdY[i];
}
c.newWalkCmdX[0] = c.newWalkCmdY[0] = c.tmpNWCX[0] = c.tmpNWCY[0] = 0;
int firstStepY = c.absY;
int tmpFSY = firstStepY;
firstStepY -= c.mapRegionY * 8;
c.newWalkCmdIsRunning = (c.inStream.readSignedByteC() == 1);
for(i = 0; i < c.newWalkCmdSteps; i++) {
c.newWalkCmdX[i] += firstStepX;
c.newWalkCmdY[i] += firstStepY;
}
c.poimiY = firstStepY;
c.poimiX = firstStepX;
}
}
}
public void getNextMove(int range) {
try {
for(Player p : server.playerHandler.players) {
if(p != null) {
client c = (client) p;
int i = 0;
int j = 0;
int x = 0;
int y = 0;
i = misc.random(1);
j = misc.random(range);
if(i == 0) { // -
x = c.absX - misc.random(j);
} else if(i == 1) { // +
x = c.absX + misc.random(j);
} else System.out.println("invalid option in getNextMove: i = " + i);
i = misc.random(1);
if(i == 0) { // -
y = c.absY - misc.random(j);
} else if(i == 1) { // +
y = c.absY + misc.random(j);
} else System.out.println("invalid option in getNextMove: i = " + i);
c.sendMessage("New location: " + x + ", " + y);
//forceWalk(x, y); // walking randomly to find new targets
c.teleportToX = x;
c.teleportToY = y;
}
}
} catch(Exception e) {
e.printStackTrace();
}
}
public void teleportTo(int x, int y) {
for(Player p : server.playerHandler.players) {
if(p != null) {
client c = (client) p;
c.teleportToX = x;
c.teleportToY = y;
}
}
}
public void run() {
attackNPCS(10);
getNextMove(10);
try {
Thread.sleep(1000);
} catch(Exception e) {
e.printStackTrace();
}
run();
}
}
Step 3: save as MacroHandler.java (with capitals) Step 4: open server.java Step 5: search for this:
Code:
public static void main(java.lang.String args[]) {
clientHandler = new server();
//webserver = new webserver();
(new Thread(clientHandler)).start(); // launch server listener
pest = new pest();
playerHandler = new PlayerHandler();
worldObject = new WorldObject();
npcHandler = new NPCHandler();
itemHandler = new ItemHandler();
shopHandler = new ShopHandler();
antilag = new antilag();
itemspawnpoints = new itemspawnpoints();
GraphicsHandler = new GraphicsHandler();
objectHandler = new ObjectHandler();
clanHandler = new ClanHandler();
skillHandler = new SkillHandler();
somewhere in there add this:
Code:
macroHandler = new MacroHandler();
now search for:
Code:
public static PlayerHandler playerHandler = null;
public static NPCHandler npcHandler = null;
public static ItemHandler itemHandler = null;
public static pest pest = null;
public static ShopHandler shopHandler = null;
public static antilag antilag = null;
public static WorldObject worldObject = null;
public static itemspawnpoints itemspawnpoints = null;
public static GraphicsHandler GraphicsHandler = null;
public static ObjectHandler objectHandler = null;
public static ClanHandler clanHandler = null;
public static SkillHandler skillHandler = null;
public static DialogueHandler dialogueHandler = null;
and somewhere in there add this:
Code:
public static MacroHandler macroHandler = null;
Step 6: save server.java and open client.java Step 7: search for this:
Code:
public void customCommand(String command) {
actionAmount++;
if you don't like commands, you can add the code into buttons and such also
by the way, there is an extra void in the handler for if you only want to attack 1 type of npc at a time, ex attacking only men instead of everything around you Credits: Endar/Ben Sprinkle, Whitey, java docs