#How would you add a rng system that can account for luck such as a double luck gamepass
1 messages · Page 1 of 1 (latest)
I understand and know how to make a basic rng system, and I understand the base concept of multiplying the “rare” values to create a increase luck effect, but how would you go about dealing with the rest, the stuff that isn’t changed? And how would you get it to work cleanly?
uhhhhh
MultiplierManager module
or something
actually if ur referring to the gamepass then you should just learn MarketplaceService and check if the player owns said gamepass when the player joins the game, then multiply its luck stat accordingly
What is that?
No no the gamepass isn’t the issue that’s fine, it’s just the logic of returning a value where a 2x multiplier is used
Module that stores functions that ease adding multipliers
(its not a resource)
(you gotta make it urself)
(or you could just adapt to the system u use alr to avoid having to redo everything
Weell, do you have a script alrrady?
For rng yes
But not with luck included
And the gamepass feature is easy
I mean I don’t mind if it means it’s more efficient
Okay but how would I actually make one
Like the luck stuff
@pale yoke
aw fuck its a file
im on mob rn i can't do shit
you should prob start with adding luck stats to the plr first
and then make a single function for all 4 possible operations that you can do for changing said luck stat
an updateStat function
Ahh same lol
Well that’s easy
Wym all possible 4 operations
But then it’s like how you actually make the luck feature
addition, subtraction, multiplication, division
But how would I know what ones to multiple
But that makes no sense
If I had common of 50%
I wouldn’t multiple it by 2?
Bc then it’s 100%
no no you have to multiply LUCK by 2
not the chances
if luck is just 1.56 or sumth
...wait
no wait f luck is +x0.56 (multiplier adding to base luck) then you could just mult that by 2 without too much trouble
yes but where do i get luck from yk
Yes but how would you go about the rng part, what are we multiplying?
what about this?
local module = {}
module.items = {
["Celestial"] = 0.001,
["Divine"] = 0.01,
["Godly"] = 0.05,
["Mythic"] = 0.1,
["Exotic"] = 1,
["Legendary"] = 2.5,
["Epic"] = 5,
["Rare"] = 10,
["Uncommon"] = 26.4,
["Common"] = 54.939
}
local function chooseRarity(luck)
luck = math.max(luck or 1, 1)
local adjusted = {}
local totalWeight = 0
for rarity, chance in pairs(module.items) do
local rarityFactor = 1 / chance
local adjustedChance = chance * (1 + ((luck - 1) * rarityFactor * 0.001))
adjusted[rarity] = adjustedChance
totalWeight += adjustedChance
end
local roll = math.random() * totalWeight
local cumulative = 0
for rarity, weight in pairs(adjusted) do
cumulative += weight
if roll <= cumulative then
return rarity
end
end
return "Common"
end
module.chooseItem = function(luck)
local rarity = chooseRarity(luck)
return rarity
end
return module
u frogot teh colurs. and the prices.
Yeah ofc this is just a base example to get the idea right first
Apart from that would you say it’s good?
A effective way to do it?
uhh
luck should be a player stat managed in a completely different script
thus, remove the luck line under the .chooseRarity() functoon opening
oh also whats weight for
Well yes that was just a testing, but could I not just use “player.luck.Value”?
Like the total of all the rarities
your weighted random is correct, and seems like the luck weight is correct too, so not sure why you need to balance all the weights to sum to 100 if you're doing correct weighted random to start with 🤷
maybe just easier to visualize the chances that way 🤷
yeah, as an argument for the function
Well yeah it’s easyier to visualise them and add more later while understanding the probability
Okay thank you guys let me try all this
@cosmic root @pale yoke this is not right..., like it works kind of, if im rolling with 100k luck i shouldnt be able to get commons, really it should be all celestial right?
like the luck is way to scattered for such a high luck rating
this is 1x in the first photo and 2x in second
not much luck i see
it actually went down for how many legendarys
Yes
Same piece
Just displayed the values when I got it
But you understand what I mean? Like that scaling isn’t right
Or shouldn’t be in my eyes
well thats the thing if you add more later, it will be harder if you do this. what is the odds of 1 when the total weight is 273?
you can calculate it trivially but .. you wouldn't hardcode it to the range of 1~100
Yeah but when I say add more, I mean like rarer ones so I would only add stuff like 0.000001 or less
Nothing more then 1
But either way the luck system doesn’t really work right now
@cosmic root @pale yoke any idea how to fix the luck stuff