Scrifen -- Hafen scripting API

Forum for alternative clients, mods & discussions on the same.
Thedrah
Posts: 943
Joined: Fri Apr 08, 2011 2:20 am
Location: behind you

Re: Scrifen -- Hafen scripting API

Post by Thedrah »

am i the only one having trouble with the method/function "onFlowerMenuOpen(options)"? i am trying to get it to work with "return options[0];" which doesn't do anything

i know it's being called as i have some print out in the command line but nothing is happening in game. even have the character wait 5+seconds before using return ._.

windows 7 64bit, 4gb, i3 cpu
  ▲
▲ ▲
algorithm
Posts: 218
Joined: Thu Aug 13, 2015 2:17 pm

Re: Scrifen -- Hafen scripting API

Post by algorithm »

Thedrah wrote:am i the only one having trouble with the method/function "onFlowerMenuOpen(options)"? i am trying to get it to work with "return options[0];" which doesn't do anything

i know it's being called as i have some print out in the command line but nothing is happening in game. even have the character wait 5+seconds before using return ._.

windows 7 64bit, 4gb, i3 cpu
After few changes in onFlowerMenuOpen(options) you should call g.chooseFlowerMenuOption(option) instead of returning value.
algorithm wrote:Cape awarded? ;)
jorb wrote:Oh, for sure. Delivery 2022. ;)
User avatar
b0r3d0m
Posts: 95
Joined: Sun Sep 13, 2015 2:39 pm

Re: Scrifen -- Hafen scripting API

Post by b0r3d0m »

Thedrah wrote:am i the only one having trouble with the method/function "onFlowerMenuOpen(options)"? i am trying to get it to work with "return options[0];" which doesn't do anything

i know it's being called as i have some print out in the command line but nothing is happening in game. even have the character wait 5+seconds before using return ._.

windows 7 64bit, 4gb, i3 cpu
Yep, what algorithm said.

If it doesn't help you for some reason, feel free to post here your code so I can help you.
Thedrah
Posts: 943
Joined: Fri Apr 08, 2011 2:20 am
Location: behind you

Re: Scrifen -- Hafen scripting API

Post by Thedrah »

it worked, thanks guys

now to figure out how to make the guy pick the closest tree to chop
  ▲
▲ ▲
User avatar
b0r3d0m
Posts: 95
Joined: Sun Sep 13, 2015 2:39 pm

Re: Scrifen -- Hafen scripting API

Post by b0r3d0m »

Thedrah wrote:it worked, thanks guys

now to figure out how to make the guy pick the closest tree to chop
You can use combination of getPlayerCoords and getAllMapObjects functions like this:

Code: Select all

function getDistance(lhs, rhs) {
  var dx = lhs.x - rhs.x;
  var dy = lhs.y - rhs.y;
  return Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
}

function getNearestMapObject() {
  var nearestMapObject = null;

  var playerCoords = g.getPlayerCoords();
  
  var nearestMapObjectDistance = null;
  var mapObjects = g.getAllMapObjects();
  for (var i = 0; i < mapObjects.length; ++i) {
    var mapObject = mapObjects[i];

    if (mapObject.name == 'body') {
      continue;
    }

    // TODO: Determine whether it is a tree

    var distance = getDistance(playerCoords, mapObject.coords);
    if (nearestMapObject == null || distance < nearestMapObjectDistance) {
      nearestMapObject = mapObject;
      nearestMapObjectDistance = distance;
    }
  }

  return nearestMapObject;
}
foomanchu
Posts: 121
Joined: Wed Jun 29, 2011 6:13 am

Re: Scrifen -- Hafen scripting API

Post by foomanchu »

any chance you can make it so theres a menu option (like amber's extensions) that has icons for multiple scripts? (similar to old haven clients that had scripting functionality)

not a particular fan of having only 1 script that runs when the client opens.. in legacy i must have had a few dozen scripts at least
but otherwise, great work.. i tried it out last night and its nice.. but its still missing some features for user qol.. start/stop script.. multiscript functionality.. and some api (that probably will get added in eventually).. but otherwise, good work!
User avatar
b0r3d0m
Posts: 95
Joined: Sun Sep 13, 2015 2:39 pm

Re: Scrifen -- Hafen scripting API

Post by b0r3d0m »

foomanchu wrote:any chance you can make it so theres a menu option (like amber's extensions) that has icons for multiple scripts? (similar to old haven clients that had scripting functionality)

not a particular fan of having only 1 script that runs when the client opens.. in legacy i must have had a few dozen scripts at least
but otherwise, great work.. i tried it out last night and its nice.. but its still missing some features for user qol.. start/stop script.. multiscript functionality.. and some api (that probably will get added in eventually).. but otherwise, good work!
You can load additional script files via `eval` function and you can use the `onUserInput` API event to launch different actions. I know that it doesn't what you actually want (there's no GUI-related stuff right now) but at least i works :)
User avatar
dzielny_wojownik
Posts: 703
Joined: Thu Oct 02, 2014 10:38 am
Location: Trapped in the autism cage with William

Re: Scrifen -- Hafen scripting API

Post by dzielny_wojownik »

great job, would love GUI also.
is there any way to find out if the autowalker/pathfinder is stuck on water or whatever, because it does get stuck when it tries to pathfind on water.
or on any other random stops

btw, it shows that chat message functions are not defined for me when I'm trying to use them :? and yes, I have the newest client available from the post
sendVillageChatMessage('test');
There was a wise soviet conscript that was surrounded by the enemy on the battle of Stalingrad. A mortar shot teared his pants apart causing a big hole in his pants right on his right butt cheek. He felt a glorious cold ass breeze of wind on his butt cheek, like it would be sent by stalin himself, he said - hide your butts
Thedrah
Posts: 943
Joined: Fri Apr 08, 2011 2:20 am
Location: behind you

Re: Scrifen -- Hafen scripting API

Post by Thedrah »

dzielny_wojownik wrote: btw, it shows that chat message functions are not defined for me when I'm trying to use them :? and yes, I have the newest client available from the post
sendVillageChatMessage('test');
are you using "g.sendVillageChatMessage('test');"? i noticed a lot of functions don't work without the 'g.' part hehe
  ▲
▲ ▲
User avatar
lacucaracha
Posts: 171
Joined: Thu Dec 05, 2013 4:50 pm

Re: Scrifen -- Hafen scripting API

Post by lacucaracha »

Your client is great, keep up the good work!
Just one thing, it would be way better if we could create several scripts and load/stop them ingame, like union client used to be!
Thanks!

Return to “The Wizards' Tower”