VXAce Random money event doesn’t work correctly + copied events break the random

Hi everyone. I need some help


I’m trying to make a random money event (random reward), but it doesn’t work correctly and I can’t understand what the problem is.


What I did:


  • In one event I use
    Control Variables: CoinRandom = Random No. (1..5)
  • Then with Conditional Branches I turn ON switches:
    • Coin1
    • Coin2
    • Coin3
    • Coin4
    • Coin5

After that, each switch has its own event page that gives a different amount of gold.


Problems:


  1. The random works inconsistently — sometimes it gives the wrong result.
  2. When I copy this event, then:
    • the copy and the original activate at the same time
    • or the random does not work separately for each event
    • sometimes only one event works, as if they are linked together

It looks like all events are using the same variables and switches.


Questions:


  • Do I need separate variables for each event?
  • Should I use Self Switches instead of normal Switches?
  • What is the correct way to make a random money event so every copy works independently?

I would really appreciate any explanation or example


1768901150643.png


1768901165594.png


1768901186202.png


1768901196207.png
You didn't add the switches to the pages. Each page has to have a switch that turns it on, or it will just use the last page.
I didn't really understand which switches page, can you explain?
The random is still not working, I don't really understand what I'm doing wrong, 2 events and 1 of them has the same random, maybe I missed something?



1768923920591.png

1768923928772.png

1768923937409.png

1768923945523.png

1768923960031.png
You will never activate page 2 because one of the following pages will be triggered first by one of those "global" switches.

Instead of using Erase Event, you should use Switch Local so that the event does not repeat.

My advice, stop using Switches and use the variable page.
Page 1: Variable sorting (Random 1~5)
Page 2: Activated by the Variable if the value is 1 or above
Page 3: Activated by the Variable if the value is 2 or above
Page 4: Activated by the Variable if the value is 3 or above
Page 5: Activated by the Variable if the value is 4 or above
Page 6: Activated by the Variable if the value is 5 or above
Page 7: Activated by Switch Local "A", containing nothing, not even a graph
thx)
if the chest is 1xx, why not check and give the loot inside the condition,
and selfswitch A on, so it become a blank page.

if it can be used multiple time, use wait on second page, and turn off selfswitvch A.

but variable pages or switch pages, I would omit though.
Are you sure you need separate event pages for this? I'm not 100% sure what is supposed to be happening, but it seems to me that it could be done on one page with conditional branches...? Maybe can you write out step by step what should happen?
Are you sure you need separate event pages for this?
You're right, it's really not necessary.
I preferred to explain it this way because I thought he wanted to include a sprite for each possible item.
I wanted to make a random spawn of items that are in the page list, there is a special graphic and coin number on that page, if it can be done more easily, can you please explain?

1768973966621.png

1768973980915.png

1768973992903.png

1768974005861.png
You might want to add Control Variables[0001:CoinRandom] = 0 after Control Self Switch: A =On so that it doesn't interfere with other copies of the event.

if it can be done more easily, can you please explain?
While you could do the event on one page, using unique graphics from TileSets complicates that. So you've probably got the best setup without using Scripts(MoreSelfSwitches) or Custom Graphics(Using MoveRoute to Change Graphic).
I didn't understand, do you want the item to reappear when the player returns to the map, or do you want the item to change position on the map each time the player enters?
I didn't understand, do you want the item to reappear when the player returns to the map, or do you want the item to change position on the map each time the player enters?
I want to just go to the map and have items appear randomly in places that will be with that event. It would be easier to do this than randomly in any place on the map.
It would be easier to do this than randomly in any place on the map.
I did something similar for my game. I drew over the spawnable areas on the map with a Region then used this script to get a list of those XY positions.
Spoiler: Code
Ruby:
#====================================================================================
# ◇ SpawnFinder
#   Logic/Pseudocode By utunnels, Compiled/Edited By Zahawk84
#
# ◇ Description:
#   Finds and outputs to console all tile coordinates on the map that match a
#   given Region ID or Tile ID(singular/range).
#   .: A Region ID/Tile ID to Array tile coordinate gathering dev tool.
#
# ◇ How to Use:
# 1. Place this script below "Materials" and above "Main" in the Script Editor.
# 2. Call method from an event using a Script command:
#      SpawnFinder.find_region(region_id)
#    → Outputs an array of coordinates for the given RegionID.
#    Example. SpawnFinder.find_locations(1)
#   SpawnFinder.find_tile(tile_range,tile_layer)
#    → Outputs an array of coordinates matching the TileID or TileID range.
#    Example. SpawnFinder.find_tile(3008,1)
#             SpawnFinder.find_tile(3008..3054,1)
#   TileLayer: 0=Ground, 1=Ground2, 2=B/C/D/E
#   Output default(in console): [[4, 6], [12, 3], [24,9], ...]
#   Output to variable: $game_variable[1] = SpawnFinder.find_locations(1)
#   Comment out "p locations" if using variables instead.
#
# ◇ Notes: Find TileIDs
#   Calls to check TileIDs at a position:
#     p "Tile_ID Layer0 = #{$game_map.tile_id(x, y, 0)}"
#     p "Tile_ID All Layers = #{$game_map.layered_tiles(x, y)}"
#   For AutotileID Ranges: Borderless Tile=Start of Range, Dot Tile=End of Range
#====================================================================================
module SpawnFinder

  def self.find_region(region_id)
    locations = []
    for x in 0...$game_map.width
      for y in 0...$game_map.height
        if $game_map.region_id(x, y) == region_id
          locations.push([x, y])
        end
      end
    end   
    p locations
    return locations
  end
 
  def self.find_tile(tile_range, tile_layer)
    locations = []   
    for x in 0...$game_map.width
      for y in 0...$game_map.height
        if tile_range.include?($game_map.tile_id(x, y, tile_layer))
          locations.push([x, y])
        end
      end
    end   
    p locations
    return locations
  end
 
end
Then if you set that list to a variable $game_variables[1]=[[x,y],[x,y],etc] Then you can call Control Variables: [0002:] = $control_variables[1].sample Which chooses a random XY position to spawn the event. You can even randomise the amount spawned if you want to via a loop and variable set by rand. Actually spawning the event I used a script called Copy Event by Fomar0153/Shaz/Fluffy Dragon Which you can create a prefab map to store events that you want to populate other maps with.

I want to just go to the map and have items appear randomly in places that will be with that event.
Right enough of that though. If you're trying to have multiple of those events then using a variable to control copies will sync them all together so you'll need to use self switches instead, or if self switch A-D isn't enough you'll need this script Self Data Suite By PK8
It's probably simpler with scripts, but if it doesn't have to be completely random, it is doable with events. Now that I understand a bit better what you want to achieve (though not completely, seriously, a step by step description always helps), I'd probably put the variable randomizing command into the transfer to map event. So when you leave one map, an event takes you to the map with the gold - in that event, add the variable to be assigned the random number before the transfer player command. Then the event with the gold will know which page to process, without having a parallel process running to determine it first. You can have one event in one place, changing graphics and the gold amount based on the variable, or you can have multiple (with multiple, but fixed, positions) events, which would show up or stay hidden based on the variable.

Original thread: https://forums.rpgmakerweb.com/threads/random-money-event-doesnt-work-correctly-copied-events-break-the-random.182056/