Jump to content

Randomness in stores


temnix

Recommended Posts

I would like some, but not all stores carry a random quantity of a certain item for sale. Here is the code I'm using:

COPY_EXISTING_REGEXP GLOB ~^.+\.STO~ ~override~

PATCH_IF (SOURCE_SIZE > 120) THEN BEGIN

PATCH_IF (RANDOM (3 3)) THEN BEGIN  

PATCH_IF (RANDOM (4 4)) THEN BEGIN

ADD_STORE_ITEM PLATIN_# LAST #0 #0 #0 ~NONE~ #74 LIMITED 

END

PATCH_IF (RANDOM (3 4)) THEN BEGIN

ADD_STORE_ITEM PLATIN_# LAST #0 #0 #0 ~NONE~ #53 LIMITED 

END

PATCH_IF (RANDOM (2 4)) THEN BEGIN

ADD_STORE_ITEM PLATIN_# LAST #0 #0 #0 ~NONE~ #38 LIMITED 

END

PATCH_IF (RANDOM (1 4)) THEN BEGIN

ADD_STORE_ITEM PLATIN_# LAST #0 #0 #0 ~NONE~ #12 LIMITED 

END

END
END
BUT_ONLY

There is randomness within randomness here. The first check should patch every third store, but within that selection I'm not sure about using RANDOM. There are three of these checks in a row with the same maximum number (range size), and hopefully the same roll will be used for them. That is my intention. I don't want separate rolls that would put different amounts of the item in the same shop. The reason I have this extra randomness is because, apparently, there is no way to insert a randomness in the "stock" parameter of ADD_STORE_ITEM. Ideally I would put a roll there between about 10 and 80 and let every store be different, but that doesn't seem possible, so there is an imitation here. But the results are wrong. All of the stores get the item and all of them get 74 pieces, even though this is the (RANDOM (4 4)) amount, the least common roll in the 4 range. Why is this? Is there a better way?

 

Link to comment

This isn't how RANDOM works. (It's nothing like the RandomNum() command in BCS scripting.)

(i) RANDOM (x y) generates a random integer between x and y. So RANDOM (4 4) always returns 4, for instance.

(ii) Each time you call RANDOM you get a new random number. If you want to use the same random number in multiple places, assign it to a variable and then check the variable. For instance (not tested),

SET randvar=RANDOM(1 3)
PATCH_IF randvar=1 BEGIN
[do something]
END ELSE 
PATCH_IF randvar=2 BEGIN
[do something else]
END ELSE BEGIN
[do something else again]
END

will do one of three things with equal probability of each.

(iii) In any case, PATCH_IF (RANDOM (x y)) THEN BEGIN ... END will evaluate the ... if RANDOM (x y) is true. And WEIDU treats any integer except 0 as 'true'. So this will evaluate the ... whenever x and y are >0.

In addition, the code you posted will add items into bags of holding, which I suspect isn't what you want. 

Link to comment

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...