Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Gold +/- random amount, and round up?

Okay, so I was looking into the script of the default battle system and I found this on line 150:
Code:
        gold += enemy.gold
Presumably, this tells the game how much gold to give me after I kill the enemy group.
Is there a way to do something somewhere along the lines of...
Multiply enemy.gold by a random number between 0.8 and 1.2, then round up to nearest whole number?
Example of what I want in the outcome:
I kill an enemy who's "GOLD" value in the database is 100.
I want the game to give me a random amount of gold between 80 and 120,
or if the enemy was supposed to give me 73 gold, then an amount between 58.4 (round to 59) and 87.6 (round to 88).
Is there a way to do that kind of a calculation in ruby?
Am I even looking at the right part of the script for this?
If someone could let me know, that would be great.

EDIT:
To be more specific about "0.8 and 1.2", it would probably be more like a number chosen from an array.
I don't need to be multiplying things by 0.83657 or something like that.
So like... [0.8, 0.9, 1, 1.1, 1.2] or something.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top