Non-threaded

Forums » Advanced Editor Forum » Read Thread

Get help from the experts on variables, scripts, items, and other scary things.

Randomly placed items?

one year ago
Hi, I have a vision of a game where you explore a kingdom to find a set of items. The idea being that they're always going to be in different places--but only certain ones. So an ancient helm for example could be found in a different museum or vault or the remains of a battlefield every time, but not a random bakery.

Is this doable with scripting, and how?

Randomly placed items?

one year ago
Commended by mizal on 2/9/2023 6:24:02 PM

You can do this with variables if you use $ITEMSTATE instead of the starting page select bar on the item page.

Put the following code on the first page's page script for each item you want to randomize:

%DIEROLL := 1D4
IF %DIEROLL = 1 THEN %LOCVAR := 3
IF %DIEROLL = 2 THEN %LOCVAR := 8
IF %DIEROLL = 3 THEN %LOCVAR := 10
IF %DIEROLL = 4 THEN %LOCVAR := 21

%LOCVAR is the variable you'll use to keep track of what page the item is on. %DIEROLL temporarily stores the randomzied roll. In the above code, you're chooseing between 4 locations, pages 3, 8, 10, and 21. You'd substitue that with the page number of whatever page you want it on.

Next, go to the page script of page 3, and paste the following code:

IF %LOCVAR = 3 THEN $ITEMSTATE1 := 1

This will add item 1 directly to the player's inventory if the location generated at the start of the game was page 3. You'd paste a similar code on the page script for pages 8, 10, and 21. (Note: You have to do the page script, this won't work in a link script.)

There may be a simpler way of doing this, but this should work.