Union Client Scripts

Forum for alternative clients, mods & discussions on the same.

Moderator: Phades

User avatar
SamaR
Posts: 65
Joined: Thu Sep 23, 2010 6:18 pm

Re: Union Client Scripts

Post by SamaR »

Ok, now it doesn't show but if I try to run the script it's the same result. Other script says that:

Code: Select all

//#! name = Farmer
//#! uniq = farmer_apxproductions
//#! icon = gfx/invobjs/seed-hops
// Globals
var inventory = checkInventory();
var harvester;


// Settings
var actionTimeout = 1000 * 60 * 2;	// Lag timeout
var cannotPlantTimeout = 1000 * 10;	// Non-plowed tile timeout
var cropRadius = 3;					// Радиус в которм идет поиск (верх, право, низ, лево)

// Flags
var stopFlag = false;

/* =========================================================================== */
/* ==============================	МОРКОВКА	============================== */
/* =========================================================================== */
function CarrotHarvester() {
    this.cropName = "plants/carrot";		// Имя кропа который нужно харвестить
    this.cropSeedName = "invobjs/carrot";	// Имя семечки которую нужно сажать
	this.cropStage = 4;						// Стадия обработки
}
CarrotHarvester.prototype.processHarvestedGoods = function() {
    inventory = checkInventory();
	
	var seeds = inventory.getItems(this.cropSeedName);
	var free = inventory.freeSlots();
	var i = 0;
	if (free < 3) {
		inventory.sortItems(seeds, "quality", false);
		for (i = 0; i < 3 - free; i++) {
			// Есть морковь если голоден
			if (jGetHungry() < 95) {
				if (seeds[i].isActual()) {
					seeds[i].iact();
					jWaitPopup(actionTimeout);
					jSelectContextMenu("Eat");
					waitUnActual(seeds[i]);
				}
			}
			// Выбросить лишку
			if (seeds[i].isActual()) {
				seeds[i].drop();
			}
		}
	}
};

/* =========================================================================== */
/* ==============================	СВЕКЛА		============================== */
/* =========================================================================== */
function BeetHarvester() {
    this.cropName = "plants/beetroot";		// Имя кропа который нужно харвестить
    this.cropSeedName = "invobjs/beetroot";	// Имя семечки которую нужно сажать
	this.cropStage = 3;						// Стадия обработки
}
BeetHarvester.prototype.processHarvestedGoods = function() {
    inventory = checkInventory();
	
	var seeds = inventory.getItems(this.cropSeedName);
	var free = inventory.freeSlots();
	var i = 0;
	//dropsleaves
	var leaves = inventory.getItems("beetrootleaves");
	if(leaves.length > 0)
		if(leaves[0].isActual())
			leaves[0].dropSuchAll();
	while(leaves.length > 0)
	{
		leaves = inventory.getItems("beetrootleaves");
		jSleep(500);
	}
	if (free < 6) {
		inventory.sortItems(seeds, "quality", false);
		for (i = 0; i < 4 - free; i++) {
			if (jGetHungry() < 95) {
				if (seeds[i].isActual()) {
					seeds[i].iact();
					jWaitPopup(actionTimeout);
					jSelectContextMenu("Eat");
					waitUnActual(seeds[i]);
				}
			}
			if (seeds[i].isActual()) {
				seeds[i].drop();
			}
		}
	}
};

/* =========================================================================== */
/* ==============================	ВИНОГРАД	============================== */
/* =========================================================================== */
function WineHarvester() {
    this.cropName = "plants/wine";		// Имя кропа который нужно харвестить
    this.cropSeedName = "invobjs/seed-grape";	// Имя семечки которую нужно сажать
	this.packName = "invobjs/grapes";
	this.cropStage = 3;						// Стадия обработки
	this.barrelID = 0; //id of barrel
	this.pressID = 0; //id of winepress
	this.containerID = 0;
	this.startCoord = jCoord(0, 0);
	this.fieldSize = jCoord(0, 0);
	this.offsMove = jCoord(2, 0);
}

WineHarvester.prototype.selectObjects = function() {
	var bar = jSelectObject("Select barrel...");
	if(jObjectName(bar).indexOf("barrel") == -1)
	{
		jToConsole("ERROR: This is not a barrel!");
		return false;
	}
	else this.barrelID = bar;
	var pr = jSelectObject("Select winepress...");
	if(jObjectName(pr).indexOf("winepress") == -1)
	{
		jToConsole("ERROR: This is not a press!");
		return false;
	}
	else this.pressID = pr;
	var cnt = jSelectObject("Select container (chest/lchest)...");
	if(jObjectName(cnt).indexOf("cclosed") == -1 && jObjectName(cnt).indexOf("lchest") == -1)
	{
		jToConsole("ERROR: This is not a container!");
		return false;
	}
	else this.containerID = cnt;
	return true;
}

WineHarvester.prototype.selectRect = function() {
	var offs = jCoord(0, 0);
	var size = jCoord(1, 1);
	var confirm = false;
	jDrawGroundRect(offs, size);
	var blist = ["West", "East", "North", "South", "Inc width", "Inc height", "Dec width", "Dec height", "Confirm", "Exit"];
	var selectWindow = jGUIWindow(jCoord(250, 250), jCoord(105, blist.length * 25 + 15), "Test");
	var label = jGUILabel(selectWindow, jCoord(5, 5), "Select grapes area.");
	for(var i = 0; i < blist.length; i++)
		jGUIButton(selectWindow, jCoord(5, 25 + i*25),  100, blist[i]);
	selectWindow.toggleCloseButton();
	var btext = "";
	while(btext != "Exit"){
		btext = selectWindow.waitButtonClick();
		if(btext == blist[0]) offs.x--;
		if(btext == blist[1]) offs.x++;
		if(btext == blist[2]) offs.y--;
		if(btext == blist[3]) offs.y++;
		if(btext == blist[4]) size.x++;
		if(btext == blist[5]) size.y++;
		if(btext == blist[6]) if(size.x > 1) size.x--;
		if(btext == blist[7]) if(size.y > 1) size.y--;
		if(btext == blist[8]) {confirm = true; break;}
		jDrawGroundRect(offs, size);
	}
	selectWindow.destroy();
	jDrawGroundRect(offs, jCoord(0, 0));
	this.startCoord = jMyCoords().add(offs.mul(11));
	this.fieldSize = size;
	return confirm;
}

WineHarvester.prototype.processHarvesting = function() {
	var result = false;
	var grapes = jGetObjectsInRect(this.startCoord, this.fieldSize, this.cropStage, [this.cropName]);
	inventory = checkInventory();
	var cuts = Math.floor((inventory.freeSlots() - 1)/3); //хуйпизда
	if(cuts > 8) cuts = 8;
	var currentgrape = 0;
	while(1)
	{
		if(currentgrape >= grapes.length) {result = true; break;}
		//cursor
		if(!jIsCursor("harvest")) {
			jSendAction("harvest");
			jWaitCursor("harvest", actionTimeout);
		}
		//harvesting grapes
		for(var i = 0; i < cuts; i++)
		{
			if(jGetStamina() < 50) drinkWater();
			if(currentgrape >= grapes.length) break;
			jDoClick(grapes[currentgrape], 1, 0);
			jWaitProgress(actionTimeout);
			currentgrape++;
		}
		//got pack of grapes
		resetCursor();
		//goes to press
		jAbsClick(jObjectPos(this.pressID).add(this.offsMove.mul(11)), 1, 0);
		jWaitMove(actionTimeout);
		jDoClick(this.pressID, 3, 0);
		jWaitWindow("Winepress", actionTimeout);
		//no window in lag/etc
		jSleep(100);
		if(!jHaveWindow("Winepress")) {result = false; break;}
		//transfers all grapes to winepress
		inventory.getItems(this.packName)[0].transferSuchAll();
		//waits transfering
		while(inventory.getItems(this.packName).length > 0)
			jSleep(300);
		//making juice
		jGetWindow("Winepress").pushButton(1);
		while(jGetWindow("Winepress").getInventories()[0].getItems(this.packName).length > 0)
			jSleep(500);
		//lifts press
		var pc = jObjectPos(this.pressID);// memorizing press coords
		jSendAction("carry");
		jWaitCursor("chi", actionTimeout);
		//lag
		if(!jIsCursor("chi")) {result = false; break;}
		jDoClick(this.pressID, 1, 0);
		jSleep(1500);
		/*while(!jAvatarIsCarrying(jGetMyID()))
			jSleep(200);*/
		//juice to barrel
		jDoClick(this.barrelID, 3, 0);
		jWaitMove(actionTimeout);
		jSleep(2000);
		//placing press back
		jAbsClick(pc, 3, 0);
		jWaitMove(actionTimeout);
		/*while(jAvatarIsCarrying(jGetMyID()))
			jSleep(200);*/
		//getting seeds from press
		jDoClick(this.pressID, 3, 0);
		jWaitWindow("Winepress", actionTimeout);
		//no window in lag/etc
		jSleep(100);
		if(!jHaveWindow("Winepress")) {result = false; break;}
		//transfer to pack seeds
		jGetWindow("Winepress").getInventories()[0].getItems("")[0].transferSuchAll();
		while(jGetWindow("Winepress").getInventories()[0].getItems("").length > 0)
			jSleep(200);
		//offset move
		jMoveStep(this.offsMove);
		jWaitMove(actionTimeout);
		//going to lchect
		var lc = jObjectPos(this.containerID).add(this.offsMove.mul(11));
		jAbsClick(lc, 1, 0);
		jWaitMove(actionTimeout);
		jDoClick(this.containerID, 3, 0);
		jWaitWindow("Chest", actionTimeout);
		//no window in lag/etc
		jSleep(100);
		if(!jHaveWindow("Chest")) {result = false; break;}
		var bags = jGetWindow("Chest").getInventories()[0].getItems("invobjs/bag-seed");
		var cbag = 0; //current bag
		inventory = checkInventory();
		//transferring seeds, btw i hate loftar
		while(inventory.getItems(this.cropSeedName).length >= 1)
		{
			if(cbag >= bags.length) {result = true; break;}
			var cnt = inventory.getItems(this.cropSeedName).length; //inventory count
			bags[cbag].iact();
			//opens seedbag
			while(!jHaveWindow("Seedbag"))
				jSleep(200);
			//check for free slots
			if(jGetWindow("Seedbag").getInventories()[0].freeSlots() == 0)
			{
				jGetWindow("Seedbag").close();
				while(jHaveWindow("Seedbag"))
					jSleep(200);
				cbag++;
				continue;
			}
			jSleep(100);
			var free = jGetWindow("Seedbag").getInventories()[0].freeSlots(); //free slots in seedbag
			inventory.getItems(this.cropSeedName)[0].transferSuchAll();
			while(inventory.getItems(this.cropSeedName).length > Math.abs(cnt - free))
				jSleep(200);
			jGetWindow("Seedbag").close();
			while(jHaveWindow("Seedbag"))
				jSleep(200);
			cbag++;
		}
		//идите на хуй, мне лень чтото делать с этими семенами
		if(result == true) {inventory.getItems(this.cropSeedName)[0].dropSuchAll(); jSleep(1000); break;} //break if all bags r full
		//checks barrel
		var bc = jObjectPos(this.barrelID).add(this.offsMove.mul(11));
		jAbsClick(bc, 1, 0);
		jWaitMove(actionTimeout);
		jDoClick(this.barrelID, 3, 0);
		while(!jHaveWindow("Barrel"))
			jSleep(500);
		//barrel label
		var blbl = jGetWindow("Barrel").getLabelText(1);
		if(blbl.indexOf("100.0") != -1) {result = true; break;} //breaks if barrel is full
	}//1
	return result;
}

