Jump to content




Percentage


  • You cannot reply to this topic
3 replies to this topic

#1 koslas

  • Members
  • 62 posts
  • LocationChristchurch, New Zealand

Posted 21 September 2015 - 01:45 PM

I'm working on a game, and I have it to mine something, that it works out your mining level, and what your mining, and will do math.random() to pick a number, between 1, and what it's worked out. I want to be-able to have it work out the percentage change of succesfully mining it

chance = miningRequiredLevel/miningLevel*30
randomNum = math.random(1,chance)
cPrint(randomNum.."/"..chance)

This just shows me the chance I have to mine it, with a mining level of 41, and the miningRequiredLevel at 30, chance = 21.95122, but I would like to know how to make that appear as a percentage, for another thing you can mine at level 1, with a mining level of 41 it's chance is 1, so that it's prints as "1/1" meaning a 100% success rate, I just don't understand percentages enough to be-able to make something appear as one, I did try Google it, but couldn't work it out, so any help would be much appreciated

#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 21 September 2015 - 02:10 PM

I'm confused as to what you want to do? A percentage is easy to calculate, it's just division and multiplication.

local percentage = current / maximum * 100

So if you have a max mining level of 10, and you have a current mining level of 1, percentage would equal 10%.

#3 koslas

  • Members
  • 62 posts
  • LocationChristchurch, New Zealand

Posted 21 September 2015 - 02:24 PM

Well I have it with an experience system, each time it successfully mines, it adds the amount of experience for the thing you mined, you get a certain amount of experience, and then when you reach a certain amount, your level goes up. There isn't really a max mining level you can get (It's capped at 50 atm, by slowly getting more experience) but it does
chance = miningRequiredLevel/miningLevel*25
MiningRequiredLevel = 15 for this ore, but the miningLevel will change as you level it up. It then does math.random(1,chance) and sees if it = 1 then, so I want to work out the percentage of what the chance of you getting a 1 is from math.random()
Sorry about confusing you, as you might be-able to tell, I'm not the best at explaining things very well

#4 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 21 September 2015 - 02:45 PM

So you have:

math.random( 1, miningRequiredLevel/miningLevel * 25 )

Which gives you a number between 1 and miningRequiredLevel/miningLevel * 25. You want the percentage of the time it will equal 1, which is

local percentage = 1 / (miningRequiredLevel / miningLevel * 25 )

Edited by KingofGamesYami, 21 September 2015 - 02:45 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users