Tuesday 12 July 2016

Yanfly's Event Window

Yanfly's Event Window is a small window that automatically pops up whenever the Player gains or loses items or gold, and shows exactly what they gained or lost.

I made the following tweaks:

Only display found items


I didn't necessarily want it to show up for items lost, so I added a flag that would turn that functionality off. You could make this the ID of a global switch, much like the HIDE_SWITCH is, but I don't think I'll ever want to toggle it mid-game, so I'm just setting it to false here.


Then you modify the IF statement like below:
First half of the event_window_make_item_text method

Text format


I also added a space between the icon and the item name, and made it always show the amount that had been found even if only 1 has been found.

Second half of the event_window_make_item_text method

Only show newly found items

I personally found it confusing that the Event Window would retain its data every time a new item was found. It made me think I had gotten another of the previous item. So I added code to clear the data every time the Event Window disappeared.

If you get another item before the Event Window has had time to vanish, however, it still shows the previous item. I think this is okay, because it means the window only shows up once when multiple items are received at a time.


The Event Window actually fades away. It doesn't just vanish instantly. That's why there's an if statement to check if the opacity is at 0 before clearing the data, because this method gets called multiple times, gradually reducing the opacity of the window until it's totally gone.

Play a sound every time an item is found

The Event Window is not very obvious, so I wanted a sound to play every time an item was found.

Done during add_text since that only happens each time an item is found

What I would really like is to make it look like the Message Window and perhaps be in a more prominent place, but I haven't figured out how to do those things yet.

Yanfly's Ace Message System

One of Yanfly's scripts is called the Ace Message System. I originally got this script because it allows you to reference an Item's ID in a Show Text command, and have RPG Maker automatically insert both the Item's Icon and it's Name.

The reason this is important is because you might go and change the icon and/or name of an item at a later date, and if you do you definitely don't want to have to update every single event that refers to it manually.

Gotcha #1


If you install this script, you need to be aware of this section:


It's not made clear, but those numbers 21 and 22 are the IDs of your global variables. So if you're currently using variables 21 and 22 for other purposes, you need to change these numbers to be IDs of ones you aren't already using. Otherwise, you will get weird message window sizes that look broken.

Name Window


The Ace Message System also does a whole stack of other things as well. One of the best things is that it allows you to also display a Name Window above your message windows without having to make a custom script call. (I hate having to remember script calls.)

All you have to do is enter in \n<name> right into the Show Text command, much like any of the other commands to change font size or font colour, etc, and you'll get a name window displayed with the text you put between the angle brackets in it.



Gotcha #2

Call me lazy, but I really didn't want to have to go back over every single Show Text command I'd so far written, and repeatedly type in \n<name> at the start of every single one, nor have to do so for every future one. Nor have to do so again if I happened to change someone's name.

So I modified the script to automatically put a Name Window on every Message Window that contained a Face Graphic, and to use the name of the file as the character's name.

This means that NPCs with specific names need their own Face Graphic file (which is not a bad thing, since I have trouble remembering which Face Graphic is whose for the more important NPCs). It also means that even the most insignificant NPC needs some sort of name or descriptor, but this isn't such a big deal. Descriptors can be really useful for the player, and I just use Villager, or Girl, or Noble, etc, which means I can also group a bunch of Face Graphics together into the same file for those insignificant NPCs for ease of use.

I also scripted it so that it will use the name of the file up until any underscore character. This means I can have 16 servant NPCs in two files named Servant_1.png and Servant_2.png and still have the Name Window just displaying "Servant".

All that's required is to modify the start_name_window method at around line 885 to look like this:


Use Event Name

An alternative is to use Yanfly's original logic of \n<name>, but to modify it so you can specify an Event ID in place of just any string. E.g. \n<21> where 21 is Event 21.

The added line 803 below will take that tag and get the name of the Event that matches the given ID for the Name Window. If this tag is present in the Show Text command, this is what will be displayed in the Name Window rather than the name of the Face Graphic.



The rest of the lines in this method are variations that will change the position of the Name Window. I don't see myself ever doing that, so I didn't bother adding equivalent lines with the Event ID tag.

Gotcha #3

Getting an Event's name requires a bit of further tweaking. Even though the documentation clearly states that the Event object has a name property (and everything on Google indicates that it does for other people), the code I have in RPG Maker actually didn't. 

So I had to go and add this into Yanfly's script as well:

Note that I put this well before the Name Window class.

Yanfly Scripts

After spending about 150 hours learning RPG Maker VX Ace and developing my starting town and the introduction to my main story, I finally hit the world map and random encounters.

I hadn't seen the battle system prior to this, but when I did I was incredibly unimpressed.

So I went Googling and discovered Yanfly's Scripts.

These allow the whole battle system to be changed, and not just the battle system. So I've now come to the conclusion that Yanfly's scripts are a MUST HAVE if you're frustrated with the limitations of RPG Maker, and don't want to write custom script calls all the time. And unlike various other authors of scripts out there, Yanfly most definitely knows what he/she is doing.

The best thing is that the scripts are free to use for everyone provided credit is given to Yanfly, and you give thanks in the form of a free copy of your game.

All Yanfly's scripts can be found here: https://yanflychannel.wordpress.com/rmvxa/

Yanfly provides a tonne of scripts for a wide variety of different purposes, and are mostly well documented, though not all of them will be to your liking. Some are plug and play, while others require a bit of set up such that some programming knowledge really helps.

Installing Scripts

To install a script, open up the Script Editor and scroll down to the Materials section. All custom scripts need to go in this section.


Right click the script list, and select Insert. This will give you a new blank script. Enter a name for it down the bottom, then copy the entirety of one of Yanfly's scripts and paste it in the big blank box on the right.

The order you put the scripts in CAN sometimes matter, so be sure to put any core scripts at the top of the list. (I separate the scripts in the list with blanks to make it easier to find them.)

Then just click OK, make sure to Save your project, and hit Playtest to make sure the scripts don't cause any errors.

NOTE
I haven't encountered this with Yanfly's scripts so far, but something to be aware of is that some scripts will cause the game to crash when loading a game save file that was created BEFORE installing the script, but will work fine if you start a New Game. This is to do with what the script requires to be set up when the game starts, and does not mean the script is a bad script.


Monday 11 July 2016

How to make NPCs stay where you put them

Problem: My NPC doesn't stay where I put him!


Every time the Player enters a map, all events return back to where they were originally placed.

This means that any NPCs you manually moved while the Player was on the map are right back where they started.

This is fine for random townsfolk who move about randomly or just repeat the same route, but if you have cut scenes or any interaction that causes an NPC to change locations (and/or change their behaviour) then it can really stuff you up.

Solution 1

If the NPC is supposed to vanish, the easiest way to get them to remain vanished when the Player comes back is to set a Self Switch (or Switch, if controlling them from a different Event) that switches their behaviour to a new Event Page with no graphic. (Self Switches and Switches maintain their state globally.)

(This solution can also be used to change their Autonomous Movement, if you just want their move route to change.)

Solution 2

If you need your NPC to be in a totally new location, however, the only way to do this without scripts is to create an Event with its Trigger set to Parallel Process. Insert Set Event Location commands and set up each NPC with its new coordinates. 

Once all commands are set, use an Erase Event command. This will terminate the Parallel Process after it has run once, and since Erase Event commands don't actually delete the Event, it will reset every time the Player returns to the map, and all those Set Event Location commands will happen again.

This only runs when the set condition is true