Seedspreaderent

Villager
Member
Joined
Jan 5, 2022
Messages
17
Reaction score
1
First Language
English
Primarily Uses
RMMZ
Hey all,

I am trying to make a common event for random fetch quests. To do this, I want to set the item needed to be random. Usually I would just set my temporary variable to the equal the item number. However, I do not want to include all item numbers. How would I set a JS function to be between several number arrays? (eg. 1-60, 70-90, 61, 65).
 

JGreene

Veteran
Veteran
Joined
Oct 24, 2015
Messages
456
Reaction score
373
First Language
English
Primarily Uses
RMMV
You can use an array in a script call:

Code:
var x = #
var itemchoice = [1, 2, 3, 4, 5];
var index = Math.randomInt(itemchoice.length);
var questitem = itemchoice[index];
$gameVariables.setValue(x, questitem);

  1. Set x to the game variable you wish to store the result under
  2. Inside the square brackets [ ], type each number followed by a comma. It will be a long list, but it's guaranteed to work.
There is also a method called splice in JavaScript. If you wish to look into how to utilize it, feel free. This array, set up correctly, will function the same.
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
4,647
Reaction score
3,779
First Language
EN
Primarily Uses
RMMZ
In general I think I'd consider an array, too. However, unless you have a lot of gaps, this shouldn't be too bad without scripting. You can roll a random number for the full range, and add values to bump it over the gaps you want to skip.

For your example:
(eg. 1-60, 70-90, 61, 65).
The full range is 60 + 21 + 1 + 1 = 83, with only two gaps:
  • 62~64 inclusive => +3 (62 -> 65) if rolled value ≥ 62;
  • 66~69 inclusive => +4 (66 -> 70) if rolled value ≥ 66.
E.g.

◆Control Variables:#0001 = Random 1..83 ◆If:#0001 ≥ 62 ◆Control Variables:#0001 += 3 ◆ :End ◆If:#0001 ≥ 66 ◆Control Variables:#0001 += 4 ◆ :End ◆Text:None, None, Window, Bottom : :Random pick: \v[1]
 

Latest Threads

Latest Profile Posts

World building was one of the main reasons i got in to game dev, but geeez, it eats up the time... This is a WIP from today before i call it a night.. maybe 80% finished.
maps.png
Dial_000_f002_show.jpg
Wohoo, its finished. It took some time but slowly I get used to this retro 90s anime style.
Now I just have to finish the other 37 frames. for the first dialogue... oh lord, what have I done :LZSlol:
(and if you are confused: yes, I place various eastereggs about other great cyberpunk games/videos/books that I like in my game ;) )
Has anyone watched the movie "Tiny Toons: How I Spent My Summer Vacation"? It is a cartoon and it is freaking hilarious. We watched that movie so many times when our kids were growing up. Thankfully it has a lot of adult humor to keep the adults entertained that the kids don't really get.
Here's some more weapon icons for the Wastes I've finished recently. Some are mine, some are icons that @Ninjakillzu originally made (the AK variants, the Thompson, the Glock, the M16 variants), but edited by me with permission.
1686428693206.png1686428742838.png
Still working on balance issues for my almost-out Cube Trail demo... Boss balance is no joke.

Forum statistics

Threads
131,777
Messages
1,223,288
Members
173,557
Latest member
ykokeb1
Top