Yanfly Engine Plugins is a plugin library made for RPG Maker MV, a wonderful piece of software to help you make that role playing game of your dreams. You can find out more about RPG Maker MV here.
You can grab the plugins used in this video here:
Event Copier
Self Switches & Variables
Support Team Yanfly on Patreon
—
Eventing a foraging system might sound pretty basic at first. Just make an event where you can grab some berries from a bush, turn on a self switch, and then call it a day. But once you’ve decided to give them the ability to respawn after a number of days, it suddenly becomes a lot more complex. This tutorial video will cover how to create a foraging system complete with respawning from the ground up!
You can grab the copy/paste code here:
For those who wish to acquire the script call used, you can get it from here. Change the values in red to fit your game’s settings.
var mapId = $gameVariables.value(1); // This variable contains the Map ID. var eventId = $gameVariables.value(2); // This variable contains the Event ID. var varId = 41; // This is the self variable ID you're using for Respawn Days. // Update the self variable: Respawn Day's value. var value = this.getSelfVariableValue(mapId, eventId, varId); if (value > 0) value -= 1; this.setSelfVariableValue(mapId, eventId, varId, value);
For those who would like to see the structures of the events and common events used, look below:
Berry Bush – Event
◆Comment:// Calculate a random number to determine yield ◆Control Variables:#0001 Temp Variable 1 = Random 2..8 ◆Comment:// Player acquires the random number ◆Change Items:Berry + {Temp Variable 1} ◆Comment:// Set the number of days to wait before respawning berries ◆Control Variables:#0041 Self Var Respawn Days = 3 ◆Comment:// Play a sound effect and show a message. ◆Play SE:Item1 (90, 100, 0) ◆Text:None, Dim, Bottom :Text: :Text:\> \<Acquired x\v[1] \i[577]\c[4]Berries\c[0]!
Remember to make a second page with the variable condition set to the Self Variable: Respawn Days.
Sleep – Common Event
◆Comment:// This common event is used whenever the player :Comment:approaches a bed that they can sleep in. For the :Comment:time being, it'll only work from the cave's bed. ◆Comment:// Ask player about going to sleep ◆Text:None, Dim, Bottom :Text: :Text:\> \<Do you wish to go to sleep? ◆Show Choices:\i[90]Yes, \i[91]No (Window, Right, #2, #2) :When \i[90]Yes ◆Comment:// If Yes, fade out the screen ◆Play ME:Inn (90, 100, 0) ◆Fadeout Screen ◆Comment:// Then run the Night Cycle common event ◆Common Event:Night Cycle ◆Comment:// Finally, teleport the player to the entrance of the cave ◆Transfer Player:Around the Cave (15,6) (Direction: Down) ◆Wait:60 frames ◆Comment:// Fade in the screen ◆Fadein Screen ◆ :When \i[91]No ◆Comment:// If No, do nothing ◆ :End
Night Cycle – Common Event
◆Comment:// The purpose of the Night Cycle common event is to cycle :Comment:through all of the common events that are used to update :Comment:the various event systems in place for the game. ◆Common Event:Update Day Respawns
Update Day Respawns – Common Event
◆Comment:// This event is called by the Night Cycle. It is used :Comment:to update the number of days left on each event that :Comment:uses the Self Variable: Respawn Days ◆Comment: :Comment:// Update variable 1 with the Map ID to update the Respawn Days for. :Comment:Then, run the Respawn Day Cycler common event. ◆Comment: :Comment:// Map 14: Around the Cave ◆Control Variables:#0001 Temp Variable 1 = 14 ◆Common Event:Respawn Day Cycler ◆Comment: :Comment:// Map 25: Another Map ◆Control Variables:#0001 Temp Variable 1 = 25 ◆Common Event:Respawn Day Cycler ◆Comment: :Comment:// Map 36: Yet Another Map ◆Control Variables:#0001 Temp Variable 1 = 36 ◆Common Event:Respawn Day Cycler ◆Comment: :Comment:// * Note: Don't worry if the Map ID doesn't exist. :Comment:// This will not crash your game.
Respawn Day Cycler – Common Event
◆Comment:// This event is used to cycle through the many events :Comment:found on each map and to see if the Self Variable named :Comment:Respawn Days needs to be updated. ◆Comment: :Comment:// Variable 2: The current Event ID being checked. Start at 1. :Comment: Variable 3: The maximum Event ID that needs to be checked. Usually 999. ◆Control Variables:#0002 Temp Variable 2 = 1 ◆Control Variables:#0003 Temp Variable 3 = 999 ◆Comment:// Create the loop. ◆Loop ◆Comment:// Make a script call that gathers the value of the currently looped event ID. ◆Script:var mapId = $gameVariables.value(1); // This variable contains the Map ID. :Script:var eventId = $gameVariables.value(2); // This variable contains the Event ID. :Script:var varId = 41; // This is the self variable ID you're using for Respawn Days. :Script: :Script:// Update the self variable: Respawn Day's value. :Script:var value = this.getSelfVariableValue(mapId, eventId, varId); :Script:if (value > 0) value -= 1; :Script:this.setSelfVariableValue(mapId, eventId, varId, value); ◆Comment:// Increase the current Event ID at the end of each loop. ◆Control Variables:#0002 Temp Variable 2 += 1 ◆If:Temp Variable 2 > Temp Variable 3 ◆Comment:// If the current Event ID bypasses the maximum Event ID, break the loop. ◆Break Loop ◆ :End ◆ :Repeat Above
And that’s all! These are the basic and common events used to event a foraging system!
Happy RPG Making!