Help Designing a randomized search event

Yummytiger22

Villager
Member
Joined
May 25, 2012
Messages
17
Reaction score
4
First Language
English
Primarily Uses
Hello,

I was hoping someone with a little more skill might look over my current event design and tell me if it is the best way to implement this idea.

Overall Event Goal: To create a series of 10 search locations, with 5 of the 10 locations randomly containing treasure. As the player searches each location, a NPC character also is searching other locations. I've included the non-parallaxed version of the map below with some quick blobs to indicate potential search locations (in-game, there is a animated sparkle).

My plan was to create a series of 10 switches named DM_t1 through DM_t10 to represent treasure, and DM_s1 through DM_s10 to represent searched. So, at the beginning of the event, I would randomly select 5 events and flip the corresponding "DM_t#" switch. Then, the player would move to a location, and search. Once searched, the corresponding "DM_s#" search switch would flip. 

As this is going on, there is an NPC sprite on the map. At each location, when the player searches, the NPC sprite is randomly moved to an unsearched location. The NPC then searches that location. In the end, the NPC and the player will have each search 5 locations.

1. So, I'm not a programmer by any means, but this is how I was thinking no trying to implement this. At the start, select a random number between 1-10. If the "DM_t#" switch for that number is not flipped, then turn it on, if it is already on, select a new number. Do this until 5 switches are on.

2. The player moves to a location, searches and gets the results. After that, a random number is selected again. If the "DM_s#" switch is not ON, then move the NPC character to that location and flip the switch (adjusting their treasure variable in the process if there is treasure). Do this until the number randomly selected corresponds with a location that has not been searched yet.

I think this will work, but I also think I am doing this terribly inefficient. How long is it going to take for the random number system to randomly select the last location? So, the player has searched 5 locations, the NPC 4, meaning only one is left unsearched. Based on this system, the game has to wait until it randomly selects that 1 number (10% chance). Additionally, this method requires setting up a lot of conditional branches as I go. I don't have a problem with that, but again, I think there is probably a easier solution that I am simply overlooking (I'm a noob, what can I say :) ).

Here is a link to a simple picture, not sure it is even really necessary, but I thought I would include it: http://i.imgur.com/7eGIdkz.jpg

Thanks in advance for any help or ideas! I really appreciate it!

YummyTiger
 

KanaX

Just being a mouse
Veteran
Joined
Apr 3, 2013
Messages
1,463
Reaction score
1,287
First Language
Broken English.
Primarily Uses
N/A
The way I understand it, is that you want 5 of those 10 holes to have treasure but you want it to be at random holes each time, right?
I need this clarification to start thinking of some ideas.
 

Kvich

Veteran
Veteran
Joined
Oct 6, 2014
Messages
89
Reaction score
19
First Language
Danish
Primarily Uses
The way I understand it, is that you want 5 of those 10 holes to have treasure but you want it to be at random holes each time, right?

I need this clarification to start thinking of some ideas.
I think the thread starter wants the 5 of the 10 holes to be different on each play through.

The way I would do it may be something like this:

Designate a variable to a "RNG" (Random Number Generator)

Then another variable to count the treasures applied

I would then for the start of the treasure hunt set the event that distribute the treasure locations randomly up a bit like this:

Treasure Roll.png

Pardon me for not doing all 10 conditional branches, but I hope you get the basic idea. :)

The Jump to Label would make the event rerun until it gets 5 different applied treasure locations, and then turn on self switch A, stopping the event.

I would do a bit the same with the NPC looking for treasure

Roll the RNG, if the number rolled matches a switch that's already turned on (searched) reroll using the jump to label.
 

Yummytiger22

Villager
Member
Joined
May 25, 2012
Messages
17
Reaction score
4
First Language
English
Primarily Uses
Thanks for the replies!

Yes, Kanax, I was aiming to have the treasure be in different holes each time. The player will do this event a total of three times throughout the game, and I want the treasure locations to differ each time.

