Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weiry6922/3e1e807af8da7518df13e1eb0f4a30b7 to your computer and use it in GitHub Desktop.
Save weiry6922/3e1e807af8da7518df13e1eb0f4a30b7 to your computer and use it in GitHub Desktop.
/**
* @filename MFHelper.js
* @author kolton
* @desc help another player kill bosses or clear areas
*/
function MFHelper() {
var OnOff = {
file: "",
find: function() {
var i, n,
configFilename = "",
classes = ["Amazon", "Sorceress", "Necromancer", "Paladin", "Barbarian", "Druid", "Assassin"];
for (i = 0; i < 5; i += 1) {
switch (i) {
case 0: // Custom config
if (!isIncluded("config/_customconfig.js")) {
include("config/_customconfig.js");
}
for (n in CustomConfig) {
if (CustomConfig.hasOwnProperty(n)) {
if (CustomConfig[n].indexOf(me.profile) > -1) {
if (notify) {
print("?c2Loading custom config: ?c9" + n + ".js");
}
configFilename = n + ".js";
break;
}
}
}
break;
case 1:// Class.Profile.js
configFilename = classes[me.classid] + "." + me.profile + ".js";
break;
case 2: // Realm.Class.Charname.js
configFilename = me.realm + "." + classes[me.classid] + "." + me.charname + ".js";
break;
case 3: // Class.Charname.js
configFilename = classes[me.classid] + "." + me.charname + ".js";
break;
case 4: // Profile.js
configFilename = me.profile + ".js";
break;
}
if (configFilename && FileTools.exists("libs/config/" + configFilename)) {
this.file = "libs/config/" + configFilename;
return true;
}
}
print("\xFFc;ConfigChanger \xFFc0:: Couldn't find config file.");
return false;
},
disable: function(line) {
this.find();
if (this.file == "") {
return false;
}
try {
var confFile = File.open(this.file, 0);
} catch (e) {
return false;
}
var lines = confFile.readAllLines();
confFile.close();
for (var i = 0; i < lines.length; i++) {
if (lines[i].match(line + " = ")) {
lines[i] = lines[i].replace(/true/gi, "false");
print("\xFFc;ConfigChanger \xFFc0:: Disabled: " + line);
Misc.fileAction(this.file, 1, lines.join("\n"));
return true;
}
}
return true;
},
enable: function(line) {
this.find();
if (this.file == "") {
return false;
}
try {
var confFile = File.open(this.file, 0);
} catch (e) {
return false;
}
var lines = confFile.readAllLines();
confFile.close();
for (var i = 0; i < lines.length; i++) {
if (lines[i].match(line + " = ")) {
lines[i] = lines[i].replace(/false/gi, "true");
print("\xFFc;ConfigChanger \xFFc0:: Enabled: " + line);
Misc.fileAction(this.file, 1, lines.join("\n"));
return true;
}
}
return true;
}
};
this.partyLevel = function (level) {
if (!level) {
level = me.charlvl;
}
var i, player;
for (i = 0 ; i < 30 ; i += 1) { // Try 30 times because getParty(); can fail once in a while.
player = getParty();
if (player) {
do {
if (player.level < level) { // Player is not ready.
return false;
}
} while (player.getNext());
return true;
}
delay(250);
}
return false;
};
// SCRIPT I ADDED
if (me.diff == 1 && this.partyLevel(79)) {
OnOff.disable("Scripts.MFHelper");
OnOff.disable("Scripts.BaalHelper");
OnOff.enable("Scripts.AutoSmurf");
}
var i, player, playerAct, split, area,
oldCommand = "",
command = "";
const match = ["kill", "clearlevel", "clear", "quit", "cows", "council"];
/*
function ChatEvent(name, msg) {
if (!player) {
if (msg) {
for (i = 0; i < match.length; i += 1) {
if (msg.match(match[i])) {
player = this.findPlayer(name);
break;
}
}
}
}
if (player && name === player.name) {
command = msg;
}
}*/
this.findPlayer = function (name) {
var party = getParty();
if (party) {
do {
if (party.name !== me.name && party.name === name) {
return party;
}
} while (party.getNext());
}
return false;
};
this.getPlayerAct = function (player) {
if (player.area > 0 && player.area <= 39) {
return 1;
}
if (player.area >= 40 && player.area <= 74) {
return 2;
}
if (player.area >= 75 && player.area <= 102) {
return 3;
}
if (player.area >= 103 && player.area <= 108) {
return 4;
}
if (player.area >= 109) {
return 5;
}
return false;
};
this.buildCowRooms = function () {
var i, j, room, kingPreset, badRooms, badRooms2,
finalRooms = [],
indexes = [];
kingPreset = getPresetUnit(me.area, 1, 773);
badRooms = getRoom(kingPreset.roomx * 5 + kingPreset.x, kingPreset.roomy * 5 + kingPreset.y).getNearby();
for (i = 0; i < badRooms.length; i += 1) {
badRooms2 = badRooms[i].getNearby();
for (j = 0; j < badRooms2.length; j += 1) {
if (indexes.indexOf(badRooms2[j].x.toString() + badRooms2[j].y.toString()) === -1) {
indexes.push(badRooms2[j].x.toString() + badRooms2[j].y.toString());
}
}
}
room = getRoom();
do {
if (indexes.indexOf(room.x.toString() + room.y.toString()) === -1) {
finalRooms.push([room.x * 5 + room.xsize / 2, room.y * 5 + room.ysize / 2]);
}
} while (room.getNext());
return finalRooms;
};
this.clearCowLevel = function () {
var room, result, myRoom,
rooms = this.buildCowRooms();
function RoomSort(a, b) {
return getDistance(myRoom[0], myRoom[1], a[0], a[1]) - getDistance(myRoom[0], myRoom[1], b[0], b[1]);
}
while (rooms.length > 0) {
// get the first room + initialize myRoom var
if (!myRoom) {
room = getRoom(me.x, me.y);
}
if (room) {
if (room instanceof Array) { // use previous room to calculate distance
myRoom = [room[0], room[1]];
} else { // create a new room to calculate distance (first room, done only once)
myRoom = [room.x * 5 + room.xsize / 2, room.y * 5 + room.ysize / 2];
}
}
rooms.sort(RoomSort);
room = rooms.shift();
result = Pather.getNearestWalkable(room[0], room[1], 10, 2);
if (result) {
Pather.moveTo(result[0], result[1], 3);
if (!Attack.clear(30)) {
return false;
}
}
}
return true;
};
//addEventListener("chatmsg", ChatEvent);
addEventListener("copydata", (id, message) => {
print("id: " + id + " || " + message);
if (id == 77) {
let { name, msg } = JSON.parse(message);
print("recv: " + msg + " || from: " + name);
for (let m of match) {
if (msg.match(m)) {
player = this.findPlayer(name);
break;
}
}
if (player && name === player.name) {
command = msg;
}
}
});
Town.doChores();
Town.move("portalspot");
if (Config.Leader) {
for (i = 0; i < 30; i += 1) {
if (Misc.inMyParty(Config.Leader)) {
break;
}
delay(1000);
}
if (i === 30) {
throw new Error("MFHelper: Leader not partied");
}
player = this.findPlayer(Config.Leader);
}
// START
MainLoop:
while (true) {
if (player) {
while (!player.area) {
delay(100);
}
playerAct = this.getPlayerAct(player);
if (playerAct && playerAct !== me.act) {
Town.goToTown(playerAct);
Town.move("portalspot");
}
// Finish if leader is in chaos or throne
if ([108, 131].indexOf(player.area) > -1) {
break;
}
if (command !== oldCommand) {
oldCommand = command;
if (command.indexOf("kill") > -1) {
print("MFHelper Kill");
split = command.split("kill ")[1];
area = player.area;
for (i = 0; i < 5; i += 1) {
if (Pather.usePortal(player.area, player.name)) {
break;
}
delay(1000);
}
if (me.area === area) {
Precast.doPrecast(false);
try {
if (!!parseInt(split, 10)) {
split = parseInt(split, 10);
}
Attack.kill(split);
Pickit.pickItems();
} catch (killerror) {
print(killerror);
}
delay(1000);
if (!me.inTown && !Pather.usePortal(null, player.name)) {
Town.goToTown();
}
} else {
print("Failed to use portal.");
}
} else if (command.indexOf("clearlevel") > -1) {
print("MFHelper Clear Level");
area = player.area;
for (i = 0; i < 5; i += 1) {
if (Pather.usePortal(player.area, player.name)) {
break;
}
delay(1000);
}
if (me.area === area) {
Precast.doPrecast(false);
Attack.clearLevel(Config.ClearType);
Precast.doPrecast(true);
if (!Pather.usePortal(null, player.name)) {
Town.goToTown();
}
} else {
print("Failed to use portal.");
}
} else if (command.indexOf("clear") > -1) {
print("MFHelper Clear");
split = command.split("clear ")[1];
area = player.area;
for (i = 0; i < 5; i += 1) {
if (Pather.usePortal(player.area, player.name)) {
break;
}
delay(1000);
}
if (me.area === area) {
Precast.doPrecast(false);
try {
if (!!parseInt(split, 10)) {
split = parseInt(split, 10);
}
Attack.clear(15, 0, split);
} catch (killerror2) {
print(killerror2);
}
delay(1000);
if (!me.inTown && !Pather.usePortal(null, player.name)) {
Town.goToTown();
}
} else {
print("Failed to use portal.");
}
} else if (command.indexOf("quit") > -1) {
break MainLoop;
} else if (command.indexOf("cows") > -1) {
print("MFHelper Clear Cows");
for (i = 0; i < 5; i += 1) {
if (Town.goToTown(1) && Pather.usePortal(39)) {
break;
}
delay(1000);
}
if (me.area === 39) {
Precast.doPrecast(false);
this.clearCowLevel();
delay(1000);
if (!Pather.usePortal(null, player.name)) {
Town.goToTown();
}
} else {
print("Failed to use portal.");
}
} else if (command.indexOf("council") > -1) {
print("MFHelper Kill Council");
area = player.area;
for (i = 0; i < 5; i += 1) {
if (Pather.usePortal(player.area, player.name)) {
break;
}
delay(1000);
}
if (me.area === area) {
Precast.doPrecast(false);
Attack.clearList(Attack.getMob([345, 346, 347], 0, 40));
if (!Pather.usePortal(null, player.name)) {
Town.goToTown();
}
} else {
print("Failed to use portal.");
}
}
}
}
delay(100);
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment