Eventing help: Give player random amt. of gold every X steps?

Hi all! Because I'm not planning to have any random encounters in my game (there will be some combat, but it happens at specific times/points in the story), I wanted to instead give the player small, random amounts of gold as they walk around. I feel like this is going to involve loops and conditional branches, so I tried to combine those to the best of my (fairly limited) ability.

1620500267312.png


(I know it says the trigger is "none" but don't worry, I have an event on my test map to call this)

To explain a little bit: I've set up two variables, one to store the number of steps walked, and another to generate a random number between 10 and 100. I kind of tried to make it so every 50 steps the loop would "reset" the variable and start over, but I don't think I did it right... The break loop command is there to make sure you can't just run around endlessly and get a bajillion gold 😛

Anyway! I haven't gotten this to work yet, could someone tell me what I'm doing wrong?

Thanks~
The problem might just be that there's no trigger, even if the event is called. Try setting up one and see if it works.
At what time is this event executed? During the start of the game or a while later? If it is started some time later, then the first thing you should do is reset the variable designated to count the steps because the game does it from the first moment (the developer just calls a variable in function to this to know that information).


Condense the actions to a single condition: if "steps" is equal to or greater than 50.
I think, you can execute variable somewhere else to start at 0 or at -1.
there is also a "step counter" under "variables -> Game Data -> other"
which is maybe easier to use, once step counter hit 50, give gold
and reset variable steps = 0
the steps will never reset to zero, so you'll need two variables, one to store previous goldstep and one for the current step.
if the current step is 50 higher than the last goldstep, give gold and update goldstep to current step
Be careful with loops! I expect that event will severely reduce framerate (if Parallel) or lock up the game (non-Parallel). Try to follow the logic through and see if you can spot why. Hints:
  • What happens if the variable is not 50 when the loop starts?
  • There are no waiting points in that loop: the game will try to complete it within one frame.
Instead, as mentioned by others, you can keep a running tally of steps taken in another variable. This variable can be reset when you give the gold. Consider a Parallel event something like this:
Code:
◆Comment:Get difference between stored step count and current step count
◆Control Variables:#0001 Check -= Steps
◆Comment:Has it changed since last check?
◆If:Check ≠ 0
  ◆Comment:It has changed (player has moved)! Update step count variable~
  ◆Control Variables:#0002 Step Count -= Check
  ◆If:Step Count > 49
    ◆Comment:50+ steps taken!
    ◆Show Balloon Icon:Player, Light Bulb
    ◆Change Gold:+ 20
    ◆Comment:Reset step count to 0
    ◆Control Variables:#0002 Step Count = 0
    ◆
  :End
  ◆
:End
◆Comment:Store current step count in variable for next check~
◆Control Variables:#0001 Check = Steps
◆Comment:Check again in 6 frames
◆Wait:6 frames
This uses two variables:
  • Check - tracks step count from last frame, used to check for player having moved.
  • Step Count - running tally of steps taken
purely based on your excertps there, it looks like the second If is set incorrectly because you have it so that if steps are lower than 50: reset variable, when it should be more than 50 steps when it does this. for the break loop condition you did it correctly. above 10k g it breaks the loop. so currently it resets your step count all the time and they'll never reach 50
From what I can tell:
  • We don't know when or how often your event will be called, so you might run into performance issues if it's called multiple times. You can avoid this by using "Parallel Process" as Trigger. You can use a Switch to turn this even on or off.
  • If the event calling this is not a Parallel Process, your game will freeze unless Steps is exactly 50 (it's highly unlikely this will happen when the event is first called).
  • You're trying to set Steps to 0 by saving it into var #16 and setting that one to 0. That won't work. Even if it did work, by resetting your step count to 0 whenever your step count is smaller than 50, your step count will never reach 50.
  • Once your step count is 50, you get gold. Players can easily abuse this by taking 50 steps and then waiting for their gold to reach 100000. You need to reset the step count the moment you award the gold.
  • You're defining the random amount of gold outside the loop, so as long as you're inside the loop, the player will always get the same amount of money that was randomly chosen at the beginning. You should set var #17 right before you award the gold.
  • Steps is cumulative, so you can't reset it unless you use a script to force it to 0. If you have any other mechanic that depends on Steps, messing with it could lead to unexpected behavior. Instead, why not try to store Steps modulo 50 into var #16 and checking if var #16 is 0? Don't forget to flip a "gold awarded" switch to prevent the event from awarding any more gold. You can flip that switch back off when var #16 is NOT 0.
  • You're breaking the loop once the player reaches 100000 gold. If the player spends that gold and no longer has 100000 gold, he won't receive any more money because the loop has been broken. Is that your intention? Consider checking for Gold < 100000 and putting your Steps = 50 inside that branch instead.
  • If you change the Trigger to Parallel Process, you can get rid of the loop entirely, as the entire event will repeat instead.
Make a separate common event, set it to parralel process with a trigger switch that will never be turned off. Put in a conditional branch: if the player's gold is less then X, turn [Switch that will trigger this process] on; otherwise, turn the switch off. end this common event with a "Wait: # frames" so it doesn't lag your game to heck.

In this actual common event, make it Parallel Process with the designated switch. You will need two variables: "Steps" and "Steps Memory". Steps will just be defined as however many steps the player has currently taken. Subtract the Steps Variable by Steps memory: if the result is 0, do nothing. If the result is greater than 0, put the number into a third variable called "Step Counter" and then define Step Memory as however many steps the player has taken. After this conditional branch, create a second conditional branch within the same common event that checks if the Step Counter variable is equal to or above 50. If it is, give the player a random amount of money and then set the Step Counter variable to zero; if not, the conditional branch should do nothing. after this second conditional branch, end the common event with a "Wait: # frames" so it doesn't lag your game to heck.
I'm going to try and answer all the questions but my apologies if I miss someone! It's pretty clear that loops are NOT the way to go here, it seems. I will try the method that @caethyril (this is where I wish you could just directly edit the text of events instead of having to press a dozen buttons >.< )

At what time is this event executed? During the start of the game or a while later? If it is started some time later, then the first thing you should do is reset the variable designated to count the steps because the game does it from the first moment (the developer just calls a variable in function to this to know that information).


Condense the actions to a single condition: if "steps" is equal to or greater than 50.

I was planning to have it running at the start of the game, yeah. Probably after whatever short tutorial area I end up doing.

From what I can tell:
  • We don't know when or how often your event will be called, so you might run into performance issues if it's called multiple times. You can avoid this by using "Parallel Process" as Trigger. You can use a Switch to turn this even on or off.
  • If the event calling this is not a Parallel Process, your game will freeze unless Steps is exactly 50 (it's highly unlikely this will happen when the event is first called).
  • You're trying to set Steps to 0 by saving it into var #16 and setting that one to 0. That won't work. Even if it did work, by resetting your step count to 0 whenever your step count is smaller than 50, your step count will never reach 50.
  • Once your step count is 50, you get gold. Players can easily abuse this by taking 50 steps and then waiting for their gold to reach 100000. You need to reset the step count the moment you award the gold.
  • You're defining the random amount of gold outside the loop, so as long as you're inside the loop, the player will always get the same amount of money that was randomly chosen at the beginning. You should set var #17 right before you award the gold.
  • Steps is cumulative, so you can't reset it unless you use a script to force it to 0. If you have any other mechanic that depends on Steps, messing with it could lead to unexpected behavior. Instead, why not try to store Steps modulo 50 into var #16 and checking if var #16 is 0? Don't forget to flip a "gold awarded" switch to prevent the event from awarding any more gold. You can flip that switch back off when var #16 is NOT 0.
  • You're breaking the loop once the player reaches 100000 gold. If the player spends that gold and no longer has 100000 gold, he won't receive any more money because the loop has been broken. Is that your intention? Consider checking for Gold < 100000 and putting your Steps = 50 inside that branch instead.
  • If you change the Trigger to Parallel Process, you can get rid of the loop entirely, as the entire event will repeat instead.


Yeah, the "random variable is set once and that's it" is something I'm still a bit confused by, I remember having to fiddle with it for another event that used random values.
I'm not planning to have any other step-related mechanic (that I know of, yet...) Like I said, there won't be any random encounters. Though I wonder, would this also count steps that the player "takes" during a cutscene? Maybe I need to have a switch that runs this event only if you're NOT in a cutscene.
Though I wonder, would this also count steps that the player "takes" during a cutscene? Maybe I need to have a switch that runs this event only if you're NOT in a cutscene.
I just had a look at the MV code, and any steps taken with "Set Movement Route" are not counted towards your step count.

Also, your step count doesn't change while you're in a vehicle. You might want to keep that in mind.

So you don't need to switch your event off during cutscenes.

Original thread: https://forums.rpgmakerweb.com/threads/eventing-help-give-player-random-amt-of-gold-every-x-steps.136328/