BadMinotaur

You can do it!
Veteran
Joined
Mar 13, 2012
Messages
260
Reaction score
115
First Language
English
Primarily Uses
RMVXA
Beacons - NPC Spawning

by BadMinotaur

Introduction

Ever wanted to have your town full of citizens in different places, as if everyone in the town maybe didn't stay in the same spot forever? Or maybe you want an easier way to randomize your touch encounters on your map. This script lets you do both, and more.

Features

This script introduces a feature called "Beacons," blank events on a map that spawn events from a container map full of spawnable events. That probably sounds weird, so let's run with our citizen example above: let's say you have a town, and you want the citizens in the town to change up every time the player enters the map. So you place several "citizen" beacons around your town, and when the map loads, the script chooses a bunch of citizens randomly from your pool of designated citizen NPCs and places them on the map in place of the beacons. Voila!

It also exposes its NPC spawning code so that anyone who wants to use a Script Call event command or who wants to integrate it into his/her own script can do so. This can be used for traps, cutscenes, toys... whatever you'd like!

How to Use

Once you learn how to use Beacons, they're very easy to work with. But the explanation is a little long-winded. Click on the spoiler to see the full tutorial. The script itself also has this same explanation in its header.

First, you need to set up a container map. This is a map that contains all of the events you'll want to spawn. First, make a new, empty map, and make a note of its number. Don't worry about naming it anything specific -- you can name it and really do anything you want with it -- this script only cares about events on this map.

Rfc3ruw.png


Open up this script in your script editor, and navigate to the MAP_ID and MAP_NAME options, and change them to whatever number your map has.

NOTE:  MAP_NAME is *not* the name you give it inside of RPG Maker! It is the file name of the map, without the .rvdata2 extension.

KxWfIJk.png


Now we get to actually make the events we will spawn! Make an event like normal on the container map. When you're satisfied with your event, add a comment at the very top of the event. Here, we're going to "tag" the event. Type this:

<beacontype: my_beacon_name>into the comment. This will let the script know that you now have an NPC named "my_beacon_name" that you want to spawn later!

VXpU3aY.png


The great thing about this script is that more than one NPC can have the same beacontype. If you gave three different NPCs the beacontype "my_beacon_name", the script would choose randomly between each one when spawning them. This is great for, say, spawning a town of NPCs that change each time the map loads!

There is one more tag you can put on these events. By default, this script assumes each NPC you're spawning is "generic" -- any number of them can spawn. You can instead put another tag next to your beacontype:

<unique>This tag tells the script that if the current NPC is already on the map, STOP the spawning! This NPC will only be one per map, no matter what. Great for story-specific items or NPCs.

NOTE: This script checks each *current* page for beacontypes! What this means is that if you set a variable/switch that makes your NPC change pages, this script will look at the new page to see if it has any beacontypes. So if you want the NPC to keep its beacontypes (and uniqueness) you'll need to copy and paste them onto each relevant page!

After you've set up whatever NPCs you want, then you can actually spawn them on a map! This is also done using event tags. On whatever map you want an NPC to spawn, just add a blank, empty event with the following tag (again, in a comment at the top of the event):

<beacon: my_beacon_name>Replacing "my_beacon_name" with whatever name you gave your NPC on the container map.

1qy61lG.png


The cool thing about beacons is that the beacon also looks at what page it is on to see what beacontype it will spawn. So, for example, if you put a bunch of beacons in a town to spawn citizens, then that town gets taken over by goblins, you can set a switch and all of the beacons will now spawn goblins!

There is one last bit of functionality when using beacons. If you'd like a beacon to sometimes spawn a "rare" NPC some percent of the time, tag it like this:

<rare: another_beacon_name>Then, the spawner will roll a 100-sided die to see if the rare beacon is spawned. The default chance for a rare NPC to spawn from a raretype is 25%, but you can change this number with the BEACON_RARE_CHANCE option in the script.

NOTE: I say to use an empty event for your beacon, but you don't have to. You can give it a graphic, and even other event commands, but none of these will matter or show up in-game. When the game sees that it is a beacon, it will destroy the original event and replace it with the spawned NPC.

So how does that work out in the end? Here's our map inside of RPG Maker:

I98pjn1.png


And here's the same map actually running:

k3TF7ml.png
And for you scripters and Script Callers:

