|Topic was automatically imported from the old Question2Answer platform.
I’ve googled quite a bit and can’t wrap my head around it. My goal is to have the probability of an item generated that is dependent on player score. How would I even begin this? Does anyone have experience with this in their game?
Edit: Apologies for the delay and being vague. I had a family emergency I tried to code through but just couldn’t. I would like a max probability. I’ll see if i can use LuminousNutria’s code with what i already have and see if it works. I am currently spawning an object that is randomly picking an object amongst an array. I want the probability to be between an array of items. The probability is specific to whether one item spawns or another. So the higher score would be more likely to spawn a negative item. That said now it is equal between a good or a bad item meaning the baseline is a coin flip. I’d like to keep that the odds at a baseline that is even between the array of items but as the player gains points that changes.
I’ve gotten further along. The following below works for a coin flip situation
var rand_index = randi() % options.size()
if randi()%101+1 <= prob:
In this example a case statement in which
prob is set to relative to the player’s score will be simple enough in selecting between 2 items so far only good and bad. However using that logic for a player chest for instance in which a wide array of items can be selected. I’m not sure how to implement.
How about some simple if else conditions?
codevanya | 2019-01-17 18:39
add Timer and put random generator of 1 or 0. If it give 1 then emit signal to spawn mob if 0 then no.
Zippelin | 2019-01-17 19:14
Hi, Could you give us more details? Do you want a max probability for the item? or can it reach 100%? Usually, i would calculate probability with a function depending of score with asymptote to the max probability (for example
max_prob-exp(-score) will be near 0 for low scores, and near max_prob when score is high). Then, i would use a random number between 0 and 1, and if that number is less or equal than the number generated by the probability function, you generate the item. If not, you dont. Something like this?
p7f | 2019-01-18 11:47