Scrifen -- Hafen scripting API

Forum for alternative clients, mods & discussions on the same.
User avatar
lacucaracha
Posts: 171
Joined: Thu Dec 05, 2013 4:50 pm

Re: Scrifen -- Hafen scripting API

Post by lacucaracha »

Is there a way to select an area, like in claims, paving and etc?
Also, is there any function that gives me the type of terrain i'm standing/is next to me?

@edit

I also miss a function to put a item from your hand on the inventory, and another one to pick dropped itens from the ground. Ty!
Thedrah
Posts: 943
Joined: Fri Apr 08, 2011 2:20 am
Location: behind you

Re: Scrifen -- Hafen scripting API

Post by Thedrah »

you can use the g.mapobjectarightclick(object.id); for picking up the item

found out when carrots growing use the same name as the dropped carrots
  ▲
▲ ▲
User avatar
lacucaracha
Posts: 171
Joined: Thu Dec 05, 2013 4:50 pm

Re: Scrifen -- Hafen scripting API

Post by lacucaracha »

Thedrah wrote:you can use the g.mapobjectarightclick(object.id); for picking up the item

found out when carrots growing use the same name as the dropped carrots
Cool! Thanks!
Thedrah
Posts: 943
Joined: Fri Apr 08, 2011 2:20 am
Location: behind you

Re: Scrifen -- Hafen scripting API

Post by Thedrah »

warning to people making a carrot harvesting script: the create stockpile function will plant the carrot if it's over plowed land
  ▲
▲ ▲
User avatar
b0r3d0m
Posts: 95
Joined: Sun Sep 13, 2015 2:39 pm

Re: Scrifen -- Hafen scripting API

Post by b0r3d0m »

Update is available.

Added new API methods:
  • useItemFromHandOnCoords(x, y)
  • dropItemFromHandToWindow(windowName)
  • takeItemFromWindow(windowName, itemName)
  • feastEat(itemName)
  • openTable(id)
See documentation for more info.
User avatar
b0r3d0m
Posts: 95
Joined: Sun Sep 13, 2015 2:39 pm

Re: Scrifen -- Hafen scripting API

Post by b0r3d0m »

Thedrah wrote:is there a way to have the script use 'feast' at a table?
See the previous post.

You can write code like this now:

Code: Select all

var thrones = g.getMapObjects('cottagethrone');
if (thrones != null && thrones.length > 0) {
  var throne = thrones[0];
  g.mapObjectRightClick(throne.id);
  sleep(3000);

  var tables = g.getMapObjects('cottagetable');
  if (tables != null && tables.length > 0) {
    var table = tables[0];
    g.openTable(table.id);
    sleep(3000);

    g.feastEat('blueberry');
  }
}
Thedrah wrote:edit: a way to get the stats of an animal? with name of stat with the number?
Not at the moment.
Thedrah wrote:possible for a simple left click on a tile would solve most cases :P
Ok, I'll add the corresponding function.
Thedrah wrote:can't use highlighted objects due to error

Code: Select all

java.lang.ClassCastException: org.mozilla.javascript.UniqueTag cannot be cast to org.mozilla.javascript.Function
	at haven.Evaluator.call(Evaluator.java:139)
	at haven.ChatUI$MultiChat.lambda$uimsg$0(ChatUI.java:805)
	at haven.Evaluator.lambda$new$0(Evaluator.java:39)
	at java.lang.Thread.run(Unknown Source)
It seems that you don't have `onMapObjectHighlight` function in your script.

Define it like this:

Code: Select all

/** It is fired when a new object highlighted via ALT + LMB
 * @param {Object} obj Highlighted map object
 * @param {String} obj.name Basename of the map object's resource
 * @param {String} obj.fullName Full name of the map object's resource
 * @param {Number} obj.id Map object's ID
 * @param {Object} obj.coords Coordinates of the map object
 * @param {Number} obj.coords.x x coordinate of the map object
 * @param {Number} obj.coords.y y coordinate of the map object
 */