WineHarvester.prototype.plantGrapes = function() {
	jMoveStep(this.offsMove);
	jWaitMove(actionTimeout);
	//going to lchect
	var lc = jObjectPos(this.containerID).add(this.offsMove.mul(11));
	jAbsClick(lc, 1, 0);
	jWaitMove(actionTimeout);
	jDoClick(this.containerID, 3, 0);
	jWaitWindow("Chest", actionTimeout);
	//no window in lag/etc
	jSleep(100);
	if(!jHaveWindow("Chest")) return false;
	jGetWindow("Chest").getInventories()[0].getItems("invobjs/bag-seed-f")[0].transferSuchAll();
	jSleep(1000);
	inventory = checkInventory();
	var fullbags = inventory.getItems("invobjs/bag-seed-f");
	for(var i = 0; i < fullbags.length; i++)
		fullbags[i].iact();
	while(jGetWindows("Seedbag").length < fullbags.length)
		jSleep(200);
	var swnds = jGetWindows("Seedbag");
	var allseeds = [];
	for(var i = 0; i < swnds.length; i++)
	{
		var sinvs = swnds[i].getInventories()[0].getItems(this.cropSeedName);
		for(var j = 0; j < sinvs.length; j++)
			allseeds.push(sinvs[j]);
	}
	//allseeds.sort(sortFunction2); //а Арх хуй!
	var cseed = 0;
	var overflow = false;
	jAbsClick(jTilify(this.startCoord), 1, 0);
	jWaitMove(actionTimeout);
	for(var i = 0; i < this.fieldSize.x; i++) {
		if(overflow == true) break;
		for(var j = 0; j < this.fieldSize.y; j++) {
			if(cseed >= allseeds.length) {overflow = true; break;}
			if(jGetStamina() < 50) drinkWater();
			jAbsClick(this.startCoord.add(i*11, j*11));
			jWaitMove(actionTimeout);
			if(jFindObjectByName(this.cropName, 3) != 0) continue;
			plantNewCrop(this, false);
			/*if(!jGetTileType(jCoord(0, 0)) != 9) plowTile();
			allseeds[cseed].take();
			jWaitDrag(actionTimeout);
			jAbsInteractClick(jCoord(0, 0), 3, 0);
			jWaitDrop(actionTimeout);
			jSleep(100);*/
			cseed++;
		}
		jSleep(100);
	}
	jToConsole("test");
}
/* =========================================================================== */
/* ==============================	КОНОПЛЯ		============================== */
/* =========================================================================== */
function HempHarvester() {
    this.cropName = "plants/hemp";		// Имя кропа который нужно харвестить
    this.cropSeedName = "invobjs/seed-hemp";	// Имя семечки которую нужно сажать
	this.cropStage = 4;						// Стадия обработки
	bagsSeedsSorter(this);
}
HempHarvester.prototype.processHarvestedGoods = function() {
    bagsSeedsSorter(this);
};

/* =========================================================================== */
/* ==============================	ЛЕН			============================== */
/* =========================================================================== */
function FlaxHarvester() {
    this.cropName = "plants/flax";		// Имя кропа который нужно харвестить
    this.cropSeedName = "invobjs/flaxseed";	// Имя семечки которую нужно сажать
	this.cropStage = 3;						// Стадия обработки
}
FlaxHarvester.prototype.processHarvestedGoods = function() {
    bagsSeedsSorter(this);
};

/* =========================================================================== */
/* ==============================	ПЕРЕЦ		============================== */
/* =========================================================================== */
function PepperHarvester() {
    this.cropName = "plants/pepper";		// Имя кропа который нужно харвестить
    this.cropSeedName = "invobjs/seed-pepper";	// Имя семечки которую нужно сажать
	this.cropStage = 3;						// Стадия обработки
}
PepperHarvester.prototype.processHarvestedGoods = function() {
    bagsSeedsSorter(this);
};

/* =========================================================================== */
/* ==============================	ЧАЙ 		============================== */
/* =========================================================================== */
function TeaHarvester() {
    this.cropName = "plants/tea";		// Имя кропа который нужно харвестить
    this.cropSeedName = "invobjs/seed-tea";	// Имя семечки которую нужно сажать
	this.cropStage = 3;						// Стадия обработки
	this.leaveName = "invobjs/tea-fresh";
	this.containerID = 0;
}
TeaHarvester.prototype.processHarvestedGoods = function() {
    bagsSeedsSorter(this);
};

TeaHarvester.prototype.selectObjects = function() {
	var cnt = jSelectObject("Select container (chest/lchest)...");
	if(jObjectName(cnt).indexOf("cclosed") == -1 && jObjectName(cnt).indexOf("lchest") == -1)
	{
		jToConsole("ERROR: This is not a container!");
		return false;
	}
	else this.containerID = cnt;
	return true;
}
/* =========================================================================== */
/* ==============================		МАК		============================== */
/* =========================================================================== */
function PoppyHarvester() {
    this.cropName = "plants/poppy";		// Имя кропа который нужно харвестить
    this.cropSeedName = "invobjs/seed-poppy";	// Имя семечки которую нужно сажать
	this.cropStage = 4;						// Стадия обработки
}
PoppyHarvester.prototype.processHarvestedGoods = function() {
	bagsSeedsSorter(this);
};

/* =========================================================================== */
/* ==============================	ПШЕНИЧКА	============================== */
/* =========================================================================== */
function WheatHarvester() {
    this.cropName = "plants/wheat";		// Имя кропа который нужно харвестить
    this.cropSeedName = "wheat";	// Имя семечки которую нужно сажать
	this.cropStage = 3;						// Стадия обработки
}
WheatHarvester.prototype.processHarvestedGoods = function() {
    bagsSeedsSorter(this);
};
/*==============================Кропчики============================================*/

function bagsSeedsSorter(harv) {
	inventory = checkInventory();
	var bags = inventory.getItems("invobjs/bag-seed");
	var fslots = 0;
	
	if (bags.length > 0) {
		var windows = jGetWindows("Seedbag");
		if (windows.length > 0) {
			var seeds = [];
			var maxseedscount = bags.length * 9;
			//getting seeds from all seedbags into array
			for (var i = 0; i < windows.length; i++) {
				var inv = waitInventory(windows[i], 0);
				fslots += inv.freeSlots();
				var bufseeds = inv.getItems(harv.cropSeedName);
				for (var j = 0; j < bufseeds.length; j++) {
					seeds.push(bufseeds[j]);
				}
			}
			//from inventory to same array
			var invseeds = inventory.getItems(harv.cropSeedName);
			for (var j = 0; j < invseeds.length; j++) {
				seeds.push(invseeds[j]);
			}
			//calculation quality of all seeds
			var allq = 0;
			for (var j = 0; j < seeds.length; j++) {
				allq += seeds[j].quality();
			}
			//medium quality
			var mediumrange = (allq / seeds.length) - 1;
			//correcting medium q
			//too many seeds
			if(fslots < 9)
				mediumrange += 1;
			
			if (seeds.length > maxseedscount * 0.75) {
				for (var j = 0; j < seeds.length; j++) {
					if (seeds[j].quality() <= mediumrange) seeds[j].drop();
				}
				organizeBags(inventory, harv.cropSeedName);
			}
		}//bags windows
	}
	if (inventory.freeSlots() < 4 && bags.length < 1) {
		inventory.sortItems(inventory.getItems(harv.cropSeedName), "quality", false);
		for (i = 0; i < 3 - free; i++) {
			if (seeds[i].isActual()) {
				seeds[i].drop();
			}
		}
	}
}

function organizeBags(inv, name) {
	var bagw = jGetWindows("Seedbag");
	if(bagw.length < 1) return;
	var fullb, nextb;
	fullb = 0;
	nextb = bagw.length - 1;
	while(1)
	{
		if(fullb == nextb) break; //breaks if filling bag == last bag
		if(bagw[fullb].getInventories()[0].freeSlots() == 0) {
			fullb++;
			continue;
		}
		if(bagw[nextb].getInventories()[0].freeSlots() == 9) {
			nextb--;
			continue;
		}
		var freeSlot = bagw[fullb].getInventories()[0].freeSlotsCoords()[0]; //getting 1st empty slot at current filling bag
		var seed = bagw[nextb].getInventories()[0].getItems(name)[0];	 //getting 1st seed at current emptying bag
		seed.take();
		jWaitDrag();
		bagw[fullb].getInventories()[0].drop(freeSlot); //drops to filling bag
		jWaitDrop();
	}
}

function openAllSeedbags() {
	inv = checkInventory();
	var bags = inv.getItems("invobjs/bag-seed");
	if(bags.length < 1)
		return;
	for(var i = 0; i < bags.length; i++)
		if(bags[i].isActual())
			bags[i].iact();
	while(jGetWindows("Seedbag").length != bags.length)
		jSleep(300);
}

function waitUnActual(item) {
	while (item.isActual()) {
		jSleep(100);
	}
}

function resetCursor() {
	if (!jIsCursor("arw")) {
		jAbsClick(jCoord(0, 0), 3, 0);
		jWaitCursor("arw", actionTimeout);
	}
}

function checkInventory() {
	if(!jHaveWindow("Inventory")) {
		jToggleInventory();
		while(!jHaveWindow("Inventory"))
			jSleep(100);
	}
	return jGetWindow("Inventory").getInventories()[0];
}

function checkEquipment() {
	if(!jHaveWindow("Equipment")) {
		jToggleEquipment();
		while(!jHaveWindow("Equipment"))
			jSleep(100);
	}
	return jGetJSEquip();
}

function waitInventoryObject(inv, objname) {
	while (true) {
		var objs = inv.getItems(objname);
		if (objs.length > 0) break;
		else jSleep(100);
	}	
}

