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.

Battle Formula editing

Acera

Sponsor

I've been trying (note: trying) to edit the battle formula's to suit my likings. And there's something I'm stuck with;

here's the line which I've been messing around with;
Code:
self.damage = atk + (attacker.str / 4)

to say thing simple, I'd like to have an extra variable added in there, a random number which can be -2, -1, 0, 1 or 2 (lets call that variable dmgmod for the sake of explanation)

so the code should become
Code:
self.damage = atk + (attacker.str / 4) + dmgmod

seems simple enough right? Well I can't figure out how to make a random number go from -2 to 2. rand(3) goes from 0 to 2 (right? O.o) I tried some things which work on my calculator (which uses RandInt(-2,2) which could output any number from -2 to 2. But ruby doesn't like my calculator it seems..

EDIT: I've also been messing around with the "critical strike damage modifier" it used to be
Code:
self.damage *= 2
but that didn't really fit in with my damage so I changed it to
Code:
self.damage *= 1.5
Now the problem is that I'm getting crits which are like 7.65 damage, how can I make sure that it's rounded off to either 8 (when it's 7.5 or above) or to 7 (when it's 7.49 or below)

If anyone could illuminate me, that would be appreciated  :smile:
~Acera
 
Hey
for the dmgmod problem try making
dmgmod = rand(3) - rand(3) 

for the critical you can try this
self.damage *= 3
self.damage /= 2
though there's probably other ways

hope it helps / works =)
 
Clockwise solutions should work. For the first problem though, the game will have a bias towards picking numbers close to zero if you use Clockwise solution. If you don't want that bias, try following: self.damage = atk + (attacker.str / 4) + rand(5) - 2
 

Acera

Sponsor

Code:
self.damage = atk + (attacker.str / 4) + rand(5) - 2
Code:
for the critical you can try this
self.damage *= 3
self.damage /= 2

sorry, didn't have enough time to test it enough. Just did some testing and it seems to work out perfect.

Both thanks a lot =)
~Acera
 

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