Skill - Find number of treasure in map

Hello guys.

I wanna make a skill that call a common event that give to you the amount of undiscovered treasures in the map.

I'm breaking my head thinking how to make it.

I thought to count how much treasure i have in a map (example 3) and create a event with automatic start that set Variable X to 3.
Then, every treasure that you find in the map, decrease the result.

But... in this way, i must create one variable for each maps, only for count the number of treasures. X_X

There is another way for achieve this result without creating lots of variables?
Not finished

Sorry, i touch save and it was not finished.
Not finished

What do you mean?? 😳
I think you can automate it with 4 variables.

\v[master variable] This one is the variable who will save all the data.
\v[alt variable] This one is the one we will work with.
\v[incremental] This one will save us work.
\v[map position] This one will give us information about the digit position inside master variable.

The map position variable is the most important here. This variable should change every time the user enters the map.

Example:
Map 1 = 3 | MPV: 1
Map 2 = 4 | MPV: 2
Map 3 = 9 | MPV: 3
Map 4 = 5 | MPV:4
Map 5 = 6 | MPV:5

So the master variable should be something like: 65943. Note that the valor is incremental, so if is a 6th map the valor should be placed at start like: [x]65943.

So, to take the chests opens in map 5 you should make an event branch like that:

1599592448005.png


Code:
  //Eliminate decimal characters of $gameVariables ()
  var variable = $gameVariables(5) //put here id of the \v[alt variable]
  var result = Math.trunc(variable)
  $gamevariables() = variable //put in () the id of \v[alt variable]

Now, in \v[alt variable] should give the desired value.

Take note that this aproximation only gives you up to 9 chests in each map. I think is the less variable consuming aproximation you can do.

EDIT: I just noticed this works only with the latest map. Doing a workaround to prevent it.
I think you can automate it with 4 variables.

\v[master variable] This one is the variable who will save all the data.
\v[alt variable] This one is the one we will work with.
\v[incremental] This one will save us work.
\v[map position] This one will give us information about the digit position inside master variable.

The map position variable is the most important here. This variable should change every time the user enters the map.

Example:
Map 1 = 3 | MPV: 1
Map 2 = 4 | MPV: 2
Map 3 = 9 | MPV: 3
Map 4 = 5 | MPV:4
Map 5 = 6 | MPV:5

So the master variable should be something like: 65943. Note that the valor is incremental, so if is a 6th map the valor should be placed at start like: [x]65943.

So, to take the chests opens in map 5 you should make an event branch like that:

View attachment 159874

Code:
  //Eliminate decimal characters of $gameVariables ()
  var variable = $gameVariables(5) //put here id of the \v[alt variable]
  var result = Math.trunc(variable)
  $gamevariables() = variable //put in () the id of \v[alt variable]

Now, in \v[alt variable] should give the desired value.

Take note that this aproximation only gives you up to 9 chests in each map. I think is the less variable consuming aproximation you can do.

EDIT: I just noticed this works only with the latest map. Doing a workaround to prevent it.


Wow, good idea this way. But what about if you have lots of maps? in that way you must split the variable in lots. i don't know how much is the value that you can give on a variable.

I don't know... if this is the only way, i think that i will adopt the first method and make a variable for each map... 🙁
Put <treasure> in the note of your events, and then in the common event called by the skill assign the following script to a variable:

Code:
$gameMap.events().filter(event => event.event().note.match(/<treasure>/) && $gameSelfSwitches.value([$gameMap.mapId(), event.eventId(), 'A']) === false).length

That will give you the number of treasure-note events on the current map which aren't opened yet.
Put <treasure> in the note of your events, and then in the common event called by the skill assign the following script to a variable:

Code:
$gameMap.events().filter(event => event.event().note.match(/<treasure>/) && $gameSelfSwitches.value([$gameMap.mapId(), event.eventId(), 'A']) === false).length

That will give you the number of treasure-note events on the current map which aren't opened yet.

My god, this is SUPER! I will try it! The beauty of knowing how to use javascript T_T

Is it right that the code ends in this way "false).length" in your code-tab, right?
Yes. You're basically filtering the list of events on the map by which ones have "<treasure>" in their note AND have their self switch A off, and then returning the length of the resulting array (which is the number of unopened treasures). Then you can assign that to a variable and use \v[variable id] in a show text command to say how many unopened treasures there are.
Yes. You're basically filtering the list of events on the map by which ones have "<treasure>" in their note AND have their self switch A on, and then returning the length of the resulting array (which is the number of unopened treasures). Then you can assign that to a variable and use \v[variable id] in a show text command to say how many unopened treasures there are.

You. Are. Amazing. I will try it this evening. Thank you so much, all of you T.T
You're more than welcome. Always glad to be able to help people save on their variables. 🙂
You're more than welcome. Always glad to be able to help people save on their variables. 🙂

works perfectly, you are great! thank you so much!! T.T

Original thread: https://forums.rpgmakerweb.com/threads/skill-find-number-of-treasure-in-map.127002/