function waitUnActual(item) {
	while (item.isActual()) {
		jSleep(100);
	}
}

function drinkWater() {
	if (jGetStamina() > 80) return;
	inventory = checkInventory();
	var buckets = inventory.getItems("bucket-water");
	if (buckets.length > 0) {
		inventory.sortItems(buckets, "amount", false);
		var bucket = buckets[0];
		var bucket_coord = bucket.coord();
		if (bucket.isActual()) {
			bucket.take();
			jWaitDrag();
			var flasks = inventory.getItems("waterflask", "waterskin");
			if (flasks.length > 0) {
				var flask = flasks[0];
				if (flask.isActual()) {
					flask.itemact(0);
					jSleep(500);
					inventory.drop(bucket_coord);
					jWaitDrop();
				}
			}
		}
	}
	var flasks = inventory.getItems("waterflask", "waterskin");
	if (flasks.length > 0) {
		var flask = flasks[0];
		if (flask.isActual()) {
			flask.iact();
			if (jWaitPopup(actionTimeout)) {
				jSelectContextMenu("Drink");
				jWaitProgress();
			} else {
				// No water
				stopFlag = true;
			}
		}
	}
}

function TileInfo(crd) {
	this.coord = crd;
}

function findCrop(harv) {
	var objid = 0;
		for (var i = 0; i < cropRadius; i++) {
		objid = jFindObjectWithOffset(harv.cropName, 1, jCoord(0, i)); // down
		if (objid && jObjectBLOB(objid, 0) == harv.cropStage) return objid;
	}
	for (var i = 0; i < cropRadius; i++) {
		objid = jFindObjectWithOffset(harv.cropName, 1, jCoord(0, -i)); // up
		if (objid && jObjectBLOB(objid, 0) == harv.cropStage) return objid;
	}
	for (var i = 0; i < cropRadius; i++) {
		objid = jFindObjectWithOffset(harv.cropName, 1, jCoord(i, 0)); // right
		if (objid && jObjectBLOB(objid, 0) == harv.cropStage) return objid;
	}
	for (var i = 0; i < cropRadius; i++) {
		objid = jFindObjectWithOffset(harv.cropName, 1, jCoord(-i, 0));// left
		if (objid && jObjectBLOB(objid, 0) == harv.cropStage) return objid;
	}
	objid = jFindObjectByName(harv.cropName, cropRadius);
	if (jObjectBLOB(objid, 0) != harv.cropStage) objid = -1;
	return objid;
}

function dropItem(coord) {
	var items = inventory.getItems("");
	for (var i = 0; i < items.length; i++) {
		if (items[i].coord().x == coord.x && items[i].coord().y == coord.y) { 
			items[i].drop();
			break;
		}
	}	
}

function waitDragName(name) {
	while (true) {
		var item = jGetDraggingItem();
		if (item != null) {
			if (item.resName() != null) {
			if (item.resName().indexOf(name) >= 0) {
				break;
			} else {
				jSleep(100);
			}
			} else jSleep(100);
		} else {
			break;
		}
	}
}

function equipScythe() {
	var equip = checkEquipment();
	var scythe = inventory.getItems("scythe")[0];
	if (!scythe) return;
	if (equip.resName(6).indexOf("shovel") >= 0) {
		equip.takeAt(6);
		jWaitDrag(actionTimeout);
		inventory.drop(scythe.coord());
		jSleep(1000);
		waitDragName("scythe");
		equip.dropTo(6);
		jWaitDrop(actionTimeout);
	}
}

function equipShovel() { // From scythe
	var equip = checkEquipment();
	var shovel = inventory.getItems("shovel")[0];
	if (!shovel) return;
	if (equip.resName(6).indexOf("scythe") >= 0) {
		dropItem(shovel.coord().add(0, 2));
		equip.takeAt(6);
		jWaitDrag(actionTimeout);
		inventory.drop(shovel.coord());
		jSleep(1000);
		waitDragName("shovel");
		equip.dropTo(6);
		jWaitDrop(actionTimeout);
	}
}

function plowTile() {
	drinkWater();
	equipShovel();
	jSendAction("plow");
	jWaitCursor("dig", actionTimeout);
	jOffsetClick(jCoord(0, 0), 1, 0);
	jWaitProgress();
	jOffsetClick(jCoord(0, 0), 3, 0);
	jWaitCursor("arw", actionTimeout);
}

function sayArea(text) {
	var chats = jGetChats();
	for (var i = 0; i < chats.length; i++) {
		if (chats[i].chatName().indexOf("Area Chat") >= 0) {
			chats[i].sendMessage(text);
			break;
		}
	}
}

function sortFunction2(a, b) {
	if (!a.isActual() || !b.isActual()) return 0;
	else return a.quality() - b.quality();
}

function sortFunction(a, b) {
	if (!a.isActual() || !b.isActual()) return 0;
	if (a.quality() < b.quality()) return 1;
	if (a.quality() > b.quality()) return -1;
	return 0;
}

function waitInventory(wnd, index) {
	while (wnd.getInventories().length <= 0) {
		jSleep(100);
	}
	return wnd.getInventories()[index];
}

function plantNewCrop(harv, notrecursive) {
	jSleep(300);
	inventory = checkInventory();
	var plantedSeed = null;
	var windows = jGetWindows("Seedbag");
	var seedbags = inventory.getItems("invobjs/bag-seed-f");
	if (seedbags.length > 0) {
		var seeds = [];
		for (var i = 0; i < windows.length; i++) {
			var inv = waitInventory(windows[i], 0);
			if (inv) {
				var bufseeds = inv.getItems(harv.cropSeedName);
				for (var j = 0; j < bufseeds.length; j++) {
					seeds.push(bufseeds[j]);
				}
			}
		}
		var invseeds = inventory.getItems(harv.cropSeedName);
		for (var j = 0; j < invseeds.length; j++) {
			seeds.push(invseeds[j]);
		}
		var sorted_seeds = seeds.sort(sortFunction);
		plantedSeed = sorted_seeds[0];
	} else {
		var invseeds = inventory.getItems(harv.cropSeedName);
		if (invseeds.length > 0) {
			inventory.sortItems(invseeds, "quality", true);
			plantedSeed = invseeds[0];
		}
	}
	
	if (plantedSeed) {
		// Plow tile if needed
		if (jGetTileType(jCoord(0, 0)) != 9) {
			plowTile();
		}
		if (plantedSeed.isActual()) {
			plantedSeed.take();
			jWaitDrag();
			jInteractClick(jCoord(0, 0), 0);
			if (!jWaitDrop(cannotPlantTimeout)) {
				jWaitDrop();
				if (notrecursive) return;
				plowTile();
				plantNewCrop(harv, true);
			}
		} else {
			if (!notrecursive) plantNewCrop(harv, true);
			else jPrint("Double fail on non-actual seed");
		}
	}
}

function waitPFEndMove() {
	while (true) {
		jWaitEndMove();
		jSleep(500);
		if (!jIsMoving()) {
			return;
		}
	}
}

function main() {
	jDropLastWindow();
	openAllSeedbags();
	var blist = ["Carrot", "Poppy", "Wheat", "Hemp", "Beetroot", "Grapes", "Tea", "Flax", "Pepper", "Exit"];
	var selectWindow = jGUIWindow(jCoord(250, 250), jCoord(110, blist.length * 25 + 15), "Farming");
	var label = jGUILabel(selectWindow, jCoord(5, 5), "Select crop type:");
	for(var i = 0; i < blist.length; i++)
		jGUIButton(selectWindow, jCoord(5, 25 + i*25),  100, blist[i]);
	selectWindow.toggleCloseButton();
	var btext = selectWindow.waitButtonClick();
	if(btext == blist[0]) harvester = new CarrotHarvester();
	if(btext == blist[1]) harvester = new PoppyHarvester();
	if(btext == blist[2]) harvester = new WheatHarvester();
	if(btext == blist[3]) harvester = new HempHarvester();
	if(btext == blist[4]) harvester = new BeetHarvester();
	if(btext == blist[5]) {
		selectWindow.destroy();
		harvester = new WineHarvester();
		if(!harvester.selectObjects()) return;
		if(!harvester.selectRect()) return;
		if(!harvester.processHarvesting()) return;
		harvester.plantGrapes();
		return;
	}
	if(btext == blist[6]) {
		harvester = new TeaHarvester();
		if(!harvester.selectObjects()) return;
	}
	if(btext == blist[7]) harvester = new FlaxHarvester();
	if(btext == blist[8]) harvester = new PepperHarvester();
	if(btext == blist[blist.length - 1]) {selectWindow.destroy(); return;}
	selectWindow.destroy();
	while (!stopFlag) {
		var crop = findCrop(harvester);
		if (crop == -1) break; // No crops found
		drinkWater();
		equipScythe();
		if (!jIsPathFree(jObjectPos(crop))) {
			resetCursor();
			jPFMove(jObjectPos(crop));
			jWaitStartMove();
			waitPFEndMove();
			while (jIsMoving() || jMyCoords().dist(jObjectPos(crop)) > 1) {
				jSleep(100);
			}
		}
		jSendAction("harvest");
		jWaitCursor("harvest", actionTimeout);
		jDoClick(crop, 1, 0);
		jWaitProgress();
		harvester.processHarvestedGoods();
		plantNewCrop(harvester, false);
	}
}

main();

objectblob.png
And why something like this doesn't even work? :|

Code: Select all

//#! name = Harvest
//#! uniq = Harvest
//#! icon = gfx/invobjs/straw

function harvestCrop(crop){
	jSendAction("harvest");
	jWaitCursor("harvest");
	jDoClick(crop.getID(),1,0);
	inventoryItemsCountChange();
	resetCursor();
}	


I found the fixed farmer code at first page and it's working now :| anyways thanks for responding, I'll be trying to write something by myself :)
You do not have the required permissions to view the files attached to this post.
User avatar
shubla
Posts: 13041
Joined: Sun Nov 03, 2013 11:26 am
Location: Finland

Re: Union Client Scripts

Post by shubla »

Anyone ever fixed grapebot farmer that makes wine and stuff?
Image
I'm not sure that I have a strong argument against sketch colors - Jorb, November 2019
http://i.imgur.com/CRrirds.png?1
Join the moderated unofficial discord for the game! https://discord.gg/2TAbGj2
Purus Pasta, The Best Client
ddarongg
Posts: 6
Joined: Wed Aug 11, 2010 5:33 am

Re: Union Client Scripts

Post by ddarongg »

error.jpg
hi. i was trying to use foraging bot maker

but when i ran scripts this error message comes out.

and i put swamp menu, scripts just finished and doesn't work.

