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

● ARCHIVED · READ-ONLY
Started by Trihan 48 posts Page 2 of 3 View original ↗
  1. Draegon said:
    This is all working, but when creating more nodes in other places, more and more must be filled into the Node Re-spawn common event.
    So I was hoping to combine this solution in this topic with my current setup.

    Maybe not using the array? But still pushing the MapID and EventID to the events in a variable?
    So that my Node Re-spawn common event is this checked manually.
    I suggest you follow Trihan's tutorial more strictly. That's the entire point of his script in his common event, the for loop does the countdown and check for every ore that you've put into the array to be respawned eventually.
    Draegon said:
    I do not want ore nodes (or maybe other resources) to re-appear the same day in game.
    Then you control how long they take to respawn, by the values you put into the array and how long you make the parallel event wait at the end.

    But by changing his tutorial and separating it into specific events like this, you've basically broken the exact thing you want it to do, and made the event much longer and more complicated than it needs to be.
  2. ATT_Turan said:
    I suggest you follow Trihan's tutorial more strictly. That's the entire point of his script in his common event, the for loop does the countdown and check for every ore that you've put into the array to be respawned eventually.

    Then you control how long they take to respawn, by the values you put into the array and how long you make the parallel event wait at the end.

    But by changing his tutorial and separating it into specific events like this, you've basically broken the exact thing you want it to do, and made the event much longer and more complicated than it needs to be.
    Thanks for all the advice and insights.
    I'll give the tutorial a try then.
    I just mentioned what I already had running ;)

    Update:
    I've applied the tutorial script. With just a small adjustment it also seems to work the way I wished for. :D

    I adjusted the array from 500 to 1
    1658826752774.png
    And then I just added my random variable:
    1658826683361.png

    This way I have a chance that nodes re-spawn. Instead off re-spawning always. :)
    I hope there aren't any flaws in this setup?

    If this looks OK, I would like to thank you for this and helping me forward :D
  3. Hey there fellow game devs! I figured I'd add this tutorial to my list of RPG Maker tutorials to do my "Plugin-ification" remodeling. My main focus for my plugin-ification projects is to make them for RPG Maker MZ, so if that helps you out with your game dev projects, then my Eventing-Style to Plugin Command Style remodeling of existing Tutorials/Guides will help. I basically recreate the actions of MZ Evented Commands in the form of neat-and-tidy Plugin Commands to reduce the amount of lines of Eventing needed which makes debugging your Events much easier with less lines to scan thru.

    Here's the link to the small RPG Maker MZ Demo Project I made of the Plugin-ified remodel of Trihan's Tutorial:
    https://kurochan.itch.io/ke-gsysmz-plugin

    Hope this helps you guys out! I had fun turning this super epic tutorial by Trihan into a Plugin as well!
    (a side note to any other RPG Maker MV/MZ tutorial creators who happen to be reading his, I'd be glad to do a Plugin-ification remodel of your Game System tutorials as well if you want! Just reach out to me with the link to your Tutorials you want remodeled as a plugin and I'll add them to my "To-Do List".)
  4. LvLUpDesign said:
    Hey man, thanks for the tutorial.
    I did a video explainer on my YT channel of it and credited you for it, however my MV viewers are having an issue saying that .remove is not a function.
    Would you have any idea why this would be?
    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;
            }
        }
    };
  5. Thank you @Trihan, this is really helpful for me and I couldn't manage this by myself I think. I will use this for a "event timers" in processing stations in my game.
  6. I've been looking for self respawning nodes for hours. Works perfectly fine.

    What has me scratching my head is how to calculate the tics to minutes. Thanks again!

    Question, how can I make it so nodes respawn in 500-5000 tics? So it's a little more randomized.
  7. Nectar said:
    I've been looking for self respawning nodes for hours. Works perfectly fine.

    What has me scratching my head is how to calculate the tics to minutes. Thanks again!
    You'd just have to put in a number of frames corresponding to the number of minutes you want the wait to be. So for, say, 5 minutes, it'd be 18000 frames.
  8. Trihan said:
    You'd just have to put in a number of frames corresponding to the number of minutes you want the wait to be. So for, say, 5 minutes, it'd be 18000 frames.
    It just hit me that its calculated by the 60FPS so I had to use a frames to timecode calculator xD

    I'm not sure if you saw my edit but how can I make it so nodes respawn in 500-5000 tics? So it's a little more randomized.

    Again thanks for your help.
  9. Okay, so for that in the place where you provide the frames argument you would do

    Math.randomInt(max - min + 1) + min

    So for 500-5000 frames

    Math.randomInt(4501) + 500

    The +1 is because randomInt is value-exclusive, so it goes from 0 up to 1 less than the value you specify.
  10. Hello, how would I make it so that the ores respawn on resting at an inn rather than on a timer?
  11. Emperor3D said:
    Hello, how would I make it so that the ores respawn on resting at an inn rather than on a timer?
    You'd change the parallel event to a regular common event and take out the counting down.

    Code:
    for (const oreData of $gameVariables.value(1)) 
    {
        $gameSelfSwitches.setValue([oreData[0], oreData[1], 'A'], false);
        $gameVariables.value(1).remove(oreData);
    }

    Have your innkeeper events call that common event.
  12. Unsure if I've done something wrong, the event seems to only respawn some nodes. Let's say I mine 6 nodes, if I rest, it will only respawn the first, third and fifth nodes. If I rest again, it respawn the second and sixth nodes. I rest one more time to respawn the fourth node.
  13. Emperor3D said:
    Unsure if I've done something wrong, the event seems to only respawn some nodes. Let's say I mine 6 nodes, if I rest, it will only respawn the first, third and fifth nodes. If I rest again, it respawn the second and sixth nodes. I rest one more time to respawn the fourth node.
    That seems odd. Can you show me your events?
  14. Trihan said:
    That seems odd. Can you show me your events?
    Sorry for the late reply. Here are the events:

    The Ore node. This has been copied 5 times in the same map:
    Screenshot_2.png
    Common event. I assume I messed something up here:
    Screenshot_1.png
    Innkeeper event:
    Screenshot_3.png
  15. I can't see why that wouldn't reset all nodes, but looking at your use case I'm not sure this was the way to go for you in the first place. If you don't need *timed* node respawn and they all just reset when you stay at an inn, you can just turn on a self switch for the event and then your respawn event would just turn all those self switches off.
  16. Thanks for your help :)
  17. 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?
  18. Candacis said:
    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?
    I might be confused - why would you need a second variable? Just set it to a higher value.

    JavaScript can take integer values up to 9,007,199,254,740,991 so that's probably more than you need.

    Alternately, you could in fact use a second variable in the common event so that the number you push into the arrays for your nodes represents seconds or minutes, rather than frames.

    e.g.
    Control Variables -> +1
    Conditional Branch -> that variable == 60
    - Control Variables -> 0
    - Trihan's script

    will make it run every second instead of every frame. You can adjust the math from there. But there's really no need for that.

    Candacis said:
    Also, what would happen, if the player doesn't wait it out, but goes to bed at night?
    They wake up feeling rested.

    Candacis said:
    Is it possible that an innkeeper event could add specific time/frames to the timer?
    Oh, you meant the player makes the character go to bed :stickytongue: Sure.

    Just make another common event, copy the script from the parallel one. You'd change two things:
    - change the second line from saying -- to saying -=28800
    - change the third line from === 0 to <=0

    Then make your innkeeper call that common event.
  19. ATT_Turan said:
    I might be confused - why would you need a second variable? Just set it to a higher value.

    JavaScript can take integer values up to 9,007,199,254,740,991 so that's probably more than you need.

    Alternately, you could in fact use a second variable in the common event so that the number you push into the arrays for your nodes represents seconds or minutes, rather than frames.

    e.g.
    Control Variables -> +1
    Conditional Branch -> that variable == 60
    - Control Variables -> 0
    - Trihan's script

    will make it run every second instead of every frame. You can adjust the math from there. But there's really no need for that.


    They wake up feeling rested.


    Oh, you meant the player makes the character go to bed :stickytongue: Sure.

    Just make another common event, copy the script from the parallel one. You'd change two things:
    - change the second line from saying -- to saying -=28800
    - change the third line from === 0 to <=0

    Then make your innkeeper call that common event.
    Hey, answer your own threads! I was just in the middle of responding to this. XD
  20. Trihan said:
    Hey, answer your own threads! I was just in the middle of responding to this. XD
    Sorry! Please answer it better, messire! That way education may be doubly bestowed.