Kvich, thanks! That is kind of what I was thinking, although you have it in more detail. My original question remains though. So, the system needs to keep creating random numbers over and over again until it finds a number not used? For the first randomization (applying the treasure), it has a good chance of hitting an unused number, but when looking at the NPC location and search, it seems like for the later searches, this might have to run quite a few times to hit that final number? So, after the player has searched 4 locations, there are only 3 more possible numbers, then after searching 5 locations, there is only 1 number free, 10% chance of hitting that number per roll. Otherwise, it would simply be running through the event over and over trying to roll that last number.

Does that make sense? Maybe this all goes so quickly that it is irrelevant. I have not set up the actual event yet. I was just making sure this is the most efficient way of doing something like this.

Thanks!
 

Kvich

Veteran
Veteran
Joined
Oct 6, 2014
Messages
89
Reaction score
19
First Language
Danish
Primarily Uses
This is the most simple way of doing it I can think of, and I'm not sure how long it will take to find unused numbers, and if it's a lag that the player will notice.

You could, make it (more time consuming for you) so you roll once the RNG between 1 and 10, set up the 10 conditions, reroll between 1 and 9, and have 9 new conditions in each of the 10 firsts. that will turn on the 2nd treasure switch between 1 and 10 minus the switch that's already turned on, and do the same in now the 90 different conditional branches with the 8 remaining switches to see which is turned on next... A lot of lines to go through, if one have a mistake..

For the NPC, it's on average 10 rolls to find the only suitable number for the last treasure location, and if each roll takes a frames time, it's on average 10 frames, barely noticeable I think. :)
 

KanaX

Just being a mouse
Veteran
Joined
Apr 3, 2013
Messages
1,463
Reaction score
1,287
First Language
Broken English.
Primarily Uses
N/A
Say that each "hole" has an event on it. Since you have ten holes let's say that the event ids are 1-10
Create a second page on each one with the conditional "Self switch A is on". The first page is for when the event is empty and the second when it has treasure.

Create 11 variables; One for each hole and one for the 5-treasure limit. Let's say that variables 1-10 are named a-j and the 11th one is named "limit"

Make a parallel like this:

The call script actually works like this: $game_self_switches[[map id, event id, "switch"]] = value You can activate/ deactivate a self switch of an event from another event. I find it extremely useful, because I HATE making new switches. But you can easily replace the script call with switches (and of course change the conditional for the second pages to the switches).

I tested it and it works.

For when the player searches a hole you need a third page that will say "Already searched". Set a conditional for that page (either switch, or self switch).
When the player activates then event to search a hole place the text "Got treasure/empty" and everything else you need after that turn on the switch/self switch for the third page and call a common event.

The common event should be like this: (event 17 is the searcher event)

do the same for 2-10 (above repeat)

add a Label:exit at the end
move_toward_character($game_map.events[eventid]) makes the searcher event move towards the hole.

Don't worry about process time, I doubt it'll take more that 30-40 frames every time. You basically already got it, I just hope we made it a little bit easier.
 
Last edited by a moderator:

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,230
Reaction score
3,072
First Language
English
So basically what you are doing is assigning a random number to each hole first, and then during the searching process, you're just grabbing that number and telling the player what happened.

Using only events, this would probably be a little convoluted because there isn't really a way to simply take 10 numbers, shuffle them around, and then assign variables for each one.

Personally I would just use a script call for the actual number assignment

vars = [10,11,12,13,14,15,16,17,18,19]arr = [1,2,3,4,5,6,7,8,9,10].shufflearr.each_with_index do |num, i| var_id = vars $game_variables[var_id] = numendSo the first line is an array of variable ID's that you want to use (does not need to be contiguous)Second line is the numbers 1 to 10 randomly shuffled.

And then you just go through each number and assign them to a variable.

Now you just need to determine which hole will use which variable and have each hole check all of the 10 conditions. You might use an 11th variable to store the actual number that you picked and then call a common event to run the search process.
 