please help me
You do not have the required permissions to view the files attached to this post.
usernamelol
Posts: 16
Joined: Fri Jun 13, 2014 2:05 pm

Re: Union Client Scripts

Post by usernamelol »

been taking java classes at uni so I'll risk giving my humble opinion :oops:

from this log there doesn't seems to be anything wrong with your script, I might be wrong but this whole bunch of retrotranslator errors probably mean that what you have are compatibility issues

retrotranslator errors usually mean that the function your script is calling have been deprecated in the version of java you're using, short of reading up the new documentation looking for what changed, rewriting whatever stopped working and compiling the whole thing from source as far as I can see there's not much you can do with your current java version :cry:

there's an easy workaround though: if you updated your java recently and then the script stopped working downgrade back to the previous version, otherwise just download the java version the script been written for, in this case java 7, then change path on the run.bat of your client to the location of the java 7 install and all your scripts should run like a charm until a more clever and powerful wizard comes up with a patch to haven.jar fixing the compatibility issue with the newer versions 8-)

hope that helps! :geek:
ddarongg
Posts: 6
Joined: Wed Aug 11, 2010 5:33 am

Re: Union Client Scripts

Post by ddarongg »

usernamelol wrote:been taking java classes at uni so I'll risk giving my humble opinion :oops:

from this log there doesn't seems to be anything wrong with your script, I might be wrong but this whole bunch of retrotranslator errors probably mean that what you have are compatibility issues

retrotranslator errors usually mean that the function your script is calling have been deprecated in the version of java you're using, short of reading up the new documentation looking for what changed, rewriting whatever stopped working and compiling the whole thing from source as far as I can see there's not much you can do with your current java version :cry:

there's an easy workaround though: if you updated your java recently and then the script stopped working downgrade back to the previous version, otherwise just download the java version the script been written for, in this case java 7, then change path on the run.bat of your client to the location of the java 7 install and all your scripts should run like a charm until a more clever and powerful wizard comes up with a patch to haven.jar fixing the compatibility issue with the newer versions 8-)

hope that helps! :geek:
omg You're genius. I installed JAVA 7 and Problem solved. Thank you so much.
tixcu
Posts: 4
Joined: Sat Sep 20, 2014 7:14 am

Re: Union Client Scripts

Post by tixcu »

Code: Select all

    //#! name = OMG THIS SUSAVAGE
     
    var ACCNAME = "accname";         //account name
    var CHARNAME = "charname";   //character name
    include("jBotAPI");
    inventory = checkInventory();
    jDropLastWindow();
    GetRoute();
    var startPos = jMyCoords();
    var route = [];
    var CurioName = ["pearl","flotsam","itsybitsy","itsyweb"];
    function GetRoute() {
       var startPos = jMyCoords();
       var route = [];
    //MY COORDS, REWRITE IT
       route[0] = jCoord(startPos.x+320,startPos.y);
       route[1] = jCoord(route[0].x+320,route[0].y);
       route[2] = jCoord(route[1].x+220,route[1].y-210);
       route[3] = jCoord(route[2].x,route[2].y-320);
       route[4] = jCoord(route[3].x+150,route[3].y-260);
       route[5] = jCoord(route[4].x+150,route[4].y-250);
       route[6] = jCoord(route[5].x+210,route[5].y-180);
       route[7] = jCoord(route[6].x+280,route[6].y+110);
       route[8] = jCoord(route[7].x+250,route[7].y+150);
       route[9] = jCoord(route[8].x+230,route[8].y+200);
       route[10] = jCoord(route[9].x+250,route[9].y+270);
       route[11] = jCoord(route[10].x+250,route[10].y+270);
       route[12] = jCoord(route[11].x+250,route[11].y+230);
       route[13] = jCoord(route[12].x+250,route[12].y+200);
       route[14] = jCoord(route[13].x+250,route[13].y);
       route[15] = jCoord(route[14].x+250,route[14].y+390);
       route[16] = jCoord(route[15].x+150,route[15].y+250);
       route[17] = jCoord(route[16].x+70,route[16].y+250);
       route[18] = jCoord(route[17].x+70,route[17].y+250);
       route[19] = jCoord(route[18].x+70,route[18].y+250);
       route[20] = jCoord(route[19].x,route[19].y+250);
       route[21] = jCoord(route[20].x+150,route[20].y+250);
       route[22] = jCoord(route[21].x+210,route[21].y-60);
       route[23] = jCoord(route[22].x+200,route[22].y+100);
       route[24] = jCoord(route[23].x,route[23].y-250);
       route[25] = jCoord(route[24].x,route[24].y-250);
       route[26] = jCoord(route[25].x,route[25].y-250);
       route[27] = jCoord(route[26].x,route[26].y-250);
       route[28] = jCoord(route[27].x,route[27].y-470);
       route[29] = jCoord(route[28].x-200,route[28].y-350);
       route[30] = jCoord(route[29].x-380,route[29].y-170);
       route[31] = jCoord(route[30].x-250,route[30].y-200);
       route[32] = jCoord(route[31].x-250,route[31].y-200);
       route[33] = jCoord(route[32].x-150,route[32].y-260);
       route[34] = jCoord(route[33].x-150,route[33].y-260);
       route[35] = jCoord(route[34].x-190,route[34].y-280);
       route[36] = jCoord(route[35].x-200,route[35].y-230);
       route[37] = jCoord(route[36].x-230,route[36].y-160);
       route[38] = jCoord(route[37].x-230,route[37].y-90);
       route[39] = jCoord(route[38].x-230,route[38].y-110);
       route[40] = jCoord(route[39].x-230,route[39].y-110);
       route[41] = jCoord(route[40].x-230,route[40].y-110);
       route[42] = jCoord(route[41].x-230,route[41].y-60);
       route[43] = jCoord(route[42].x-230,route[42].y-60);
       route[44] = jCoord(route[43].x-230,route[43].y+140);
       route[45] = jCoord(route[44].x-230,route[44].y+270);
       route[46] = jCoord(route[45].x-230,route[45].y+270);
       route[47] = jCoord(route[46].x-230,route[46].y+300);
       route[48] = jCoord(route[47].x-100,route[47].y+280);
       route[49] = jCoord(route[48].x,route[48].y+410);
       route[50] = jCoord(route[49].x-100,route[49].y+200);
       route[51] = jCoord(route[50].x-50,route[50].y+110);
       return route;
    }

    function whereYouLoggedOut() {
       jLogin(ACCNAME);
       while(!jHaveCharlist()) jSleep(700);
       jPrint(jSelectChar(CHARNAME));
       var logwnd = jWaitNewWindow(CHARNAME, 120000);
       jSleep(100);
       logwnd.pushButton(2);
    }

    function Relogin() {
       jLogout();
    }

     function PreviousCoord(Coord) {
       if (jMyCoords()==Coord) return;
       jAbsClick(Coord, 1, 0);
       jWaitStartMove();
       while (jMyCoords().dist(Coord) > 10) jSleep(200);
    }
     
    function NewArrayWithout1stElement(arr) {
       newarr = [];
       for (var i = 1; i < arr.length; i++) {
       newarr[i-1] = arr[i];
       }
    return newarr;
    }


     function GetStuff() {
       var Stuff = jGetObjects(400,jCoord(0,0),"mussel");
       StartCoord = jMyCoords();
       while ((inventory.freeSlots() > 3)&&(Stuff.length>0)) {
          AwayFromGround();
          jPrint(Stuff.length);
          Stuff[0].doClick(3,0);
          jWaitPopup();
          jSelectPopupMenu("Pick");
          jWaitMove(6000);
          jWaitProgress(10000);
          Stuff = NewArrayWithout1stElement(Stuff);
       }   
       Stuff = jGetObjects(400,jCoord(0,0),"flotsam");
       if (Stuff.length>0) {
          AwayFromGround();
          Stuff[0].doClick(3,0);
          jWaitPopup();
          jSelectPopupMenu("Pick");
          jWaitMove(6000);
          jWaitProgress(10000);
       }
       AwayFromGround();
       PreviousCoord(StartCoord);
    }


    function GoHome () {
       jOffsetClick (jCoord(-3,0),1,2);
       jSleep (500);
       jSendDoubleAction("theTrav", "hearth");
       jWaitProgress(300000);
    }

    function checkInventory() {
       if(!jHaveWindow("Inventory")) {
          jToggleInventory();
          while(!jHaveWindow("Inventory")) jSleep(100);
       }
       return jGetWindow("Inventory").getInventories()[0];
    }


    function goToCauldron () {
       var cauldron = jFindObjectByName("cauldron",20);
       var offs = cauldron.position();
       offs = offs.add(0, -10);
       jPFMove(offs);
       jWaitStartMove();
       while (jIsMoving() || jMyCoords().dist(offs) > 10) jSleep(200);
       return cauldron;
    }

    function checkCauldron () {
       var cauldron = jFindObjectByName("cauldron",20);
       if(!jHaveWindow("Cauldron")) {
          jDoClick(cauldron.getID(), 3, 0);
          while(!jHaveWindow("Cauldron"))
          jSleep(100);
       }
       var waterInCauldron = jGetWindow("Cauldron").getMeterValue(1);
       var fuelInCauldron = jGetWindow("Cauldron").getMeterValue(2);
       water = waterInCauldron;
       fuel = fuelInCauldron;
       return water, fuel;
    }

    function goToBarrel() {
       var barrel = jFindObjectByName("barrel",20);
       var offs = barrel.position();
       offs = offs.add(10, 0);
       jPFMove(offs);
       jWaitStartMove();
       while (jIsMoving() || jMyCoords().dist(offs) > 10) jSleep(200);
       return barrel;
    }

    function getWater () {
       inventory = checkInventory();
       barrel = goToBarrel();
       goToBarrel();
       var bucket = inventory.getItems("buckete")[0];
       var bucket_coord = bucket.coord()
       var bucket_name = bucket.resName();
       bucket.take();
       jWaitDrag();
       barrel.interactClick(0);
       while (jGetDraggingItem().resName() == bucket_name) jSleep(100);
       cauldron = goToCauldron ();
       goToCauldron ();
       cauldron.interactClick(0);
       while (jGetDraggingItem().resName() !== bucket_name) jSleep(100);
       inventory.drop(bucket_coord);
       jWaitDrop();
    }

    function getBranch() {
       var inventory = checkInventory();
       var open_cupboard = jGetWindow("Cupboard").getInventories()[0];
       var branch = open_cupboard.getItems("invobjs/branch");
       if (branch.length > 0) {
          for (var i = 0; i < 2; i++) {
             var open_cupboard = jGetWindow("Cupboard").getInventories()[0];
             var branch = open_cupboard.getItems("invobjs/branch");
             branch[i].transfer();
             jSleep(200);
          }
       }
    }


    function getFuel () {
       inventory = checkInventory();
       var cupboards = jGetObjects(50, jCoord(0, 0), "terobjs/cupboard");
       for (var i = 0; i < cupboards.length; i++) {
          var fuelInInventory = inventory.getItems("invobjs/branch");
          if (fuelInInventory.length != 2) {
             var offs = cupboards[i].position();
             offs = offs.add(10, 0);
             jPFMove(offs);
             jWaitStartMove();
             while (jIsMoving() || jMyCoords().dist(offs) > 10) jSleep(200);
             jDoClick(cupboards[i].getID(),3,0);
             jSleep(1000);
             var open_cupboard = jGetWindow("Cupboard");
             getBranch();
             jSleep(1000);
          }
       }
       goToCauldron ();
       for (var i = 0; i < 2; i++) {
          cauldron = goToCauldron ();
          var branch = inventory.getItems("branch")[0];
          branch.take();
          jWaitDrag();
          cauldron.interactClick(0);
          jSleep(1000);
       }
    }

    function boilingMussel () {
       var cauldron = jFindObjectByName("cauldron",20);
       var musselInInventory = inventory.getItems("invobjs/mussel");
       inventory = checkInventory();
       if(!jHaveWindow("Cauldron")) {
          jDoClick(cauldron.getID(), 3, 0);
          while(!jHaveWindow("Cauldron")) jSleep(100);
       }
       jGetWindow("Cauldron").pushButton("Light");
       jSleep (500);
       jSendDoubleAction("craft","cmussel");
       jWaitCraft();
       while (musselInInventory.length > 0) {
          jCraftItem(false);
          jWaitProgress();
          var boiledMusselInInventory = inventory.getItems("invobjs/mussel-boiled");
          if (boiledMusselInInventory.length > 0) {
             boiledMusselInInventory[0].drop();
             jWaitDrop();
          }
          musselInInventory = inventory.getItems("invobjs/mussel");
       }
       jSendAction("carry");
       jSleep (500);
       jDoClick(cauldron.getID(), 1, 0);
       jSleep (1000);
       jOffsetClick(jCoord(0,-1), 1, 0);
       jSleep (1000);
       jOffsetClick(jCoord(0,2), 3, 0);
       jSleep (1000);
    }

    function GoDrinkWine() {
       door = jFindObjectByName("cabin-door2",100);
       doorCoord = door.position();
       doorAround = jCoord(doorCoord.x-10,doorCoord.y);
       jPFMove(doorAround);
            waitPFEndMove();
       while (jIsMoving() || jMyCoords().dist(doorAround) > 10) jSleep(100);
       door.doClick(3,0);
       jWaitMove();
       jSleep(500);
       basket = jFindObjectByName("birchbasket",100);
       basketCoord = basket.position();
       basketAround =jCoord(basketCoord.x+10,basketCoord.y);
       jPFMove(basketAround);
       waitPFEndMove();
       while (jIsMoving() || jMyCoords().dist(basketAround) > 2) jSleep(100);
       basket.doClick(3,0);
       while(!jHaveWindow("Basket")) jSleep(100);
       BasketInventory = jGetWindow("Basket").getInventories()[0];
       var buckets = BasketInventory.getItems("bucket-wine");
       if (buckets.length > 0) {
          BasketInventory.sortItems(buckets, "amount", false);
          var bucket = buckets[0];
          var bucket_coord = bucket.coord();
          if (bucket.isActual()) {
             bucket.take();
             jWaitDrag();
             var glasses = BasketInventory.getItems("glass");
             if (glasses.length > 0) {
                var glass = glasses[0];
                if (glass.isActual()) {
                   glass.itemact(0);
                   jSleep(500);
                   BasketInventory.drop(bucket_coord);
                   jWaitDrop();
                }
             }
          }
       }
       var glasses = BasketInventory.getItems("glass");
       if (glasses.length > 0) {
          var glass = glasses[0];
          if (glass.isActual()) {
             glass.iact();
             if (jWaitPopup(actionTimeout)) {
                jSelectContextMenu("Drink");
                jWaitProgress();
             }
          }
       }
    }

    function DropCurioToChest() {
       chest = jFindObjectByName("cclosed",100);
       chestCoord = chest.position();
       chestAround =jCoord(chestCoord.x,chestCoord.y+10);
       jPFMove(chestAround);
       waitPFEndMove();
       while (jIsMoving() || jMyCoords().dist(chestAround) > 10) jSleep(100);
       chest.doClick(3,0);
       while(!jHaveWindow("Chest")) jSleep(100);
       while (inventory.getItems(CurioName).length > 0) {
          inventory.getItems(CurioName)[0].transferSuchAll();
          jSleep(500);
       }
    }

    function GoToBoat() {
       var cross = jFindObjectByName("crossroads",100);
       var crossCoord = cross.position();
       var crossAround =jCoord(crossCoord.x+10,crossCoord.y);
       jPFMove(crossAround);
       waitPFEndMove();
       while (jIsMoving() || jMyCoords().dist(crossAround) > 2) jSleep(100);
       cross.doClick(3,0);
       while(!jHaveWindow("Yoitsu")) jSleep(100);
       jGetWindow("Yoitsu").pushButton(1);
       jSleep(4000);
       
       AwayFromCross();
       boat = jFindObjectByName("boat",100);
       boatCoord = boat.position();
       boatAround =jCoord(boatCoord.x-20,boatCoord.y);
       jPFMove(boatAround);
       while (jIsMoving() || jMyCoords().dist(boatAround) > 10) jSleep(100);
       boat.doClick(3,0);
       jSleep(2000);
       jSelectPopupMenu("Avast!");
       jWaitMove();
    }

    function AwayFromCross() {
       Cross = jFindObjectByName("crossroads",100);
       CrossCoord = Cross.position();
       MyCoord = jMyCoords();
       CrossAroundN = jCoord(CrossCoord.x,CrossCoord.y-10);
       CrossAroundE = jCoord(CrossCoord.x+10,CrossCoord.y);
       CrossAroundS = jCoord(CrossCoord.x,CrossCoord.y+10);
       CrossAroundW = jCoord(CrossCoord.x-10,CrossCoord.y);
       DistN = MyCoord.dist(CrossAroundN);
       DistE = MyCoord.dist(CrossAroundE);
       DistS = MyCoord.dist(CrossAroundS);
       DistW = MyCoord.dist(CrossAroundW);
       DistMin = DistN;
       CoordDistMin = CrossAroundN;
       if (DistE < DistMin){ DistMin = DistE; CoordDistMin = CrossAroundE; }
       if (DistS < DistMin){ DistMin = DistS; CoordDistMin = CrossAroundS; }
       if (DistW < DistMin){ DistMin = DistW; CoordDistMin = CrossAroundW; }
       jAbsClick(CoordDistMin, 1, 0);
       jWaitMove();
    }

    function isTileGround(coord) {
       if (!(jGetTileType(coord) == 0 || jGetTileType(coord) == 1)) return true
       else return false;
    }

    function AwayFromGround() {
       if (!((isTileGround(jCoord(0,-1))) || (isTileGround(jCoord(1,0))) || (isTileGround(jCoord(0,1))) || (isTileGround(jCoord(-1,0))))) return;
       var offs = jMyCoords();
       if (isTileGround(jCoord(0,-1))) offs = offs.add(0,20);
       if (isTileGround(jCoord(1,0))) offs = offs.add(-20,0);
       if (isTileGround(jCoord(0,1))) offs = offs.add(0,-20);
       if (isTileGround(jCoord(-1,0))) offs = offs.add(20,0);
       jAbsClick(offs, 1, 0);
       jWaitStartMove();
       jSleep(500);
    }

     function main() {
       while (1) {
          route = GetRoute();
          for(var i = 0; i < route.length; i++) {
             GetStuff();
             PreviousCoord(route[i]);
             if(jGetStamina() < 50) drinkWater();
          }
          jSleep(1000);
          GoHome ();
          jSleep(1000);
          goToCauldron ();
          checkCauldron ();
          if (water < 33) {
             getWater();
          }
          if (fuel < 13) {
             getFuel();
          }
          boilingMussel ();
          DropCurioToChest();
          jSleep(660000);
          GoDrinkWine();
          GoToBoat();
       }
    }
     
    main();
