Right guys, here's a real challange for you: (please only answer if you actually know what you're on about here).
For part of the game I'm currently working on, there's an area called mystery box. This box appears once a day, and once opened, will reveal a randomly chosen item.
Catch 1:
There is a list of possible items that the box could open to reveal, the first of which is highly probable and the last of which is the least probably (so the percentage chance of getting an item is determined by it's place in the list).
Catch 2:
Before you open the box, you have to pay. You can choose how much money you give, and this affects the probability of getting certain items! Giving the maximum amount (say, 1000 gives you the highest probability of getting an item of low probability in the list, though still offers a small chance of getting something of higher probability and less worth whilst paying the smallest amount (1) decreases the probability of getting a highly improbable item and more or less ensures getting a more probably one though there is still a possibility of gaining an improbably item).
Catch 22:
Is a pretty neat piece of work
It was easy before catch 2 came along... does anyone have any idea how I might achive this???
Many thanks for taking on the challange!
Offline
have 2 lists
Items in box
Temp.
have a variable
% of max cash entered
set var1 to ( (length of Items in box) / (% of max cash entered) )
set var2 to ( (length of Items in box) * (var1) )
set var2 to ( (length of Items in box) - (var2) )
*Temp list contains all probibilty (percent) per item*
set var1 to 0
repeat ( round (var2 - 0.5) )
| change var1 by 1
| set var3 to ( round var2 - 0.5 )
| set var3 to (var2 / var 3)
| set var3 to (var3 * var1)
| repace item var1 of temp with var3
|__________________
Think that should help
Offline
Johnnydean's method is correct. That is the way most games with this kind of feature do it. Its a typical use of arrays (lists in scratch).
What I would do exactly is first take the money in and then use that to alter the propability of getting the rare item. So say 100 gold was added, increase the odds of getting the rarer items and decrease the chance of more common items.
When the probability is assigned all the probability should add to 100. Each number represents a item on a list. Create a new item on the list with all the items that may be won and give them the number of items equal to their probalility. So with a 10% chance to get a dragon tooth you would have 10 items on the list saying dragon tooth. Then pick a random item from the list from 1 to 100.
Last edited by archmage (2011-02-11 11:26:53)
Offline
Updated project, fixed math and auto-start calculations here
Offline