Scrifen -- Hafen scripting API

Forum for alternative clients, mods & discussions on the same.
hery76
Posts: 176
Joined: Mon Feb 06, 2012 1:15 pm

Re: Scrifen -- Hafen scripting API

Post by hery76 »

oh right, for some reason (stupid one i bet) i totally forgot to put script.js in the directory.

My bad, mistery solved :P

Thanks b0r3d0m o/
clefa221
Posts: 63
Joined: Sat Feb 01, 2014 4:47 pm

Re: Scrifen -- Hafen scripting API

Post by clefa221 »

How would I go about making a script the foraged some forgables but not others? What commands would I use?

EDIT: For example, lets say that I want to make a script that forages all blueberries, curios, nettles, and chantrelles, how would I go about doing that?
User avatar
Granger
Posts: 9255
Joined: Mon Mar 22, 2010 2:00 pm

Re: Scrifen -- Hafen scripting API

Post by Granger »

You would loop over the stuff you see and test each if it is in the list of stuff you want to foreage, if so get it, if not ignore it.

You most likely need array().contains() - or indexOf(), should you need to cook one yourself - for and if.
⁎ Mon Mar 22, 2010 ✝ Thu Jan 23, 2020
UzU123
Posts: 20
Joined: Mon Dec 31, 2012 7:00 pm

Re: Scrifen -- Hafen scripting API

Post by UzU123 »

Hello, I'd like to write by myself bot which would harvest for me peppercorn from trellis but it doesn't work. I think I did something wrong. Could you help me, please?

Code: Select all

var g = null;
var autoWalkingTimerId = null;

function onClientStarted() {
  var options = {
    renderingEnabled: true
  };
  return options;
}

function onLogin() {
  print('Logging in...');

  var credentials = {
    login: 'x',
    password: 'x'
  };
  return credentials;
}

function onCharSelect() {
  print('Selecting character...');

  return 'x';
}

function onGameLoaded(game) {
  print('Game loaded');

  g = game;
  for (i = 0; i < 48; i++){
	lc()
	sleep(500);
	pieprz(i);
	sleep(500);
  }
}

function pieprz(rid){
	var kolba = g.getMapObjects('trellis');
	g.mapObjectRightClick(kolba[rid].id);
	g.chooseFlowerMenuOption(Harvest);
	g.waitForPf();
	g.waitForTaskToFinish();
}

function lc(){
	var skrzynia = g.getMapObjects('largechest');
	g.mapObjectRightClick(skrzynia[0].id);
	g.waitForPf();
	g.transferItems('peppercorn');
	g.waitForTaskToFinish();
	sleep(500);
}

function picie(){
	if (g.getStamina() < 50){
		print('Brak staminy');
		g.drink();
	}
}
Translation:
skrzynia-chest-LC
pieprz-pepper
picie-drinking
User avatar
Granger
Posts: 9255
Joined: Mon Mar 22, 2010 2:00 pm

Re: Scrifen -- Hafen scripting API

Post by Granger »

UzU123 wrote:
g.chooseFlowerMenuOption(Harvest);
This line seems to be defective.
⁎ Mon Mar 22, 2010 ✝ Thu Jan 23, 2020
UzU123
Posts: 20
Joined: Mon Dec 31, 2012 7:00 pm

Re: Scrifen -- Hafen scripting API

Post by UzU123 »

Granger wrote:
UzU123 wrote:
g.chooseFlowerMenuOption(Harvest);
This line seems to be defective.
I think you mean that I forgot to write like this ('Harvest') with "" but I added it and still it doesn't work. Bot opens LC, puts harvested (by me manually) pepper, tries to go to trellis but after it reaches one of many trellises stops and comes back to LC, opens it and etc.

Also tried to change 'peppercorn' to other names but still nothing.
User avatar
Granger
Posts: 9255
Joined: Mon Mar 22, 2010 2:00 pm

Re: Scrifen -- Hafen scripting API

Post by Granger »

Maybe you should target the plant, not the trellis.
⁎ Mon Mar 22, 2010 ✝ Thu Jan 23, 2020
UzU123
Posts: 20
Joined: Mon Dec 31, 2012 7:00 pm

Re: Scrifen -- Hafen scripting API

Post by UzU123 »

Granger wrote:Maybe you should target the plant, not the trellis.
Tried it also. I changed "trellis" to "pepper" and still nothing.

Should I use something like this? Or it won't work?

Code: Select all

var stojak = g.getMapObjectsByFullName('gfx/terobjs/plants/pepper');
Glorthan
Posts: 1099
Joined: Tue Jun 11, 2013 4:33 pm

Re: Scrifen -- Hafen scripting API

Post by Glorthan »

UzU123 wrote:
Granger wrote:Maybe you should target the plant, not the trellis.
Tried it also. I changed "trellis" to "pepper" and still nothing.

Should I use something like this? Or it won't work?

Code: Select all

var stojak = g.getMapObjectsByFullName('gfx/terobjs/plants/pepper');
You should use that so it doesn't get confused with pepper on the floor. You should also check if the pepper is harvestable (correct stage). I can't help you test this ingame at the moment, sorry.
UzU123
Posts: 20
Joined: Mon Dec 31, 2012 7:00 pm

Re: Scrifen -- Hafen scripting API

Post by UzU123 »

Ok, so now it looks like this:

Code: Select all

var g = null;
var autoWalkingTimerId = null;

function onClientStarted() {
  var options = {
    renderingEnabled: true
  };
  return options;
}

function onLogin() {
  print('Logging in...');

  var credentials = {
    login: 'x',
    password: 'x'
  };
  return credentials;
}

function onCharSelect() {
  print('Selecting character...');

  return 'x';
}

function onGameLoaded(game) {
  print('Game loaded');

  g = game;
  for (i = 0; i < 48; i++){
	lc()
	sleep(500);
	pieprz(i);
	sleep(500);
  }
}

function pieprz(rid){
	var kolba = g.getMapObjectsByFullName('gfx/terobjs/plants/pepper');
	g.mapObjectRightClick(kolba[rid].id);
	g.chooseFlowerMenuOption('Harvest');
	g.waitForPf();
	g.waitForTaskToFinish();
}

function lc(){
	var skrzynia = g.getMapObjects('largechest');
	g.mapObjectRightClick(skrzynia[0].id);
	g.waitForPf();
	g.transferItems('peppercorn');
	g.waitForTaskToFinish();
	sleep(500);
}

function picie(){
	if (g.getStamina() < 50){
		print('Brak staminy');
		g.drink();
	}
}
After logging in it opens LC and closes it and it does it again again and again. Script skips harvesting from trellis. Any ideas?

Return to “The Wizards' Tower”