Bot dont go in koords . Can somebody fix it ?
turnipmelody
Posts: 4
Joined: Tue Jul 19, 2011 8:37 am

Re: Union Client Scripts

Post by turnipmelody »

I'm ridiculously new to this, but i need a script that chops all trees in a specific area, then lifts the logs and places them in a select-able position. Is there anything for this?
User avatar
Arcanist
Posts: 2664
Joined: Mon Mar 19, 2012 2:01 pm

Re: Union Client Scripts

Post by Arcanist »

turnipmelody wrote:I'm ridiculously new to this, but i need a script that chops all trees in a specific area, then lifts the logs and places them in a select-able position. Is there anything for this?
Not currently, but there will be soon...
User avatar
Arcanist
Posts: 2664
Joined: Mon Mar 19, 2012 2:01 pm

Re: Union Client Scripts

Post by Arcanist »

Seems to work properly.

Code: Select all

//#! name = Chop Trees In Area
//#! uniq = arcanist_chopper
//#! icon = gfx/invobjs/axe

//**************************************************************************************************************
//*********************************Pathfinder*******************************************************************
//**************************************************************************************************************

var actionTimeout = 1000 * 60 * 1;


function getRandomArbitary(min, max){
  return Math.random() * (max - min) + min;
}

function jPFMove_LX(point) {
   point = jTilify(point);
   var MyX = jMyCoords().x;
   var MyY = jMyCoords().y;
   if (jIsPathFree(point)) jAbsClick(point, 1, 0);
   else jPFMove(point);
   cycles = 0;
   wcontinue = true;
   while (wcontinue) {
      wcontinue = MyX != point.x || MyY != point.y;
      jPrint("jPFMove_LX My =" + MyX + " " + MyY + " - " + point.x + " " + point.y);
      jSleep(1000);
      MyX = jMyCoords().x;
      MyY = jMyCoords().y;
      if(cycles == 6) {      
         jPrint("jPFMove_LX trying to move again");
         jOffsetClick(jCoord(getRandomArbitary(-2,2),getRandomArbitary(-2,2)),1,0);
         jSleep(500);
         if (!jIsPathFree(point)) jPFMove(point);
		 else jAbsClick(point, 1, 0);
         cycles = 0
         wcontinue = false;
      }
      cycles++;
   }
   jPrint("jPFMove ended");
}

