- Code: Select all
LoadGame();
var AutoChopping = true;
var changeDirectionCounter = 10;
var x;
var y;
var min = 30;
var max = 50;
var treeList = [];
var target;
function main(){
java.lang.System.out.print("Checking stamina...\n");
CheckStamina();
java.lang.System.out.print("Chopping...\n");
AutoChop();
}
function AutoWalk(){
if(AutoWalking) {
if(changeDirectionCounter >= 10)
{
changeDirectionCounter = 0;
x = getRandomInt(-1, 1);
y = getRandomInt(-1, 1);
}
var xAmount = getRandomInt(min, max);
var yAmount = getRandomInt(min, max);
var playerCoords = Game.getPlayerCoords();
Game.goTo(playerCoords.x + xAmount*x, playerCoords.y+ yAmount*y);
changeDirectionCounter++;
sleep(500); //give time to move
}
}
function CheckStamina()
{
if(Game.getStamina() >= 90)
{
java.lang.System.out.print("You have the stamina!\n");
}
else{
java.lang.System.out.print("You don't have enough stamina... Waiting "+(100-Game.getStamina())*7+" seconds.");
sleep(1000*(100-Game.getStamina())*7);
}
if(Game.getEnergy() > 40)
{
}
else
{
java.lang.System.out.print("You have ran out of energy! Feed your character! The script will now be stopped.\n")
AutoChopping = false;
}
}
function AutoChop()
{
if(AutoChopping)
{
if (treeList === undefined || treeList.length == 0) {
java.lang.System.out.print("Finding trees...\n");
findTrees();
}
else if(target === undefined || isEmpty(target))
{
java.lang.System.out.print("Finding target tree...\n");
findClosestTree();
}
else if(target !== undefined){
java.lang.System.out.print("Chopping tree!\n");
chopTree()
}
else{
java.lang.System.out.print("Nothing was triggered? Are there trees?\n");
java.lang.System.out.print("Tree List Size: " + treeList.length + " Target: " + target + "/n");
}
}
}
function removeTree(tree)
{
for(var i = 0; i < treeList.length; i++)
{
if(treeList[i] == tree)
{
treeList.splice(i, 1);
}
}
}
function chopTree()
{
Game.goTo(target.coords.x, target.coords.y);
java.lang.System.out.print("Going to tree...\n");
WaitTillStopped();
java.lang.System.out.print("Right clicking tree...\n");
if(Game.mapObjectRightClick(target.id))
{
java.lang.System.out.print("Chop!\n");
if(Game.chooseFlowerMenuOption('Chop'))
{
java.lang.System.out.print("Waiting to finish...\n");
Game.waitForTaskToFinish();
treeList = []; //You must always clear the list of trees after each attempt in order to renew the map list. No real way to check existence of tree.
}
else{
removeTree(target);
}
}
else{
removeTree(target);
}
}
function findTrees()
{
var mapObjects = Game.getAllMapObjects();
for (i = 0; i < mapObjects.length; i++) {
if(containsSubstring(mapObjects[i].fullName, "tree") && !containsSubstring(mapObjects[i].fullName, "stump") && !containsSubstring(mapObjects[i].fullName, "log"))
{
java.lang.System.out.print("Found a tree!\n");
java.lang.System.out.print("Adding it to the list of tress...\n");
treeList.push(mapObjects[i]);
java.lang.System.out.print("Tree List Length is now: "+treeList.length+"\n");
}
}
}
function findClosestTree()
{
if(target === undefined)
{
target = treeList[1];
}
if(treeList.length > 1)
{
for (var i = 0; i < treeList.length; i++)
{
var one = target;
var two = treeList[i];
var playerCoords = Game.getPlayerCoords();
var d1 = distance(one.coords.x-playerCoords.x, one.coords.y-playerCoords.y);
var d2 = distance(two.coords.x-playerCoords.x, two.coords.y-playerCoords.y);
if(d1 > d2)
{
target = treeList[i];
}
}
}
}
function isEmpty(value){
return (value == null || value.length === 0);
}
function distance(x, y)
{
return Math.sqrt( Math.pow(x, 2) + Math.pow(y, 2) );
}
function containsSubstring(obj, sub)
{
return obj.includes(sub);
}
function onCreatureFound(id, name, coords) {
if(name == 'bear' || name == 'boar' || name == 'badger' || name =='lynx')
{
home();
}
}
function home()
{
Game.travelToHearthFire();
WaitTillStopped();
}
function safeExit()
{
Game.travelToHearthFire();
WaitTillStopped();
Game.logout();
Exit();
}