Galv's Jump Ability issue

I am using Galv's Jump Ability plugin and I faced an issue. It is cool and all adjusting your jump reach if there is a non-walkable tile in front of you or an event that blocks your path. However, if the tile is the same priority as you and there is an event with below priority that will usually let you walk on top it will still not let you jump on it which tells me that the plugin does not consider such events at all. For example I am able to jump from this bridge to the near shore but not the other way around since the bridge is a placeholder event that appears when you push a rock in the water.
I read the plugin and found out that you should add the additional condition somewhere around here but my understanding for JS is really abysmal at this point and I do not know what I need to do:

upload_2018-7-8_2-49-18.png


Code:
Galv.JA.jumpMax = function(dir,dis) {
    var m = {x: 0, y:0};
    var x = $gamePlayer.x
    var y = $gamePlayer.y

    switch (dir) {
        case 2:
            m.y = dis;
            for (var i = 0;i < dis;i++) {if (Galv.JA.checkBlock(x, y + i + 1)) m.y = i;};
            break;
        case 4:
            m.x = dis;
            for (var i = 0;i < dis;i++) {if (Galv.JA.checkBlock(x - i - 1, y)) m.x = i;};
            break;
        case 6:
            m.x = dis;
            for (var i = 0;i < dis;i++) {if (Galv.JA.checkBlock(x + i + 1, y)) m.x = i;};
            break;
        case 8:
            m.y = dis;
            for (var i = 0;i < dis;i++) {if (Galv.JA.checkBlock(x, y - i - 1)) m.y = i;};
            break;
    };
    return m;
};


Galv.JA.checkBlock = function(x,y) {
    return Galv.JA.regions.contains($gameMap.regionId(x,y)) || Galv.JA.stopperEvent(x,y);
};


Galv.JA.stopperEvent = function(x,y) {
    var block = false;
    var events = $gameMap.eventsXy(x,y);
  
    for (var i = 0;i <= events.length;i++) {
        if (events) {
            if (events.page().list[0].code === 108 && events.page().list[0].parameters[0] === "<blockJump>") {
                block = true;
                break;
            };
        };
    };
    return block;
};

Galv.JA.canJump = function(x,y,d) {
    return $gameMap.isPassable(x,y,d) && !Galv.JA.eventThere(x,y);
};