function jPFMoveOffset_LX(point, offset) {
   offsMoveS=jCoord(0,offset);
   offsMoveE=jCoord(offset,0);
   offsMoveW=jCoord(-offset,0);
   offsMoveN=jCoord(0,-offset);
   
   while (1){
try   {
   /*
	if (jIsPathFree(point.add(offsMoveS.mul(11)))) {
		jAbsClick(point, 1, 0);
		return offsMoveS;
		}
	if (jIsPathFree(point.add(offsMoveE.mul(11)))) {
		jAbsClick(point, 1, 0);
		return offsMoveE;
		}
	if (jIsPathFree(point.add(offsMoveW.mul(11)))) {
		jAbsClick(point, 1, 0);
		return offsMoveW;
		}
	if (jIsPathFree(point.add(offsMoveN.mul(11)))) {
		jAbsClick(point, 1, 0);
		return offsMoveN;
		}
   */
      if(jPFMove(point.add(offsMoveS.mul(11))) > 0) {
         jPFMove_LX(point.add(offsMoveS.mul(11)));
		return offsMoveS;
      }
      
      if(jPFMove(point.add(offsMoveE.mul(11))) > 0) {
         jPFMove_LX(point.add(offsMoveE.mul(11)));
      return offsMoveE;
      }
      
      if(jPFMove(point.add(offsMoveW.mul(11))) > 0) {
         jPFMove_LX(point.add(offsMoveW.mul(11)));
      return offsMoveW;
      }   
      
      if(jPFMove(point.add(offsMoveN.mul(11))) > 0) {
         jPFMove_LX(point.add(offsMoveN.mul(11)));
      return offsMoveN;
      }
      jPrint("jPFMoveOffset_LX can't find path to " + point + " offset " + offset);
//      break;

         jOffsetClick(jCoord(getRandomArbitary(-2,2),getRandomArbitary(-2,2)),1,0);
         jSleep(500);
      
   }
   catch(e) {
	jPrint(e);
   }
}
}


function waitPFEndMove(){
	jWaitStartMove(300);
	jSleep(100);
	while (true) {
		jWaitEndMove(10000);
		jSleep(200);
		if (!jIsMoving()) {
			return;
		}
	}
}

//**************************************************************************************************************
//*********************************Support Functions************************************************************
//**************************************************************************************************************

function travelCount() {
	var buffs = jGetBuffs();
	for (var i = 0; i < buffs.length; i++) {
		if (buffs[i].name().indexOf("Travel Weariness") >= 0) {
			return buffs[i].meter();
		}
	}
	return 0;
}
	
	function checkInventory() {
	if(!jHaveWindow("Inventory")) {
		jToggleInventory();
		while(!jHaveWindow("Inventory"))
			jSleep(100);
	}
	return jGetWindow("Inventory").getInventories()[0];
}

function equipShovel() { // From axe
   var equip = checkEquipment();
   var shovel = checkInventory().getItems("shovel")[0];
   if (!shovel) return;
   if (equip.resName(6).indexOf("axe") >= 0) {
      dropItem(shovel.coord().add(0, 1));
      equip.takeAt(6);
      jWaitDrag(actionTimeout);
      checkInventory().drop(shovel.coord());
      jSleep(1000);
      waitDragName("shovel");
      equip.dropTo(6);
      jWaitDrop(actionTimeout);
   }
   if (equip.resName(7).indexOf("axe") >= 0) {
      dropItem(shovel.coord().add(0, 1));
      equip.takeAt(7);
      jWaitDrag(actionTimeout);
      checkInventory().drop(shovel.coord());
      jSleep(1000);
      waitDragName("shovel");
      equip.dropTo(6);
      jWaitDrop(actionTimeout);
   }
}	

function equipAxe() { // From Shovel
   var equip = checkEquipment();
   var axe = checkInventory().getItems("axe")[0];
   if (!axe) return;
   if (equip.resName(6).indexOf("shovel") >= 0) {
      dropItem(axe.coord().add(0, 1));
      equip.takeAt(6);
      jWaitDrag(actionTimeout);
      checkInventory().drop(axe.coord());
      jSleep(1000);
      waitDragName("axe");
      equip.dropTo(6);
      jWaitDrop(actionTimeout);
   }
}	

function waitDragName(name) {
   while (true) {
      var item = jGetDraggingItem();
      if (item != null) {
	  jSleep(500) 
         if (item.resName() != null) {
         if (item.resName().indexOf(name) >= 0) {
            break;
         } else {
            jSleep(100);
         }
         } else jSleep(100);
      } else {
         break;
      }
   }
}

function dropItem(coord) {
   var items = checkInventory().getItems("");
   for (var i = 0; i < items.length; i++) {
      if (items[i].coord().x == coord.x && items[i].coord().y == coord.y) { 
         items[i].drop();
         break;
      }
   }   
}

function checkEquipment() {
   if(!jHaveWindow("Equipment")) {
      jToggleEquipment();
      while(!jHaveWindow("Equipment"))
         jSleep(100);
   }
   return jGetJSEquip();
}

function drinkWater() {
   if (jGetStamina() > 80) return;
   var buckets = checkInventory().getItems("bucket-water");
   if (buckets.length > 0) {
      checkInventory().sortItems(buckets, "amount", false);
      var bucket = buckets[0];
      var bucket_coord = bucket.coord();
      if (bucket.isActual()) {
         bucket.take();
         jWaitDrag();
         var flasks = checkInventory().getItems("waterflask", "waterskin");
         if (flasks.length > 0) {
            var flask = flasks[0];
            if (flask.isActual()) {
               flask.itemact(0);
               jSleep(500);
               checkInventory().drop(bucket_coord);
               jWaitDrop();
            }
         }
      }
   }
 var flasks = checkInventory().getItems("waterflask", "waterskin");
   if (flasks.length > 0) {
      var flask = flasks[0];
      if (flask.isActual()) {
         flask.iact();
         if (jWaitPopup(actionTimeout)) {
            jSelectContextMenu("Drink");
            jWaitProgress();
         } else {
            // No water
            stopFlag = true;
         }
      }
   }
}	

function drinkWine() {
   if (travelCount() < 85) return;
   var buckets = checkInventory().getItems("bucket-wine");
   if (buckets.length > 0) {
      checkInventory().sortItems(buckets, "amount", false);
      var bucket = buckets[0];
      var bucket_coord = bucket.coord();
      if (bucket.isActual()) {
         bucket.take();
         jWaitDrag();
         var flasks = checkInventory().getItems("glass-winee");
         if (flasks.length > 0) {
            var flask = flasks[0];
            if (flask.isActual()) {
               flask.itemact(0);
               jSleep(500);
               checkInventory().drop(bucket_coord);
               jWaitDrop();
            }
         }
      }
   }
   var flasks = checkInventory().getItems("glass-winef");
   if (flasks.length > 0) {
      var flask = flasks[0];
      if (flask.isActual()) {
         flask.iact();
         if (jWaitPopup(actionTimeout)) {
			jSleep(500)
            jSelectContextMenu("Drink");
            jWaitProgress();
			winecount++;
         } else {
            // No water
            stopFlag = true;
         }
      }
   }
  if (travelCount() < 85) return;
  drinkWine();
   }


function takethislog(log) {
	while (!jFindObjectByName ("borka", 1).isCarrying ()){
      jSendAction("carry");
      jWaitCursor("chi");
      jDoClick(log.getID(), 1, 0);
      jWaitMove(2500);
	  }
}
	  

function droplog() {
	while (jFindObjectByName ("borka", 1).isCarrying ()){
		jAbsClick(jMyCoords(), 3, 0);
		jSleep(500);
		jPrint("Dropped Log");
		}
      jWaitMove(1000);
	  return;
}


function stumper(){
		dropblock();
		jSleep(100);
		equipShovel();
		jSleep(300);
		var target_stump = getNearestStump();
		jDoClick(target_stump.getID(), 3, 0);
		jWaitPopup(1000);
		jSelectContextMenu("Remove");
		jSleep(200);
		jWaitProgress(actionTimeout);
		jSleep(500);
		while (jIsDragging()) {
				jDropObject(0);
				jSleep(300);      
			}
		drinkWater();
		return;
}
	
function getNearestStump() {
   var trees = jGetObjects(35, jCoord(0, 0), ["stump"]);
   var min_len = 100500; 
   var objid = 0;
   for (var i = 0; i < trees.length; i++) {
      if (trees[i].position().dist(jMyCoords()) < min_len) {
         objid = trees[i];
         min_len = trees[i].position().dist(jMyCoords());
      }
   }
   return objid;
}
	

function resetCursor() {
	if (!jIsCursor("arw")) {
		jAbsClick(jCoord(0, 0), 3, 0);
		jWaitCursor("arw", actionTimeout);
	}
}
	


		
	
function cutthistree(target) {
			equipAxe();
			jDoClick(target.getID(), 3, 0);
			jWaitPopup(3000);
			jSelectContextMenu("Chop");
			jSleep(200);
			jWaitProgress(actionTimeout);
			jSleep(200);
			return;}
		
		

		
function dropblock() {

			checkInventory();
			var inventory_wood = jGetWindow("Inventory").getInventories()[0].getItems("wood");
			while (jIsDragging()) {
				jDropObject(0);
				jSleep(300);      
			}
			for(var i in inventory_wood){
					if(inventory_wood[i] == 0){
						break;
					}
					inventory_wood[i].drop();
					jSleep(200);
			}
	}
		
		
function selectInRect(resname, blob, title) {
	jMoveStep(jCoord(0, 0));
	var offs = jCoord(0, 0);
	var size = jCoord(1, 1);
	var confirm = false;
	jDrawGroundRect(offs, size);
	var blist = ["West", "East", "North", "South", "Inc width", "Inc height", "Dec width", "Dec height", "Confirm", "Exit"];
	var selectWindow = jGUIWindow(jCoord(250, 250), jCoord(105, blist.length * 25 + 15), "Area");
	var label = jGUILabel(selectWindow, jCoord(5, 5), title);
	for(var i = 0; i < blist.length; i++)
		jGUIButton(selectWindow, jCoord(5, 25 + i*25),  100, blist[i]);
	selectWindow.toggleCloseButton();
	var btext = "";
	while(btext != "Exit"){
		btext = selectWindow.waitButtonClick();
		if(btext == blist[0]) offs.x--;
		if(btext == blist[1]) offs.x++;
		if(btext == blist[2]) offs.y--;
		if(btext == blist[3]) offs.y++;
		if(btext == blist[4]) size.x++;
		if(btext == blist[5]) size.y++;
		if(btext == blist[6]) if(size.x > 1) size.x--;
		if(btext == blist[7]) if(size.y > 1) size.y--;
		if(btext == blist[8]) {confirm = true; break;}
		jDrawGroundRect(offs, size);
	}
	selectWindow.destroy();
	jDrawGroundRect(offs, jCoord(0, 0));
	var startCoord = jMyCoords().add(offs.mul(11));
	var fieldSize = size;
	var returns = [];
	//jToConsole(size);
	//jToConsole(startCoord);
	//jToConsole(offs);
	jToConsole("Finding Trees");
	jToConsole("This may take a while...");
	for (var x = 0; x < (size.x * 11) ; x++){ // This shit takes fucking ages, it needs to search each abs coord, since trees are not alligned to grid.
		var hori = startCoord.x + x ;
		for (var y = 0; y < (size.y * 11) ; y++) {
			var verti = startCoord.y + y ;
			var object = jFindMapObjectNearAbs(jCoord(hori,verti), 1,resname);
			//jPrint(jCoord(hori,verti));
			if (object) {
				var same = 1;
				//jToConsole("Found one");
				returns.push(object);
				
			}
		}
	}

	return returns;
}

