Union Client Scripts
Moderator: Phades
-
Arcanist
- Posts: 2664
- Joined: Mon Mar 19, 2012 2:01 pm
Re: Union Client Scripts
Well then, do you know of any workaround for the issue?
-
APXEOLOG
- Posts: 1300
- Joined: Fri Apr 23, 2010 7:58 am
- Location: Somewhere on Earth
Re: Union Client Scripts
Check https://github.com/APXEOLOG/hnh_union/b ... d.java#L42 function. I bet i've used it somewhere in the code. (Maybe not from bot, so you may need to add it to the client bot api).Arcanist wrote:Well then, do you know of any workaround for the issue?
W10 Meme Plot | W9 Mantis Garden | W8 Core | W7 Ofir | W6 the City of Dis | W5 Vitterstad | W4 A.D. | W3 Mirniy
jorb wrote:All your characters will be deleted, and I will level every village any one of them were ever members of.
-
Ocerion
- Posts: 113
- Joined: Tue Feb 08, 2011 6:53 am
Re: Union Client Scripts
Best I can tell my issue comes from the part where it says to get the meter in the coop, it just stops there and never continues, unlike the one for the troughs, where it detects how full the troughs are. Pretty sure it has to be that part because when I remove the meter reference, it works, although obviously then it doesn't stop when its full because how the hell would it know, it can't read the meter. Lol.
-
Arcanist
- Posts: 2664
- Joined: Mon Mar 19, 2012 2:01 pm
Re: Union Client Scripts
It probably calls for object 0 from getMeterValue
You might like to try changing it to object 1.
Also, change the window title
You might like to try changing it to object 1.
Also, change the window title
-
Ocerion
- Posts: 113
- Joined: Tue Feb 08, 2011 6:53 am
Re: Union Client Scripts
What I have currently is as follows:
function getCoopMeter(tr) {
jDoClick(tr.getID(), 3, 0);
while (!jHaveWindow("Coop"))
jSleep(500);
var meter = jGetWindow("Coop").getMeterValue(1);
return meter;
}
So, its already 1...and the window is right. Just doesn't work.
function getCoopMeter(tr) {
jDoClick(tr.getID(), 3, 0);
while (!jHaveWindow("Coop"))
jSleep(500);
var meter = jGetWindow("Coop").getMeterValue(1);
return meter;
}
So, its already 1...and the window is right. Just doesn't work.
-
Arcanist
- Posts: 2664
- Joined: Mon Mar 19, 2012 2:01 pm
Re: Union Client Scripts
This is an exert from a script posted by talon.
Code: Select all
var obj = GetCoop(15, jCoord(-2, 0));
jPrint("obj="+obj);
var wnd = GetWindow("Chicken Coop");
jPrint("wnd = "+wnd);
jPrint("invCount = "+wnd.getInventories().length);
var objInv = wnd.getInventories()[0];
jPrint("objInv = "+objInv);
jPrint("chickens = "+objInv.getItems("gfx/invobjs/chicken").length);
jPrint("cocks = "+objInv.getItems("gfx/invobjs/cock").length);
jPrint("chicks = "+objInv.getItems("gfx/invobjs/chick").length);
jPrint("eggs = "+objInv.getItems("gfx/invobjs/egg-chicken").length);
var eggs = objInv.getItems("gfx/invobjs/egg-chicken");
jPrint("value0 = "+wnd.getMeterValue(0));
jPrint("value1 = "+wnd.getMeterValue(1));
-
SamaR
- Posts: 65
- Joined: Thu Sep 23, 2010 6:18 pm
Re: Union Client Scripts
Hey
I have been trying to understand how these scripts work, because I can't run more advanced ones. Only things like drink water or run starver work for me, others end immediately with "script finished". So I made a couple of javascript lessons, about basics: functions, variables, and things I have seen are in these scripts. But the Haven and hearth ones are different than what I have learned. How can I make something work? where can I learn to write and edit in union script language? As far I have made something like this: using farmer.jbot, because the original file doesn't work so I wanted to make easier one, but this one doesn't seem to work neither... it just says "script finished" and the character doesn't even move. I would be grateful for any info and help
Thanks in advance.
I have been trying to understand how these scripts work, because I can't run more advanced ones. Only things like drink water or run starver work for me, others end immediately with "script finished". So I made a couple of javascript lessons, about basics: functions, variables, and things I have seen are in these scripts. But the Haven and hearth ones are different than what I have learned. How can I make something work? where can I learn to write and edit in union script language? As far I have made something like this:
Code: Select all
//#! name = Carrotsesfarmereses
//#! uniq = Usernm_Farmer
//#! icon = gfx/invobjs/carrot
include("Usernm_lib");
var direction = jMyCoords(1,0);
var inventory = checkInventory();
var field_line_size = 6;
var seed_name = "carrot";
var crop_name = "plants/carrot";
var crop_stage = 4;
function stepOnce(directon){
var next_tile = jMyCoords().add(direction.mul(11));
jAbsClick(next_tile,1,0);
safeWaitMove(next_tile);
}
function harvestCrop(crop){
jSendAction("harvest");
jWaitCursor("harvest");
jDoClick(crop.getID(),1,0);
inventoryItemsCountChange();
resetCursor();
}
function plantOneLine(seed_name, field_line_size, direction){
var start_point = jMyCoords();
if (start_point !== jTilify(start_point)){
jAbsClick(jTilify(start_point),1,0);
safeWaitMove(jTilify(start_point));
}
var inventory = checkInventory();
var seeds = inventory.getItems(seed_name);
var seed_coord = jCoord(0,0);
sortItemsInInventory(seeds);
var next_tile = start_point.add(direction.mul(11));
var crop = jFindMapObjectNearAbs(start_point, 1, "plant");
var i = 0;
while (true){
var crop = jFindMapObjectNearAbs(start_point, 1, "plant");
if ((jGetTileType(jCoord(0,0) == 9))&&(crop == null)){
jToConsole(i+" "+seeds[i]);
seeds[i].take();
jWaitDrag();
jAbsInteractClick(start_point, 0);
while (crop == null){
jSleep(100);
crop = jFindMapObjectNearAbs(start_point, 1, "plant");
}
}
i++
if (jGetTileType(direction) !== 8){
jAbsClick(next_tile,1,0);
safeWaitMove(next_tile);
start_point = jMyCoords();
crop = jFindMapObjectNearAbs(start_point, 1, "plant");
next_tile = jMyCoords().add(direction.mul(11));
} else {
jToConsole("Field line end");
}
}
}
-
Arcanist
- Posts: 2664
- Joined: Mon Mar 19, 2012 2:01 pm
Re: Union Client Scripts
It refrences the file "Usernmlib"
You need that file to run it, and we'll need that file to bugcheck for you.
What error does it throw? (look in your console window)
As far as learning the jbot libraries, the documentation is available, and the best way is to look at other's scripts and change them, to start with.
If you want some help then you can PM me your skype ID.
You need that file to run it, and we'll need that file to bugcheck for you.
What error does it throw? (look in your console window)
As far as learning the jbot libraries, the documentation is available, and the best way is to look at other's scripts and change them, to start with.
If you want some help then you can PM me your skype ID.
-
SamaR
- Posts: 65
- Joined: Thu Sep 23, 2010 6:18 pm
Re: Union Client Scripts
So, here is the Usernm_lib :
And also a screen of what happens in console and game. Can it be created without using the usernm? just something that moves 1 grid forward, harvests and then plants 1 seed back. If inventory is full I don't really care, at start i want it to just pick up and plant 1 back. I will PM you, Arcanist about skype.
// the carrots I have in inventory are carrots I harvested by hand //
Code: Select all
// Возвращает JSInventory[]
function checkInventory() {
if(!jHaveWindow("Inventory")) {
jToggleInventory();
while(!jHaveWindow("Inventory")){
jSleep(100);
}
}
return jGetWindow("Inventory").getInventories()[0];
}
// Возвращает JSEquip
function checkEquipment() {
if(!jHaveWindow("Equipment")) {
jToggleEquipment();
while(!jHaveWindow("Equipment")){
jSleep(100);
}
}
return jGetJSEquip();
}
// Функция возвращает JSWindow указанного объекта, пытаясь подойти к нему и открыть его.
function checkObject(object_gob, window_name) {
if(!jHaveWindow(window_name)) {
jDoClick(object_gob.getID(), 3, 0);
while(!jHaveWindow(window_name)){
jSleep(100);
}
return jGetWindow(window_name);
}
else {
return jGetWindow(window_name);
}
}
// Немного поправленная первая половина функции drinkWater из jBotapi. Жесткая задержка в полсекунды заменена на интеллектуальную проверку наполненности фляги.
function fillFlask() {
var 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", "kuksa");
if (flasks.length > 0) {
var flask = flasks[0];
if (flask.isActual()) {
flask.itemact(0);
if (flask.name().indexOf("Kuksa") >=0) {
var full = "0.3/0.3"
}
if (flask.name().indexOf("Waterflask") >=0) {
var full = "2.0/2.0"
}
if (flask.name().indexOf("Waterskin") >=0) {
var full = "3.0/3.0"
}
while ((flask.name().indexOf(full) < 0)&&((jGetDraggingItem().resName() == "bucket-water"))){
jSleep(100);
}
}
}
inventory.drop(bucket_coord);
jWaitDrop();
}
}
}
// Немного поправленная вторая половина функции drinkWater из jBotapi. Вместо ожидания прогресса, проверка на стамину и пустоту фляги.
function drinkFlask(){
var inventory = checkInventory();
var flasks = inventory.getItems("waterflask", "waterskin", "kuksa");
if (flasks.length > 0) {
var flask = flasks[0];
if (flask.isActual()) {
flask.iact();
if (jWaitPopup()) {
jSelectContextMenu("Drink");
while ((jGetStamina() <95)&&(flask.name().indexOf("Empty")<0)){
jSleep(100);
}
}
}
}
}
// Функция для совместимости с ботами. Делает тоже самое что и до переработки.
function drinkWater(){
fillFlask();
drinkFlask();
}
// Восполняет стамину в цикле. Удобно использовать для куксы.
function restoreStamina(){
while (jGetStamina()<95){
fillFlask();
drinkFlask();
}
}
// Функция набирает флягу на воде и пьет ее.
function drinkWaterFromWater(){
checkInventory();
var tile = jGetTileType(jCoord(0, 0));
// 1 - мелководье, 0 - глубоководье
if ((tile == 1)||(tile == 0)){
var inventory = jGetWindow("Inventory").getInventories()[0]
var flasks = inventory.getItems("waterflask", "waterskin", "kuksa");
if (flasks.length > 0) {
var flask = flasks[0];
var flask_coord = flask.coord();
flask.take();
jWaitDrag();
jAbsInteractClick(jMyCoords(),3,0);
jSleep(500);
inventory.drop(flask_coord);
jWaitDrop();
drinkFlask();
}
}
}
// Функция ждет, пока не заполнятся все слоты инвентаря персонажа.
function WaitFullInventory() {
while (jGetWindow("Inventory").getInventories()[0].freeSlots() !== 0){
jSleep(100);
}
}
// Функция копает под персонажем.
function digHere(){
jSendAction("dig");
jWaitCursor("dig");
jAbsClick(jMyCoords(),1,0);
WaitFullInventory();
resetCursor();
jAbsClick(jMyCoords(),1,0);
}
// Ждет пока количество предметов в инвентаре не поменятеся.
function inventoryItemsCountChange() {
var inventory = jGetWindow("Inventory").getInventories()[0];
var now = inventory.freeSlots();
while (inventory.freeSlots() == now){
jSleep(100);
}
return true;
}
// Дефолтная функция сброса курсора из jBotapi
function resetCursor() {
if (!jIsCursor("arw")) {
jAbsClick(jCoord(0, 0), 3, 0);
jWaitCursor("arw");
}
}
// Функция загрузки материалов в табличку.
function loadIntoTable(material){
for (var i = 0; i < material.length; i++){
material[i].transfer();
}
}
// Функция безопасного перемещения в координаты.
function safeWaitMove(coord) {
while (!jMyCoords().equals(coord)){
jSleep(100);
}
var counter = 0;
while (jIsMoving()){
if (counter > 10){
break;
}
jSleep(100);
counter++;
}
}
// Функция пытается распахать тайл по координатам. Проверка распашки через тип тайла.
function handsPlow(coord){
jSendAction("plow");
jWaitCursor("dig");
jAbsClick(coord,1,0);
safeWaitMove(jTilify(coord));
while (jGetTileType(jCoord(0,0)) !== 9){
jSleep(100);
}
}
// Функция ищет ближайший тайл из массива подходящий для распашки и возвращает его абсолютные координаты, если пахать в радиусе нечего - завершает скрипт.
function findPlowableTile(radius){
var tiles_id=new Array(10,11,13,14,15);
var tile = new Array();
var distance = new Array();
for (var i = 0; i < tiles_id.length; i++){
try {
tile[i] = jGetNearestTileAbs(radius, tiles_id[i]);
distance[i] = tile[i].dist(jMyCoords());
// jToConsole("tile with id "+tiles_id[i]+" have coordinates = "+tile[i]);
// jToConsole("distance to tile with id "+tiles_id[i]+" = "+distance[i]);
}
catch(NullPointerException){
tile[i] = -1;
distance[i] = -1;
// jToConsole("tile with id "+tiles_id[i]+" not exist");
}
}
var max_distance = 5500;
for (var i = 0; i < tiles_id.length; i++){
if ((distance[i] >= 0) && (distance[i]<max_distance)){
max_distance = distance[i];
var result_tile = tile[i];
}
}
if (max_distance == 5500){
jToConsole("No plowable tiles in range");
jExit();
} else {
return result_tile;
}
}
// Функция находит направление (сторону света) где находится объект.
function getDirectionToObject(object){
var offset_x = object.position().x - jMyCoords().x;
var offset_y = object.position().y - jMyCoords().y;
if ((offset_y <= 0)&&(Math.abs(offset_y)>=Math.abs(offset_x))){
// jToConsole("object location on North");
return jCoord(0,-1);
}
if ((offset_y > 0)&&(Math.abs(offset_y)>Math.abs(offset_x))){
// jToConsole("object location on South");
return jCoord(0,1);
}
if ((offset_x <= 0)&&(Math.abs(offset_y)<=Math.abs(offset_x))){
// jToConsole("object location on West");
return jCoord(-1,0);
}
if ((offset_x > 0)&&(Math.abs(offset_y)<Math.abs(offset_x))){
// jToConsole("object location on East");
return jCoord(1,0);
}
}
// Функция находит ближайший объект в радиусе и возвращает его. Если таких объектов в радиусе нет - возвращает -1
function findNearestObject(object_name, radius){
var objects = jGetObjects(radius, (0,0), object_name);
var distance = new Array();
for (var i = 0; i < objects.length; i++){
distance[i] = objects[i].position().dist(jMyCoords());
}
var min_distance = 5500;
for (var i = 0; i < objects.length; i++){
if ((distance[i] >= 0) && (distance[i]<min_distance)){
min_distance = distance[i];
var nearest_object = objects[i];
}
}
if (min_distance == 5500){
jToConsole("No objects in range");
return -1;
}
return nearest_object;
}
function getPlayerDirection(){
var player = jFindMapObjectNearAbs(jMyCoords(), 1, "borka")
if (player.hasLayer("head-0")){
jToConsole("SE");
return jCoord(1,1);
}
if (player.hasLayer("head-1")){
jToConsole("S");
return jCoord(0,1);
}
if (player.hasLayer("head-2")){
jToConsole("SW");
return jCoord(-1,1);
}
if (player.hasLayer("head-3")){
jToConsole("W");
return jCoord(-1,0);
}
if (player.hasLayer("head-4")){
jToConsole("NW");
return jCoord(-1,-1);
}
if (player.hasLayer("head-5")){
jToConsole("N");
return jCoord(0,-1);
}
if (player.hasLayer("head-6")){
jToConsole("NE");
return jCoord(-1,0);
}
if (player.hasLayer("head-7")){
jToConsole("E");
return jCoord(0,1);
}
}
// the carrots I have in inventory are carrots I harvested by hand //
You do not have the required permissions to view the files attached to this post.
-
Arcanist
- Posts: 2664
- Joined: Mon Mar 19, 2012 2:01 pm