Galv.JA.eventThere = function(x,y) {
    var events = $gameMap.eventsXyNt(x,y);
    if (events.length > 0) return true;
    return false;
};
[Edit: I did make a mistake here, but doesn't matter now. See follow-up post below.]

Looking at the code, I think you'd just need to change one line, in the Galv.JA.eventThere function:
Code:
    if (events.length > 0) return true;
Try replacing that line with this:
Code:
    if (events.length > 0 && !events.some(function(ev) { return ev.isNormalPriority(); })) return true;
If I've got it right, the replacement says "if there's at least one event here and none of them are of Same as Characters priority, then there's an event blocking this tile". I.e. same-as-characters events should still block jumps, but above-/below-player ones shouldn't. ^_^
Hmm, Will not that make me able to jump over a tile with Same priority that has an event with Above priority over it?
But it did not work anyway. Still not being able to jump there.

Edit:
I tried to think of the issue and I found that you may included a ! in your line that should not be there.
if (events.length > 0 && !events.some(function(ev) { return ev.isNormalPriority(); })) return true;
Logically speaking it was making so that if there is no event with Same priority it should return true. But the eventThere should check if there is an event that prevents jumping not the other way around. I dropped the ! to make it so that it check if there is an event which is Same priority. I am not sure what I did is correct but it still worked.
However, the issue that I forecasted is that I can now jump on same priority tiles with Above priority events over them. Should we include a row to handle that?

Additional thoughts:
What I understand here is that the program will allow you to jump on all tiles unless two conditions are true at the same time - The tile should be passable and there should NOT be an event there. The tile passability is straightforward I guess and it is not defined but eventThere was. The definition before you was if there is any event. However, you added the check if the event is the same prioriry (well, after my edit).
So now I will either need to make the program think that Below priority events are not there (pun intended) or to think of Above priority events as events that are there. I prefer the first option and I tried a lot of configurations (since I do not now how the program defines this kind of priority but it did not work:
!events.some(function(ev) { return ev.isLowPriority(); })
!events.some(function(ev) { return ev.isLowerPriority(); })
!events.some(function(ev) { return ev.isLowestPriority(); })
>=events.some(function(ev) { return ev.isNormalPriority(); }) (this one disabled the jump as a whole)
Although when I think of it this kind of check may allow a tile with more than 1 event that has at least 1 below priority event on it to be considered okay to jump on.
So maybe it will be best to make the overall check:
If(the tile is passable AND there are no same priority events there) OR (the tile is not passable AND there is at least one below priority event there AND no events are same priority)
I DID IT!
At least it seems so. I added this new nonBlock thingy. However, I am not sure I handled the OR in canJump field. I just put the second set of conditions on a new row.
It seems to work very well for now in the one situation I checked. Please check my solution and see if you think there will be issues with it. I will continue testing it more thorough.

Code:
Galv.JA.canJump = function(x,y,d) {
    return $gameMap.isPassable(x,y,d) && !Galv.JA.eventThere(x,y);
    !$gameMap.isPassable(x,y,d) && Galv.JA.nonBlock(x,y);
};

Galv.JA.eventThere = function(x,y) {
    var events = $gameMap.eventsXyNt(x,y);
    if (events.length > 0 && events.some(function(ev) { return ev.isNormalPriority(); })) return true;
    return false;
};

Galv.JA.nonBlock = function(x,y) {
    var events = $gameMap.eventsXyNt(x,y);
    if (events.length > 0 && !events.some(function(ev) { return ev.isNormalPriority(); }) && events.some(function(ev) { return ev.isPriorityType(0); })) return true;
    return false;
};
OK I had a proper look and it looks like the plugin is currently at version 1.6; this "can't jump onto lower events" thing was a bug fixed in 1.4. 😅

I tested with the latest version and jumping onto passable events seems to work. Here's the link~: https://galvs-scripts.com/2015/11/13/mv-jump-ability/
That is good but what about my solution? I am asking just for the sake of it being mine. A friend of mine told me that || is the sign for OR in JS so I guess the first check should be:... Is that right?
Code:
Galv.JA.canJump = function(x,y,d) {
    return ($gameMap.isPassable(x,y,d) && !Galv.JA.eventThere(x,y);) || (!$gameMap.isPassable(x,y,d) && Galv.JA.nonBlock(x,y);)
};

And also, the latest version has some other issues. I am now able to jump on "roof" tiles. For example I was able to go here with a jump. I can handle that with the regions that will disallow you to jump on these but I will actually need to be able to jump on these if you already climbed up for a few of the puzzles.

Maybe if I can dynamically can make a region block or not block jumping it will be okay. Do you think I will be able to do that in the plugin?

upload_2018-7-8_21-43-21.png
Yes, you're correct, I had a ! in the wrong place. 😴

For educational purposes: your nonBlock function is harmless but unnecessary because the code will never run it. This is because functions end at return statements and semicolons mark the end of lines in JavaScript: your addition to the canJump function is its own line that never gets run. Whoops!

Not sure about Galv's plugin, but I know Yanfly's Smart Jump can handle this with regions. It works much the same as Galv's in all other respects, too. Link if you're interested~: http://yanfly.moe/2016/02/07/yep-68-smart-jump/
#Deleted because the author is stupid.

From the author
Yanfly's plugin works via a Plugin Command: SmartJump <distance>, i.e. SmartJump 2 makes you jump 2 tiles forward. ^_^

One downside is that I don't think it offers an automatic "bind to key" feature like Galv's. You'll have to either use a parallel event or another plugin for that (e.g. Yanfly's Button Common Events).

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/galvs-jump-ability-issue.97414/