function goNearPosition( position, offset){
	if (offset == 0) distance = 11;
	if (offset > 0) distance = 11 * offset;
	    while (jIsMoving() || jMyCoords().dist(position) > distance){
			jPFMoveOffset_LX(position, offset);
			jSleep(1500);
		}
}

function selectSingleSpace(title) {
	jMoveStep(jCoord(0, 0));
	var offs = jCoord(0, 0);
	var size = jCoord(1, 1);
	var confirm = false;
	jDrawGroundRect(offs, size);
	var blist = ["West", "East", "North", "South", "Confirm", "Exit"];
	var selectWindow = jGUIWindow(jCoord(250, 250), jCoord(105, blist.length * 25 + 15), "Area");
	var label = jGUILabel(selectWindow, jCoord(5, 5), title);
	for(var i = 0; i < blist.length; i++)
		jGUIButton(selectWindow, jCoord(5, 25 + i*25),  100, blist[i]);
	selectWindow.toggleCloseButton();
	var btext = "";
	while(btext != "Exit"){
		btext = selectWindow.waitButtonClick();
		if(btext == blist[0]) offs.x--;
		if(btext == blist[1]) offs.x++;
		if(btext == blist[2]) offs.y--;
		if(btext == blist[3]) offs.y++;
		if(btext == blist[4]) {confirm = true; break;}
		jDrawGroundRect(offs, size);
	}
	selectWindow.destroy();
	jDrawGroundRect(offs, jCoord(0, 0));
	var startCoord = jMyCoords().add(offs.mul(11));
	var fieldSize = size;
	var returns = [];
	//jToConsole(size);
	//jToConsole(startCoord);
	//jToConsole(offs);

	returns = jCoord(startCoord.x,startCoord.y ); // Top left
	return returns;
}

//**************************************************************************************************************
//*********************************Main Content*****************************************************************
//**************************************************************************************************************


function main(){
var dropCoord = selectSingleSpace("Select Drop Area");
var trees = selectInRect("06", 0, "Select Area for deforrestation");
jToConsole("There are " + trees.length + " trees in this area");

var newlogs = [];
for (var currenttree = 0; currenttree < trees.length; currenttree++){
	var oldlogs = jGetObjects(50, jCoord(0, 0), "log");
	var newlogs = [];
	var logs = [];
	goNearPosition(trees[currenttree].position(), 1);
	cutthistree(trees[currenttree]);
	stumper();
	
	// Now for the logs...
	
	var logs = jGetObjects(50, jCoord(0, 0), "log");
	for (var q = 0; q < logs.length; q++){
		
		var breaker = false;
	
		if (logs[q].position().dist(dropCoord) < 11) {
			var breaker = true;
		}// Checks logs against dropCoord
		
		if (!breaker){
			for (var k = 0; k < oldlogs.length; k++){
				if(logs[q].getID() == oldlogs[k].getID()) { // Checks against all logs that were there previously. This may be commented if desired
					var breaker = true;
					break;
				}			
			}
		}
		
		if (!breaker) {
			newlogs.push(logs[q]);
		}
	}
	// Now he moves the logs
	
	for (var currentlog = 0; currentlog < newlogs.length; currentlog++){
		goNearPosition(newlogs[currentlog].position(), 0);
		takethislog(newlogs[currentlog]);
		
		goNearPosition(dropCoord, 0);
		droplog();
	}
	
	
}

}

main();
User avatar
shubla
Posts: 13041
Joined: Sun Nov 03, 2013 11:26 am
Location: Finland

Re: Union Client Scripts

Post by shubla »

Arcanist wrote:Seems to work properly.

Code: Select all

//#! name = Chop Trees In Area
//#! uniq = arcanist_chopper
//#! icon = gfx/invobjs/axe

//**************************************************************************************************************
//*********************************Pathfinder*******************************************************************
//**************************************************************************************************************

var actionTimeout = 1000 * 60 * 1;


function getRandomArbitary(min, max){
  return Math.random() * (max - min) + min;
}

function jPFMove_LX(point) {
   point = jTilify(point);
   var MyX = jMyCoords().x;
   var MyY = jMyCoords().y;
   if (jIsPathFree(point)) jAbsClick(point, 1, 0);
   else jPFMove(point);
   cycles = 0;
   wcontinue = true;
   while (wcontinue) {
      wcontinue = MyX != point.x || MyY != point.y;
      jPrint("jPFMove_LX My =" + MyX + " " + MyY + " - " + point.x + " " + point.y);
      jSleep(1000);
      MyX = jMyCoords().x;
      MyY = jMyCoords().y;
      if(cycles == 6) {      
         jPrint("jPFMove_LX trying to move again");
         jOffsetClick(jCoord(getRandomArbitary(-2,2),getRandomArbitary(-2,2)),1,0);
         jSleep(500);
         if (!jIsPathFree(point)) jPFMove(point);
		 else jAbsClick(point, 1, 0);
         cycles = 0
         wcontinue = false;
      }
      cycles++;
   }
   jPrint("jPFMove ended");
}

function jPFMoveOffset_LX(point, offset) {
   offsMoveS=jCoord(0,offset);
   offsMoveE=jCoord(offset,0);
   offsMoveW=jCoord(-offset,0);
   offsMoveN=jCoord(0,-offset);
   
   while (1){
try   {
   /*
	if (jIsPathFree(point.add(offsMoveS.mul(11)))) {
		jAbsClick(point, 1, 0);
		return offsMoveS;
		}
	if (jIsPathFree(point.add(offsMoveE.mul(11)))) {
		jAbsClick(point, 1, 0);
		return offsMoveE;
		}
	if (jIsPathFree(point.add(offsMoveW.mul(11)))) {
		jAbsClick(point, 1, 0);
		return offsMoveW;
		}
	if (jIsPathFree(point.add(offsMoveN.mul(11)))) {
		jAbsClick(point, 1, 0);
		return offsMoveN;
		}
   */
      if(jPFMove(point.add(offsMoveS.mul(11))) > 0) {
         jPFMove_LX(point.add(offsMoveS.mul(11)));
		return offsMoveS;
      }
      
      if(jPFMove(point.add(offsMoveE.mul(11))) > 0) {
         jPFMove_LX(point.add(offsMoveE.mul(11)));
      return offsMoveE;
      }
      
      if(jPFMove(point.add(offsMoveW.mul(11))) > 0) {
         jPFMove_LX(point.add(offsMoveW.mul(11)));
      return offsMoveW;
      }   
      
      if(jPFMove(point.add(offsMoveN.mul(11))) > 0) {
         jPFMove_LX(point.add(offsMoveN.mul(11)));
      return offsMoveN;
      }
      jPrint("jPFMoveOffset_LX can't find path to " + point + " offset " + offset);
//      break;

         jOffsetClick(jCoord(getRandomArbitary(-2,2),getRandomArbitary(-2,2)),1,0);
         jSleep(500);
      
   }
   catch(e) {
	jPrint(e);
   }
}
}


function waitPFEndMove(){
	jWaitStartMove(300);
	jSleep(100);
	while (true) {
		jWaitEndMove(10000);
		jSleep(200);
		if (!jIsMoving()) {
			return;
		}
	}
}

//**************************************************************************************************************
//*********************************Support Functions************************************************************
//**************************************************************************************************************

function travelCount() {
	var buffs = jGetBuffs();
	for (var i = 0; i < buffs.length; i++) {
		if (buffs[i].name().indexOf("Travel Weariness") >= 0) {
			return buffs[i].meter();
		}
	}
	return 0;
}
	
	function checkInventory() {
	if(!jHaveWindow("Inventory")) {
		jToggleInventory();
		while(!jHaveWindow("Inventory"))
			jSleep(100);
	}
	return jGetWindow("Inventory").getInventories()[0];
}

function equipShovel() { // From axe
   var equip = checkEquipment();
   var shovel = checkInventory().getItems("shovel")[0];
   if (!shovel) return;
   if (equip.resName(6).indexOf("axe") >= 0) {
      dropItem(shovel.coord().add(0, 1));
      equip.takeAt(6);
      jWaitDrag(actionTimeout);
      checkInventory().drop(shovel.coord());
      jSleep(1000);
      waitDragName("shovel");
      equip.dropTo(6);
      jWaitDrop(actionTimeout);
   }
   if (equip.resName(7).indexOf("axe") >= 0) {
      dropItem(shovel.coord().add(0, 1));
      equip.takeAt(7);
      jWaitDrag(actionTimeout);
      checkInventory().drop(shovel.coord());
      jSleep(1000);
      waitDragName("shovel");
      equip.dropTo(6);
      jWaitDrop(actionTimeout);
   }
}	

function equipAxe() { // From Shovel
   var equip = checkEquipment();
   var axe = checkInventory().getItems("axe")[0];
   if (!axe) return;
   if (equip.resName(6).indexOf("shovel") >= 0) {
      dropItem(axe.coord().add(0, 1));
      equip.takeAt(6);
      jWaitDrag(actionTimeout);
      checkInventory().drop(axe.coord());
      jSleep(1000);
      waitDragName("axe");
      equip.dropTo(6);
      jWaitDrop(actionTimeout);
   }
}	

function waitDragName(name) {
   while (true) {
      var item = jGetDraggingItem();
      if (item != null) {
	  jSleep(500) 
         if (item.resName() != null) {
         if (item.resName().indexOf(name) >= 0) {
            break;
         } else {
            jSleep(100);
         }
         } else jSleep(100);
      } else {
         break;
      }
   }
}

function dropItem(coord) {
   var items = checkInventory().getItems("");
   for (var i = 0; i < items.length; i++) {
      if (items[i].coord().x == coord.x && items[i].coord().y == coord.y) { 
         items[i].drop();
         break;
      }
   }   
}

