Help Replicating Field Skills: Move

For you JS Code.


Dont use "this" , the this keyword when used in Events refers to Game_Interpreter(A JS object that parse event commands and runs them), not the event it was called in! this is a very common very easy mistake to make. This is becuase Events dont run event code, the interpreter does.

console.log(this) //when in a script call
-> Game_Interpreter

Filter iterates through each element checking if the callback function returns true, if true the new Array will contain that element. where you have "value" is what will be considered the current event in that iteration.There is an optional second parameter that assigns the value of "this" inside the call back but we don't need it.

The second problem is you only cheking in one direction on one axis (X Axis). this means all events to the left of you are ignored and all events in front are regardless of their Y axis. calculate the distance like this d = Math.Sqr((x1 - x2)^2 + (Y1 - Y2)^2). if you suck at math fortuanley $gameMap has an inbult distance fucntion.


so your code should look like this
Code:
$gameVariables.movableEvents.filter( function(event) {
var d = $gameMap.distance($gamePlayer.x, event.x, $gamePlayer.y, event.y);
return d <= 3;
});
please note for somereason whenever i put code aross two lines it treats each line as a seperate instruction.not sure if this is true for you.

For grabbing the character ID ithink you could do it by checking charcter states. basically, add a state, call commomn event, common event checks for stat\. when finished remove state. done🙂 But if you don't need MP refunding you might aswell as leave it out since thats all i needed the actor for.
I had a simple (PlayerX - EventX) formula checked just because I wanted events triggered only in front of me, depending on where I'm looking. So there'd be other formulae in case of other directions. Won't the formula you provided work like an AoE skill? And if the return variable is an array, can I somehow sort it by distance? Just so I can grab the first (or zeroest, I dunno where arrays start in JS) object in the array and just dump all others?

And I think I'll just disregard the MP reduction from a certain character. After all, I'm not refunding it, so I can just assign that skill to a character I need and he'll use his own MP~~
Array.sort will help with sorting them. the event code i gave you lets you choose wicth event out of the array anyway.

Yes the formula would work like an Aoe as far as detecting movable events. detecting what infront of the player is a wee bit harder. first you need to check which direction that playeris facing. character directions are stored as an interger. 2 is up, 6 is right, 4 is left and 8 is down. (like your numpad). then filter (yet again) all movables outide the desired range. now the question is, can the player move all object in line with them, or all object infront of them with a 45,60,120 or even 180 degree angle?

if its in line you formula wouldnt work, becuase it also checks behind them. DeltaXfrom and DeltaY from are useful for this.

Code:
$gameVariables.movableEvents.filter(function(event){
var sx = $gamePlayer.deltaXFrom(event.x);
 var sy = $gamePlayer.deltaYFrom(event.y);
var dir = $gamePlayer.direction();
if(Math.abs(sx) > Math.abs(sy)) {return (sx > 0 ? dir == 6 : dir == 4);}
else if (sy !== 0) {return (sy > 0 ? dir == 2 : dir == 8); }
});

this is the same algorithm MV uses with "turn towards" except im returning booleans instead of setting direction.
I just don't know what to do anymore. It only moves the very first event it finds, no matter how and where I stand.
This is the example of code I wrote for when I'm facing right.
upload_2017-8-15_23-0-37.png

I tried writing it in a single line, no difference.

I think the reason of it not working could be in sorting, because I'm hella sure it's wrong. But then again - it can't even pick the correct events how I need it to.
for array.sort works by comaparing "a" and "b" in a way you define in the callback fucntion. a and b are elements from the array (in this case events). so subtracting one from another makes no sense. (its like subtracting a potato from another potato) im suprised you didnt get an error.
you sort function should comapre the two player Distances and pick the lowest one.

Code:
$gameVariables.movableEvents.sort(function(a,b)  {
var aDistance = $gameMap.distance($gamePlayer.x, a.x, $gamePlayer.y, a.y);
var bDistance = $gameMap.distance($gamePlayer.x, b.x, $gamePlayer.y,b.y);
return aDistance - bDistance;

});
Also you can do the sort function at the start just before that conditional branch. there no need to put it 4 times.


