I'm just curious about something. I always find this at games.
For example you have a monster called X.
X's loots are item1, item2, item3.
item1's probability of being dropped by X is let's say, 16%.
item2 is 0.76%.
item3 is 25%.
How will you code it?
If you have 0.76% chance of getting an item, how will you implement it?
Started by mr_skyflakes21, Jul 22 2010 02:50 AM
6 replies to this topic
#1
Posted 22 July 2010 - 02:50 AM
|
|
|
#2
Posted 22 July 2010 - 03:12 AM
I just found the solution:
1. randomize a value,
2. if the value is LESS THAN OR EQUAL to the percentage of the item, it will be dropped.
thanks for making my mind curious from time to time. :D
1. randomize a value,
2. if the value is LESS THAN OR EQUAL to the percentage of the item, it will be dropped.
thanks for making my mind curious from time to time. :D
#3
Posted 22 July 2010 - 03:49 AM
mr_skyflakes21 said:
I just found the solution:
1. randomize a value,
2. if the value is LESS THAN OR EQUAL to the percentage of the item, it will be dropped.
thanks for making my mind curious from time to time. :D
1. randomize a value,
2. if the value is LESS THAN OR EQUAL to the percentage of the item, it will be dropped.
thanks for making my mind curious from time to time. :D
Yeah. But don't make it randomize if the value is generated by user.
If user generated number is less than or equal to the percentage, it drops. You can do it other way around also.
#4
Posted 23 July 2010 - 10:03 AM
generate a random number between zero and one. if the probability is above (or "above or equal"? not sure, but shouldn't matter for sufficietly many digits in the random number.) the random number, the event occurs.
edit: accidentally wrote below instead of above.
edit: accidentally wrote below instead of above.
Edited by anotheruser, 24 July 2010 - 02:10 AM.
#5
Posted 23 July 2010 - 09:30 PM
mr_skyflakes21 said:
I just found the solution:
1. randomize a value,
2. if the value is LESS THAN OR EQUAL to the percentage of the item, it will be dropped.
thanks for making my mind curious from time to time. :D
1. randomize a value,
2. if the value is LESS THAN OR EQUAL to the percentage of the item, it will be dropped.
thanks for making my mind curious from time to time. :D
In your example.
Item 1 16%
Item 2 0.76%
Item 3 25%
If you're random number came up .001 (0.1%) then it's less than your cutoff value for Items 1,2 And 3.
Now that's fine if you wish to give all 3 Items, but you may want to add some checking that they get only the lowest % item.
#6
Posted 24 July 2010 - 09:34 AM
If it's dead, why doesn't it drop all items?
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics
#7
Posted 24 July 2010 - 10:35 AM
Because it only carries 1 item. And it has x% chance of carrying that item.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