function checkEquipment() {
   if(!jHaveWindow("Equipment")) {
      jToggleEquipment();
      while(!jHaveWindow("Equipment"))
         jSleep(100);
   }
   return jGetJSEquip();
}

function drinkWater() {
   if (jGetStamina() > 80) return;
   var buckets = checkInventory().getItems("bucket-water");
   if (buckets.length > 0) {
      checkInventory().sortItems(buckets, "amount", false);
      var bucket = buckets[0];
      var bucket_coord = bucket.coord();
      if (bucket.isActual()) {
         bucket.take();
         jWaitDrag();
         var flasks = checkInventory().getItems("waterflask", "waterskin");
         if (flasks.length > 0) {
            var flask = flasks[0];
            if (flask.isActual()) {
               flask.itemact(0);
               jSleep(500);
               checkInventory().drop(bucket_coord);
               jWaitDrop();
            }
         }
      }
   }
 var flasks = checkInventory().getItems("waterflask", "waterskin");
   if (flasks.length > 0) {
      var flask = flasks[0];
      if (flask.isActual()) {
         flask.iact();
         if (jWaitPopup(actionTimeout)) {
            jSelectContextMenu("Drink");
            jWaitProgress();
         } else {
            // No water
            stopFlag = true;
         }
      }
   }
}	

function drinkWine() {
   if (travelCount() < 85) return;
   var buckets = checkInventory().getItems("bucket-wine");
   if (buckets.length > 0) {
      checkInventory().sortItems(buckets, "amount", false);
      var bucket = buckets[0];
      var bucket_coord = bucket.coord();
      if (bucket.isActual()) {
         bucket.take();
         jWaitDrag();
         var flasks = checkInventory().getItems("glass-winee");
         if (flasks.length > 0) {
            var flask = flasks[0];
            if (flask.isActual()) {
               flask.itemact(0);
               jSleep(500);
               checkInventory().drop(bucket_coord);
               jWaitDrop();
            }
         }
      }
   }
   var flasks = checkInventory().getItems("glass-winef");
   if (flasks.length > 0) {
      var flask = flasks[0];
      if (flask.isActual()) {
         flask.iact();
         if (jWaitPopup(actionTimeout)) {
			jSleep(500)
            jSelectContextMenu("Drink");
            jWaitProgress();
			winecount++;
         } else {
            // No water
            stopFlag = true;
         }
      }
   }
  if (travelCount() < 85) return;
  drinkWine();
   }


function takethislog(log) {
	while (!jFindObjectByName ("borka", 1).isCarrying ()){
      jSendAction("carry");
      jWaitCursor("chi");
      jDoClick(log.getID(), 1, 0);
      jWaitMove(2500);
	  }
}
	  

function droplog() {
	while (jFindObjectByName ("borka", 1).isCarrying ()){
		jAbsClick(jMyCoords(), 3, 0);
		jSleep(500);
		jPrint("Dropped Log");
		}
      jWaitMove(1000);
	  return;
}


function stumper(){
		dropblock();
		jSleep(100);
		equipShovel();
		jSleep(300);
		var target_stump = getNearestStump();
		jDoClick(target_stump.getID(), 3, 0);
		jWaitPopup(1000);
		jSelectContextMenu("Remove");
		jSleep(200);
		jWaitProgress(actionTimeout);
		jSleep(500);
		while (jIsDragging()) {
				jDropObject(0);
				jSleep(300);      
			}
		drinkWater();
		return;
}
	
function getNearestStump() {
   var trees = jGetObjects(35, jCoord(0, 0), ["stump"]);
   var min_len = 100500; 
   var objid = 0;
   for (var i = 0; i < trees.length; i++) {
      if (trees[i].position().dist(jMyCoords()) < min_len) {
         objid = trees[i];
         min_len = trees[i].position().dist(jMyCoords());
      }
   }
   return objid;
}
	

function resetCursor() {
	if (!jIsCursor("arw")) {
		jAbsClick(jCoord(0, 0), 3, 0);
		jWaitCursor("arw", actionTimeout);
	}
}
	


		
	
function cutthistree(target) {
			equipAxe();
			jDoClick(target.getID(), 3, 0);
			jWaitPopup(3000);
			jSelectContextMenu("Chop");
			jSleep(200);
			jWaitProgress(actionTimeout);
			jSleep(200);
			return;}
		
		

		
function dropblock() {

			checkInventory();
			var inventory_wood = jGetWindow("Inventory").getInventories()[0].getItems("wood");
			while (jIsDragging()) {
				jDropObject(0);
				jSleep(300);      
			}
			for(var i in inventory_wood){
					if(inventory_wood[i] == 0){
						break;
					}
					inventory_wood[i].drop();
					jSleep(200);
			}
	}
		
		
function selectInRect(resname, blob, title) {
	jMoveStep(jCoord(0, 0));
	var offs = jCoord(0, 0);
	var size = jCoord(1, 1);
	var confirm = false;
	jDrawGroundRect(offs, size);
	var blist = ["West", "East", "North", "South", "Inc width", "Inc height", "Dec width", "Dec height", "Confirm", "Exit"];
	var selectWindow = jGUIWindow(jCoord(250, 250), jCoord(105, blist.length * 25 + 15), "Area");
	var label = jGUILabel(selectWindow, jCoord(5, 5), title);
	for(var i = 0; i < blist.length; i++)
		jGUIButton(selectWindow, jCoord(5, 25 + i*25),  100, blist[i]);
	selectWindow.toggleCloseButton();
	var btext = "";
	while(btext != "Exit"){
		btext = selectWindow.waitButtonClick();
		if(btext == blist[0]) offs.x--;
		if(btext == blist[1]) offs.x++;
		if(btext == blist[2]) offs.y--;
		if(btext == blist[3]) offs.y++;
		if(btext == blist[4]) size.x++;
		if(btext == blist[5]) size.y++;
		if(btext == blist[6]) if(size.x > 1) size.x--;
		if(btext == blist[7]) if(size.y > 1) size.y--;
		if(btext == blist[8]) {confirm = true; break;}
		jDrawGroundRect(offs, size);
	}
	selectWindow.destroy();
	jDrawGroundRect(offs, jCoord(0, 0));
	var startCoord = jMyCoords().add(offs.mul(11));
	var fieldSize = size;
	var returns = [];
	//jToConsole(size);
	//jToConsole(startCoord);
	//jToConsole(offs);
	jToConsole("Finding Trees");
	jToConsole("This may take a while...");
	for (var x = 0; x < (size.x * 11) ; x++){ // This shit takes fucking ages, it needs to search each abs coord, since trees are not alligned to grid.
		var hori = startCoord.x + x ;
		for (var y = 0; y < (size.y * 11) ; y++) {
			var verti = startCoord.y + y ;
			var object = jFindMapObjectNearAbs(jCoord(hori,verti), 1,resname);
			//jPrint(jCoord(hori,verti));
			if (object) {
				var same = 1;
				//jToConsole("Found one");
				returns.push(object);
				
			}
		}
	}

	return returns;
}

function goNearPosition( position, offset){
	if (offset == 0) distance = 11;
	if (offset > 0) distance = 11 * offset;
	    while (jIsMoving() || jMyCoords().dist(position) > distance){
			jPFMoveOffset_LX(position, offset);
			jSleep(1500);
		}
}

function selectSingleSpace(title) {
	jMoveStep(jCoord(0, 0));
	var offs = jCoord(0, 0);
	var size = jCoord(1, 1);
	var confirm = false;
	jDrawGroundRect(offs, size);
	var blist = ["West", "East", "North", "South", "Confirm", "Exit"];
	var selectWindow = jGUIWindow(jCoord(250, 250), jCoord(105, blist.length * 25 + 15), "Area");
	var label = jGUILabel(selectWindow, jCoord(5, 5), title);
	for(var i = 0; i < blist.length; i++)
		jGUIButton(selectWindow, jCoord(5, 25 + i*25),  100, blist[i]);
	selectWindow.toggleCloseButton();
	var btext = "";
	while(btext != "Exit"){
		btext = selectWindow.waitButtonClick();
		if(btext == blist[0]) offs.x--;
		if(btext == blist[1]) offs.x++;
		if(btext == blist[2]) offs.y--;
		if(btext == blist[3]) offs.y++;
		if(btext == blist[4]) {confirm = true; break;}
		jDrawGroundRect(offs, size);
	}
	selectWindow.destroy();
	jDrawGroundRect(offs, jCoord(0, 0));
	var startCoord = jMyCoords().add(offs.mul(11));
	var fieldSize = size;
	var returns = [];
	//jToConsole(size);
	//jToConsole(startCoord);
	//jToConsole(offs);

	returns = jCoord(startCoord.x,startCoord.y ); // Top left
	return returns;
}

//**************************************************************************************************************
//*********************************Main Content*****************************************************************
//**************************************************************************************************************


function main(){
var dropCoord = selectSingleSpace("Select Drop Area");
var trees = selectInRect("06", 0, "Select Area for deforrestation");
jToConsole("There are " + trees.length + " trees in this area");

var newlogs = [];
for (var currenttree = 0; currenttree < trees.length; currenttree++){
	var oldlogs = jGetObjects(50, jCoord(0, 0), "log");
	var newlogs = [];
	var logs = [];
	goNearPosition(trees[currenttree].position(), 1);
	cutthistree(trees[currenttree]);
	stumper();
	
	// Now for the logs...
	
	var logs = jGetObjects(50, jCoord(0, 0), "log");
	for (var q = 0; q < logs.length; q++){
		
		var breaker = false;
	
		if (logs[q].position().dist(dropCoord) < 11) {
			var breaker = true;
		}// Checks logs against dropCoord
		
		if (!breaker){
			for (var k = 0; k < oldlogs.length; k++){
				if(logs[q].getID() == oldlogs[k].getID()) { // Checks against all logs that were there previously. This may be commented if desired
					var breaker = true;
					break;
				}			
			}
		}
		
		if (!breaker) {
			newlogs.push(logs[q]);
		}
	}
	// Now he moves the logs
	
	for (var currentlog = 0; currentlog < newlogs.length; currentlog++){
		goNearPosition(newlogs[currentlog].position(), 0);
		takethislog(newlogs[currentlog]);
		
		goNearPosition(dropCoord, 0);
		droplog();
	}
	
	
}

}

main();
except sometimes it gets stuck if log gets inside another tree. And sometimes it also starts pathfinding itself to random directions.
Image
I'm not sure that I have a strong argument against sketch colors - Jorb, November 2019
http://i.imgur.com/CRrirds.png?1
Join the moderated unofficial discord for the game! https://discord.gg/2TAbGj2
Purus Pasta, The Best Client

Return to “The Wizards' Tower”