This script has a goodie for you too. I've tried to make spawning NPCs dynamically, outside of the beacon system, easy to access. Here's the command:
 

  NPCSpawner.spawn_beacontype(beacon_name, x, y)    or  NPCSpawner.spawn_beacontype_with_rare(beacon_name, rare_name, x, y)As long as beacon_name and rare_name correspond to a beacontype you've defined in your container map, you're clear to go.

Clever Uses

Beacons is a script that has a lot of potential uses. I use the citizens example pretty frequently because it's a great example, but there's other things you can do with it too. If you come up with some kind of clever way to use this script, let me know in this thread (or PM me) and I'll put it here!

Atmosphere control - In the game it came from, Runes and Dunes, we used Beacons in place of changing the music via map options. We'd put a beacon on every map that spawned an invisible, self-erasing event whose only purpose was to change the screen tint and the music. So when our villain, Gorza, took over the city, the city music changed from a happy tune to a more somber one, and the screen tone was shifted to a more grey, dull color; and it took no extra work, other than making the event in the container map change pages when he took over.

Demo

Download here

If you'd like to see the example above in an actual project to mess with, this demo already has a bare-bones demonstration of the script in action.

Script

You can get the script at this pastebin:

http://pastebin.com/H4xKdFb7

Compatibility

This script aliases Game_Map::setup and Game_Event::initialize. Any other scripts that modify these two methods have a chance at being incompatible with them. If this script breaks something in one of those scripts, try placing it before those in the Script Editor. If this script has a glaring incompatibility with another popular script, please let me know in this thread! I'll see what I can do.

FAQ

Q: Hey, my self-switches won't stick on any of my spawned events! When I change maps, they're all wiped clean!

A: I know, and it brings great shame to my family. It's something I'm working on; I have a solution in mind, I just need to actually code it and test it.

Q: I'm trying to spawn a unique NPC, and even though it's the only one of its kind spawning, the console keeps yelling at me that it can't spawn the unique NPC anyway. What gives?

A: The "unique" NPC checking method does the following:

  1. It checks to see if any other event on the map has the same character graphic ("character_name" in RGSS3), and
  2. If it does, it checks to see if that other event has the same index ("character_index" in RGSS3).
So if you're trying to spawn a unique NPC that looks exactly like another NPC, you might be out of luck. Thankfully though, you could just make a separate graphic file to hold the duplicate, and then the script won't see it as the same person anymore.

Terms of Use

You may not redistribute this script without my written permission.

You may freely use this script in non-commercial projects.
You must contact me before use in commercial projects. Don't worry, I'm a reasonable fellow.
You may alter and add on to this script for your own projects. You may not redistribute this script as an altered script (in other words, making a change does not mean you get to ignore the "don't redistribute" clause above).

However, you may freely create and redistribute any patches to the script, so long as said patches don't unnecessarily duplicate any major functionality of the script.

If you use my script, I'd like credit. "BadMinotaur" will do =)

Credit and Thanks

This script is pretty much all my work. I made it for a game a year and a half ago, and decided to rip it out, clean it up and give it to the community.

Other Notes

This is my first script release, so if I'm missing some kind of glaring, necessary thing, please let me know and I'll fix it as soon as I can! To other scripters: I'm constantly trying to improve, and I know this script is kind of weird in how it handles some things. If you see something I can fix/optimize, please don't hesitate to let me know. Just be gentle~
 
Last edited by a moderator:

Farr

Veteran
Veteran
Joined
Feb 16, 2014
Messages
247
Reaction score
93
First Language
Portuguese
Cool script dude, it brings more realism to citizens, now I wont have the flower lady standing near the same flowers for 18 days.
 

cygnus flamel

Veteran
Veteran
Joined
Feb 9, 2014
Messages
41
Reaction score
17
First Language
spanish
Primarily Uses
What!? Amazing script! I will give I a try tomorrow.
 

BadMinotaur

You can do it!
Veteran
Joined
Mar 13, 2012
Messages
260
Reaction score
115
First Language
English
Primarily Uses
RMVXA
Thanks for all the kind words, everyone! I'm super-excited that people are finding it useful.
 

Latest Threads

Forum statistics

Threads
124,349
Messages
1,162,948
Members
163,147
Latest member
onbetme
Top