How to create respawning resource nodes using a single variable and a common event.

● ARCHIVED · READ-ONLY
Started by Trihan 48 posts Page 3 of 3 View original ↗
  1. Candacis said:
    Thanks for this tutorial, it really helped me out creating a small gathering system.
    I set the timer to 86.400, so it takes 24min to respawn.

    I'm wondering if I could do a second variable for a longer respawn time and would this need a second common event, too or could I put it in the same common event?

    Also, what would happen, if the player doesn't wait it out, but goes to bed at night?
    Is it possible that an innkeeper event could add specific time/frames to the timer?
    Let's say a 24 hour day takes 86.400 frames, but one day the player doesn't run around at night, but goes to sleep for 8 hours. Could I somehow add 28.800 frames to the timer?
    If you have nodes that take longer to respawn, just put a different number in when you push that node to the array. It doesn't have to be the same for every one.

    Likewise, if you want to have 8 hours pass, do the thing in the common event but subtract the number of frames you want instead of 1, and check for <= 0 instead of === 0. Everything else should function the same.
  2. Thank you both for your fast replies!
    I woke up 8 hours later feeling rested and reading your answers :D

    Now, I'm thinking, if I have an Innkeeper event, but instead of fix 8 hours sleep, I want players always to wake up at 7 in the morning (I have a time system common event that counts the hours/time).
    But what happens, if the players goes to sleep at midnight? Or at 9 in the evening? Then maybe they sleep more or less than 8 hours.

    What complicated math shenanigans can I do to count that?
  3. Trihan said:
    Oh, beans, how did I miss this when you posted it?

    The reason is that .remove is an MZ-specific array function. Its implementation can be recreated in MV though, all it does is this:

    JavaScript:
    Array.prototype.remove = function(element) {
        for (;;) {
            const index = this.indexOf(element);
            if (index >= 0) {
                this.splice(index, 1);
            } else {
                return this;
            }
        }
    };
    @Trihan
    Sorry for asking this but, does this block of code need to be inserted inside rpg-core.js?
    If so, does it need to be in a specific position inside the file?
    Thank you
  4. Saradas said:
    @Trihan
    Sorry for asking this but, does this block of code need to be inserted inside rpg-core.js?
    If so, does it need to be in a specific position inside the file?
    Thank you
    I would add it as its own plugin rather than putting it in a core file.
  5. How would I go about removing the timer aspect from this and simply reset the nodes by manually calling the common event? I'm using a day/night system and would simply like all nodes to respawn at the start of each day.
  6. Siffers said:
    How would I go about removing the timer aspect from this
    From the instructions on the first page:
    Trihan said:
    The second line is storing an array of data identifying this particular node event and the number of frames it'll take to respawn. So in this case, 500 frames, or just over 8 seconds.
    Thus, you'd simply omit the number of frames.
    Code:
    if ($gameVariables.value(1) === 0) $gameVariables.setValue(1, []);
        $gameVariables.value(1).push([this._mapId, this._eventId]);

    Then you wouldn't have Trihan's parallel event at all; in your day/night common event, when it becomes day, you'd paste his code without any reference to the frames and checking for it to be zero.

    Code:
    for (const oreData of $gameVariables.value(1)) {
        $gameSelfSwitches.setValue([oreData[0], oreData[1], 'A'], false);
        $gameVariables.value(1).remove(oreData);
    }
  7. That's what I was thinking, but JS still intimidates me pretty hard at this point.
    Thank you for the help ♥

    Edit:
    Alright, no idea what I did wrong, but it seems to only be resetting half of the nodes at a time.

    Edit 2:
    Okay, so I just removed the "remove()" part of the code and that seemed to get them all to reset instead of half. I figure that's there to stop the array from being flooded by duplicate entries though, so I manually reset my variable back to it's initial array state.
  8. Hello, good day.It was very helpful and works very well. I'm a beginner and I'm learning to make simple plugins (MZ), I'll try to turn it into a plugin.