Last edited by a moderator:

KanaX

Just being a mouse
Veteran
Joined
Apr 3, 2013
Messages
1,463
Reaction score
1,287
First Language
Broken English.
Primarily Uses
N/A
Yeah, or Tsukihime can come and annihilate all that convoluted eventing we showed you :p

I tried using script calls with arrays, but I didn't know about the shuffle mechanic.
 

Kvich

Veteran
Veteran
Joined
Oct 6, 2014
Messages
89
Reaction score
19
First Language
Danish
Primarily Uses
Yeah, or Tsukihime can come and annihilate all that convoluted eventing we showed you :p

I tried using script calls with arrays, but I didn't know about the shuffle mechanic.
Yeah..

Well for a moment we did feel all high and mighty. ;)

And personally I didn't even know about that type of script calls, I better reread the RPG Maker ABC again. :)
 

Yummytiger22

Villager
Member
Joined
May 25, 2012
Messages
17
Reaction score
4
First Language
English
Primarily Uses
Wow, you guys are awesome. Although, my heads hurts a bit right now trying to wrap my mind around all of this. I think it will be clearer once I start trying to implement it.

If I understand what Tsukihime is saying, I am assigning a number to each hole, then throwing the 10 numbers into an array (kind of like a pot). Then when the event starts, 5 numbers are pulled from the array and assigned treasure? When the player goes to the designated hole, the game checks the variable and determines if this one had treasure or not?

My question is, during the NPC assignment phase, when I move the NPC to a random hole to search himself, do the numbers in the array get smaller? Meaning, if the player searches hole "2", does that number then get removed from the array, leaving (1, 3, 4, 5, 6, 7, 8, 9, 10)? If so, this would be perfect, as after the player searches 5 holes, and the NPC searches 4, only 1 number would be left in the array.

Of course, I may simply be rambling here with no real understanding of what is going on. I've gotten a grasp of RPG Maker and eventing, but I'm kind of at that "knows enough to be dangerous" stage.

Either way, you guys rock! Thank you for your help so far. I can't wait to try and implement this when I get home.
 

KanaX

Just being a mouse
Veteran
Joined
Apr 3, 2013
Messages
1,463
Reaction score
1,287
First Language
Broken English.
Primarily Uses
N/A
The way Tsuki's script call works, is that now your 10 variables instead of having to go through a random value every time, the be assigned to a value that will be never repeated.

To make it clearer, you have ten variables with only TEN values to available for them, unlike before where you had ten variables, EACH having ten possible values.

You have v1, v2,... v10 and 1, 2, 3,.. 10. With the shuffle ONLY v3 will take the random value 7 and ONLY v5 will take the random value 10.
So in the end you will have a result like this:

v1 = 4

v2 = 9

v3 = 7

v4 = 5

v5 = 10

v6 = 6

v7 = 3

v8 = 1

v9 = 2

v10= 8

Another way to look at it is like this:

1 = v8

2 = v9

3 = v7

4 = v1

5 = v4

6 = v6

7 = v3

8 = v10

9 = v2

10 = v5

Which Is the random order you wanted! No randomness from this point on.
If you would like me to make you sample event, tell me.
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,230
Reaction score
3,072
First Language
English
If I understand what Tsukihime is saying, I am assigning a number to each hole, then throwing the 10 numbers into an array (kind of like a pot). Then when the event starts, 5 numbers are pulled from the array and assigned treasure? When the player goes to the designated hole, the game checks the variable and determines if this one had treasure or not?


My question is, during the NPC assignment phase, when I move the NPC to a random hole to search himself, do the numbers in the array get smaller? Meaning, if the player searches hole "2", does that number then get removed from the array, leaving (1, 3, 4, 5, 6, 7, 8, 9, 10)? If so, this would be perfect, as after the player searches 5 holes, and the NPC searches 4, only 1 number would be left in the array.
I approached the problem like this


Say you have 3 holes (with variables 1, 2, and 3 assigned) and then you give each variable a random number