function onMapObjectHighlight(obj) {
  // ignored
}
Thedrah wrote:is there a way to get an array of items in study?
Not at the moment, I'll add it.
Thedrah wrote:and any way to get the quality of an item?
I'm thinking about it from time to time. The problem is WItems / GItems have any ID related to them.
User avatar
b0r3d0m
Posts: 95
Joined: Sun Sep 13, 2015 2:39 pm

Re: Scrifen -- Hafen scripting API

Post by b0r3d0m »

lacucaracha wrote:Is there a way to select an area, like in claims, paving and etc?
Also, is there any function that gives me the type of terrain i'm standing/is next to me?
Not at the moment, will think about adding them.
lacucaracha wrote:I also miss a function to put a item from your hand on the inventory
You can use `dropItemFromHandToWindow` function from the last update.
Thedrah
Posts: 943
Joined: Fri Apr 08, 2011 2:20 am
Location: behind you

Re: Scrifen -- Hafen scripting API

Post by Thedrah »

you're amazing. currently attempting to add a script to automate walking around my base then to initiate other scripts/functions to make actions happen. then i can consider it a bot :twisted:
i got a carrot and barley harvesting script, now to add planting. then other plants and possibly work orders. the onMapObjectSelect function makes things go much smoother/quicker. with the animal stats i can make a true farmhand. if we can get stats of an item from inventory/window i'll be able to do automated farming with inspecting

only things holding me up are; i can't seem to carry a barrel through mineholes/ladders or travel along a milestone using g.mapObjectRightClick(id). i have to use buckets atm, which i guess is just an efficiency problem.
and entering buildings seems to escape me, is there a certain name i'm missing? trying to enter a stonetower by g.mapObjectRightClick(g.getMapObjects('stonetower')[0].id); which gets a proper id but it appears not to be selecting the door

convenience features would be to have a way to get liters from a foodtrough. that way i could log consumption of animals
the coordinates seem to not be static so i've started to rely on objects as land markers, would it be possible to get either the res of a tile or what is on a display sign? such as to allow for a script to fill an area paved of schist with wood blocks

another feature i could think of would be to repair stuff such as walls, looms, or plows. maybe a function such as getObjectHealth
for a mining script i think i need a function for ondustfall(x, y) unless i plan on throwing tons of metal at it. and maybe res tiles of walls
after that a scout script would need to be able to determine res tiles on the ground to be able to traverse rivers imo.

any chance of getting combat functions? such as a current list of combat cards and ability to activate one. i should really read into how to compile a custom client haha just seems like a cluster fuck to get started

edit: i want to use a cart but i can only pull the cart with the script. could we get the parts of the object, maybe in array form? or something more simple? could possibly allow for a more efficient script for changing hides, knowing if leather is done by the water, and possibly entering houses. might allow for knowing if a cupboard has stuff in it or a table have symbel on it

edit 2: trying to make a script to grind barley flour, i can't seem to be able figure out how to get barley seed from a barrel or equip a bucket of seed from hand or a container. can't equip an item from hand or container. i can't seem to open a chest next to a quern either :x
still can make a grinding script but requires no barley seed in barrel/bucket
  ▲
▲ ▲
User avatar
b0r3d0m
Posts: 95
Joined: Sun Sep 13, 2015 2:39 pm

Re: Scrifen -- Hafen scripting API

Post by b0r3d0m »

Update is available.

The long-awaited "disable rendering" feature finally implemented.

You should define new `onClientStarted` API hook in the following manner:

Code: Select all

/**
 * It is fired when the client started
 * @return {Object} options - Object that contains general options for the client
 * @return {Boolean} options.renderingEnabled - Set this option to `false` if you want to disable rendering
 */
function onClientStarted() {
  var options = {
    renderingEnabled: true
  };
  return options;
}
Note that you have to define it even if you don't want to disable rendering.
User avatar
lacucaracha
Posts: 171
Joined: Thu Dec 05, 2013 4:50 pm

Re: Scrifen -- Hafen scripting API

Post by lacucaracha »

Suggestion:
getInventorySize();
(maybe)
getInventoryEmptySlots();

Return to “The Wizards' Tower”