How would I calculate attack hit percent
How would I calculate attack hit percentage chance?
Mar 5, 2021 at 11:00pm UTC
I'm having a little trouble with figuring out how to go about calculating hit percentage chance for an attack. So lets say I have an attack, and I want it to hit 90% of the time, and miss the other 10%, how would I do that? Is it simply just:
attackChance % 90;
Im confused on how this is written in code.
Last edited on
Mar 5, 2021 at 11:01pm UTC
Mar 5, 2021 at 11:27pm UTC
Use a random number generator to generate integers from 0 to 9 ie ten integers and assign them to some variable, hit_no, say.
When hit_no = 0, that's a miss, and for any other hit_no it's a hit.
Mar 6, 2021 at 12:24am UTC
Perfect, thank you, I was making it way more complicated than it needed to be.
Registered users can post here.
Sign in or register
General C++ Programming
© cplusplus.com, 2000-2020 - All rights reserved -
Spotted an error? contact us