Hole 1 = 3


Hole 2 = 2


Hole 3 = 1


When you search Hole 1, you will get number 3.


Then the NPC searches Hole 2 and gets number 2.


Now, if you search hole 3, you will get the last number that hasn't been picked.


The next problem is how to make it so that checking the same hole will yield nothing.


A simple solution is to make it so that when a hole is searched, you set the variable to 0 or something. Now, you can just add a condition that will say "sorry this hole has been searched, try again" when the variable equals 0.
 

Xer Savril

Warper
Member
Joined
Mar 24, 2015
Messages
1
Reaction score
0
First Language
English
Primarily Uses
... I just lost everything that I wrote T_T.

Ok, I have a solution that I feel seems more intuitive and easier to directly implement than the above (though I feel like they're ultimately the same - mine is perhaps more 'readable/implementable' but less efficient).

As the above posts have stated, the way to go is to label the 10 holes with fixed numbers, and then randomly assign 5 of them treasure. To me, the above code is 'confusing' in the sense that it has two sets of numbers - the indices where you place the values, and the values themselves being numbers. Instead, I'm going to shuffle a list of 10 numbers, and simply declare that the first five will contain treasure. Since the list is shuffled randomly, the first five numbers will be random, and thus the treasure is randomly distributed. So to do that, we can do...

order_id = [1, ..., 10].shuffle

order_id.each_with_index do |num, i|

  if i <= 5 then

    $game_variables[num] = true

  else

    $game_variables[num] = false

  end

end

So $game_variables[hole_id] will contain true if it has treasure, and false otherwise. If you're worried about overwriting the contents of $game_variable, simply add a 'current_size = $game_variables.length' and instead of assigning it to $game_variables[num], you assign the true/false values to $game_variables[current_size + num].

So what this means is that for your previously labeled events/holes from 1 to 10, all you need to do is check whether $game_variables is true or not in an 'if - then' statement. For example...

Hole 2

if $game_variables[2] then

  Show Text - You've found treasure!

  $game_variables[2] = false (so it doesn't contain treasure any more)

else

  Show Text - No treasure here.

end

The NPC assignment afterwards can be done in a multitude of ways. But for the sake of simplicity, I'm going to assume that the NPC picks exactly -one- hole after the player searches one, so the two alternate. Thus, in order to keep track of holes searched, you should make an array to keep track of that, say...

holes_not_searched = [1, ..., 10]

So in the above event where a player picks a hole, it would be modified to something like...

Hole 2

------ This part doesn't need changing, but it needs to be at the top so it occurs first

if $game_variables[2] then

  Show Text - You've found treasure!

  $game_variables[2] = false (so it doesn't contain treasure any more)

else

  Show Text - No treasure here.

end

------ This is the new part underneath

if holes_not_searched.include?(2) then

  holes_not_searched.delete(2)

  Call Event - NPC randomly searches through the remaining values of holes_not_searched.

end 

Of course, the details would still need working out. The thrust of what I wanted to emphasize was that choosing to make the first five elements of a shuffled list contain treasure allows us to have the values of our array only require 'true/false', instead of using a second set of numbers (Now that I look back, I'm not sure why a second set of numbers is necessary or how it's going to be utilised effectively). Well, that and the fact that you need an additional procedure for the NPC assignment - keeping track of holes searched in an array and then perhaps calling a common event based on what hole you randomly pick out of the remaining ones (since unless I'm missing something, I don't feel any of the above posts addressed that particular issue).
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Love it when someone confuses "RPG Maker (or script/plugin) has a bug" with "I didn't set it up right and it's not working as I want (or gives an error)"
Is animation really as hard as I think it is?
Out of sudden, snow. Everywhere.
Blech. I hate coming up with stories. Making gameplay is fun but coming up with lore and reasons for these areas/mechanics just makes me sleepy.

Forum statistics

Threads
94,572
Messages
921,999
Members
124,440
Latest member
YukiYuki
Top