MZ Galv's event spawner question

I'm trying to spawn events in front of the player character. Is there a way to do this with Galv's event spawner?
I haven't tested it, but something like this should work:
JavaScript:
let x = $gamePlayer.x;
let y = $gamePlayer.y;
const dir = $gamePlayer.direction();

switch (dir) {
    case 2:
        y++;
        break;
    case 4:
        x--;
        break;
    case 6:
        x++;
        break;
    case 8:
        y--;
     
}

Galv.SPAWN.event(eventId, 'xy', [x, y], 'all');

Put that in a Script... event command. You'll want to change eventId to be the actual numerical ID of the event.
Thanks for the quick reply. 🙂

I copy/pasta'd the script into the "script..." window under event commands but the text won't fit in the small window, am I doing something wrong? sorry, I'm super new to rpg maker.
You are using RPG Maker MZ, correct?
yup 🙂
There shouldn't be an issue then. The script box can hold over 5000 lines of code. Can you show me a screenshot of what you're talking about?
Screenshot 2022-06-20 155900.png

Yeah it cuts off the bottom few lines of text. I feel like i'm missing something obvious lol.
It doesn't look like you're doing anything wrong. For some reason, your editor just isn't working like it should be. When you go past the bottom line, the script box is supposed to gain a scroll bar, so it can accommodate more lines.

Spoiler: My Editor
ScriptBox.png

As you can see, I've literally got 5000 lines in mine. If there even is a limit, I've never bumped into it yet. The 12 line limit that you're experiencing was a real thing in MV, but that shouldn't be happening in MZ.

I don't really know what to tell you about that. Maybe try saving your project and then exiting MZ. Then re-open it, and see if it's working right. If not, then make sure it's updated to the latest version, and try restarting your computer.

If it's still not working after that, then I guess maybe make a support request regarding that issue? As a band-aid fix, we can work around your issue by condensing the script I posted so that it fits within 12 lines, but I'd still recommend trying to resolve the issue.

*edit* On a completely unrelated note, I am ridiculously jealous that it's only 15° C where you are.
It doesn't look like you're doing anything wrong. For some reason, your editor just isn't working like it should be. When you go past the bottom line, the script box is supposed to gain a scroll bar, so it can accommodate more lines.

Spoiler: My Editor

As you can see, I've literally got 5000 lines in mine. If there even is a limit, I've never bumped into it yet. The 12 line limit that you're experiencing was a real thing in MV, but that shouldn't be happening in MZ.

I don't really know what to tell you about that. Maybe try saving your project and then exiting MZ. Then re-open it, and see if it's working right. If not, then make sure it's updated to the latest version, and try restarting your computer.

If it's still not working after that, then I guess maybe make a support request regarding that issue? As a band-aid fix, we can work around your issue by condensing the script I posted so that it fits within 12 lines, but I'd still recommend trying to resolve the issue.

*edit* On a completely unrelated note, I am ridiculously jealous that it's only 15° C where you are.

It doesn't look like you're doing anything wrong. For some reason, your editor just isn't working like it should be. When you go past the bottom line, the script box is supposed to gain a scroll bar, so it can accommodate more lines.

Spoiler: My Editor

As you can see, I've literally got 5000 lines in mine. If there even is a limit, I've never bumped into it yet. The 12 line limit that you're experiencing was a real thing in MV, but that shouldn't be happening in MZ.

I don't really know what to tell you about that. Maybe try saving your project and then exiting MZ. Then re-open it, and see if it's working right. If not, then make sure it's updated to the latest version, and try restarting your computer.

If it's still not working after that, then I guess maybe make a support request regarding that issue? As a band-aid fix, we can work around your issue by condensing the script I posted so that it fits within 12 lines, but I'd still recommend trying to resolve the issue.

*edit* On a completely unrelated note, I am ridiculously jealous that it's only 15° C where you are.
So it turns out I had an older version of MZ. Just got the update and the script window is functioning just like you said. 🙂

I'm getting an error when I run the event though.
This is how I have the event set up.
I'm using J.A.B.S. action battle system and the events i'm trying to spawn are active npcs if that matters.

It's a nice cool first day of Summer out here in B.C. 😉
On the third line, $gameplayer needs to be $gamePlayer. It's case sensitive.

Sorry about that. That was my bad. When I typed that for you, it was 40ºC outside, and my air conditioner had been broken for several hours at that point, so I was gradually losing my ability to focus. It doesn't help that I had also pulled an all-nighter, but it was mostly the heat thing.
It works perfectly now. Thankyou so much. 🙂

Sorry to hear that about the heat where you are. Drink lots of water.

One more thing (and this isn't a big deal so feel free to not answer) I was wondering if it's possible to increase the range with that script, like to spawn an event 2 or 3 squares ahead of the player.
No problem. If you want to control the distance, you can do so with this version of the script:
JavaScript:
const distance = 3;
let x = $gamePlayer.x;
let y = $gamePlayer.y;
const dir = $gamePlayer.direction();

switch (dir) {
    case 2:
        y += distance;
        break;
    case 4:
        x -= distance;
        break;
    case 6:
        x += distance;
        break;
    case 8:
        y -= distance;
}

Galv.SPAWN.event(eventId, 'xy', [x, y], 'all');

That one will spawn the event 3 tiles ahead of the player. You can adjust it by changing the 3 in the first line. It actually should support negative numbers as well, if you want to make events spawn behind the player.
Awesome!
Thanks for everything. You're the best. 🙂
Awesome that what looking for. But here a question. What if i need that events spawning BEHIND player, What need to change in that script for result?
Awesome that what looking for. But here a question. What if i need that events spawning BEHIND player, What need to change in that script for result?
Change the + signs to - and vice versa
Thank you so much, it worked! And one more small question. I'm using this plugin for a kung fu type mini-game on nes, but I want items to drop from enemies, so after killing an enemy I use the script
JSON:
Galv.SPAWN.event(7, 'xy', [$gamePlayer.x ,$gamePlayer.y], 'all')
But items appearing at actor place, all i need is to move the item at next position before actor , i tried +1 but this is not the right. seems here need something with face direction code too.
Geez. im sorry i already understand how to... sorry for dumb question.
const distance = 1; all i need

Original thread: https://forums.rpgmakerweb.com/threads/galvs-event-spawner-question.148735/