if you want the "closest" event and only the events in front. when facing right X is greater and Y is Equal. the code i gave you before (with (gameMapDetlaY in it)will give you a wide angle of around 45 degress. filtering out anything you arent facing directly is done like:

Code:
return event.x > $gamePlayer.x &&  event.y === $gamePlayer.y; //right
return event.x < $gamePlayer.x &&  event.y === $gamePlayer.y; //left
return event.x === $gamePlayer.x &&  event.y > $gamePlayer.y; //down,Y values start from the top going down
return event.x === $gamePlayer.x &&  event.y < $gamePlayer.y; //up,Y values start from the top going down

sorry for the other code, i wanst sure what you meant by in front.
It doesn't work. Ugh, it keeps activating the leftmost event no matter where I stand. After I activate the skill once, it actually moves the event that stands next to it! But third time and onwards - it goes back to the first one and moves only it. Nothing else.
Spoiler
The highlighted event is the one that keeps activating. Event next to it gets activated ONCE the next time I use the skill after moving the first event for whatever reason unbeknownst to me, and after I move it - the baton goes again to the first one and stays there.
Spoiler
upload_2017-8-16_18-9-26.png
Piece of your code. I said " it" and just copypasted it. I don't care about learning JS now, I just want this piece of to work :c
Spoiler
upload_2017-8-16_18-12-16.png
Console log. I have no idea what your AudioLag plugin counts up there so diligently, but apart from that - the skills record all 7 events, so at least the first part works nicely.
Spoiler
upload_2017-8-16_18-14-59.png
This is just to show how it works. I'm standing next to the upmost crystal and looking right, so it is the only one event that should be activated. But it won't activate. No matter how far I am, it's always that one with a different sprite that gets activated.
Spoiler
upload_2017-8-16_18-17-17.png
Do you, maybe, want my project? Just so you can test it yourself.
sens me the common event data & a blank map you want me to test it on, ill send it back working 🙂

the code i posted was for lines each for left right down and up.

AudioLag plugin is printing out values from HTML5 Fadeout,
sens me the common event data & a blank map you want me to test it on, ill send it back working 🙂

the code i posted was for lines each for left right down and up.

AudioLag plugin is printing out values from HTML5 Fadeout,
I'll send you the map with events that will explain what should and shouldn't happen with that skill. You're my only hope, dude.
here what i came up with based on these sources.


and this http://goldensun.wikia.com/wiki/Move

this is the CommonEvents JSON file i used to replicate those above. rename the .js extenstion to .json to use it. remeber to back up your common events.
Wow, I'm surprised someone tried to make Golden Sun 4. But yes, this is the skill I'm trying to replicate, albeit with a better range.
That thing crashed my laptop, haha. It works nicely at detecting events at a distance, but it still has problems with deciding which one to move, sadly.

Anyway, here are the files. My common events that we worked on before, yours that you sent me above and a map with puzzles and explanations on what this thing has to do.
I am infinitely thankful that you're spending your time helping me.
got it working 🙂
but in youre map 3rd and 4th test i havent done yet. RPGmaker MV doesnt know the difference between a body of water , a hole and wall. they are all marked with the same flag. so i can't tell the game what it supposed to do. there isnt a "height" in RPGmaker only a X and Y Axis, the Z access is kinda reserved for the ordering of sprites. You do mention i could use regions, problem with regions is tht you can only have one per tile, but in 90% of cases you dnt need more than one.



some of your puzzles aren't solvable with Move , (theyres a crystal that is further than 3 squares that needed moving, move is 3 squares max.) in your "test" grid it kinda looks like it can go up tp 4 spaces is its west, easy,north or south of the player is thias true

I did add a cursor, i foud that some moveable are tricky to spot so i added that in.

Also i quickly noticed how tedious it is to jump in and out of the menu 12000 times each puzzle.
They are all solvable , hehe. In the 4th puzzle you have to move other crystals to get to the one you can't reach and then move them onto all buttons. Trust me, it is solvable~~ :ywink:
About how the skill works in your video:
Spoiler
If that's your engine, then good job on making your own version of Move! As for my version, I am not sure why you can activate the statues in the corners right in the beginning of your video...
You should be able to activate only the statues that are standing in a straight line depending on where you look, so in the first map in your video that makes it that cobblestone road is where you can move events (depending on where you're looking) and grass patches - where you can't. Basically if you want to move an event - you have to be on the same X or Y axis as it is AND looking at the event.
The first puzzle works wonders. But it's just one crystal, so no problems appeared.
In the second puzzle that you solved, your only option that you can pick should be a crystal in front of you. And the other crystals that you moved will remain locked in their place, because there is no way you can move them thanks to walls. You can try moving them if you stand next to them and turn towards them, but since you're blocking the path - they will stay there.
Third puzzle is totally solvable, but it's quite difficult, so it should be #5. You solved it too easily, because you could pick any event! It gets harder if you can activate the closest event in a direct line of your sight. And yes, there is always only ONE option for you when you activate the skill. If there is more than one - something is wrong. :ysad:
Fourth puzzle is solvable too. There are multiple blue squares, all of which are used in solving this puzzle. How to solve it is explained above 😅
Puzzle number 5 should be solved through water tiles, only then you can proceed!

Trials:
Number 1 works great.
Number 2 doesn't work like that. To move the crystal when it's in the middle you have to go to that indentation on the left and move it from here.
Number 3 and 4 are really hard, and I really hope you can do it... I guess regions are the only way to go. Don't give up! Even that demon wished you luck!😂
I know activating this skill through menu every time is tedious, hehe. It's why I'll be also using YF's Button Common Events! I'll be setting up 2 extra buttons that will work as shortcuts to particular skills that you'd pick. But that's for later.
4 is easier than 3 lol
now that i know you can only do it on the cobble stones its ALOT easier. like 10 ^ 31 times easier. before i was trying to bascailly navmesh all possible tiles in the way. ending up with 16 different loops! haha!

now its 4 loops that check and increasing axis until it hits a movable event or a blocked region.

by defualt the script checks what region the players is on , then comapres it with the current tile and if the differecne is 8 or more, the loop breaks and no events are found.
this way the selected event is always the closest.

the cursor is a 48x48 picture, put that in Pictures

however the puzzle with the water , the crystals are over 3 blocks away. 🙂. the other the damn followers get in the way
here it is





`
Wow dude, this stuff is spot-on! Thank you very much <3
Question: how do I insert this common event into mine? I just replace the first line (same id) with it and it gives me an error.
the easiest way is to open two projects.
one is your Game that your working on,
the second is the dummy "Copy Buffer".

copy the downloaded CommonEvents.json to Buffer's data folder.
open up both your Game and CopyBuffer into RPGmakerMV. you should have two isntances of RPGmaker MV open.
in the Buffer project, open the data base got to common events then right click and copy.

then open up the common events in your Game project and you should be able to Ctrl:V your new common event in.
editing the JSON files directly is always annoying with large amounts of data.
the easiest way is to open two projects.
one is your Game that your working on,
the second is the dummy "Copy Buffer".

copy the downloaded CommonEvents.json to Buffer's data folder.
open up both your Game and CopyBuffer into RPGmakerMV. you should have two isntances of RPGmaker MV open.
in the Buffer project, open the data base got to common events then right click and copy.

then open up the common events in your Game project and you should be able to Ctrl:V your new common event in.
editing the JSON files directly is always annoying with large amounts of data.
Okay, after lots of testing this stuff works really good! Thank again!

Question 1: can I have that cute pointing finger picture?
Its not very good and i don't even know where it came from, it looks like an old RTP arrow, so its not even mine to use in a game.
I could just draw my own, but how do I add it?
You add it into pictures, then in the common events look for the "show Picture", then change the picture displayed.

Original thread: https://forums.rpgmakerweb.com/threads/help-replicating-field-skills-move.82665/