Crit Rate and how to creat a function for it.

so currently i have this battle sequence:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
    void FightStart()
{
        ypdamt = ypatk;
        ypdamb = ypdef;
        epdamt = epatk;
        epdamb = epdef;

        int yHpNew = yhp;
        int eHpNew = ehp;
        
        while (yhp >= 0 && ehp >= 0)
        {
            int yBattleRandom = rand() % 71 + 70;
            int eBattleRandom = rand() % 71 + 70;
            int yNewNum = yBattleRandom;
            int eNewNum = eBattleRandom;
            int ypdamf = (ypdamt*yNewNum)/ypdamb;
            int epdamf = (epdamt*eNewNum)/epdamb;
            
            
        cout << "you hit your enemy for " << ypdamf << " damage." << endl;
            eHpNew -= ypdamf;
        cout << "your enemy now has " << eHpNew << " HP left" <<endl;
            
            
        if (eHpNew <= 0)
        {
            cout << "you have slain your enemy." << endl;
            break;
        }
            
        else
            
        {
    
        
        cout << "your enemy hit you for " << epdamf << " damage." << endl;
            yHpNew -= epdamf;
            cout << "you now have " << yHpNew << " HP left" << endl;
            
            
        if (yHpNew <= 0)
        {
            cout << "you are dead." << endl;
            break;
        }
        else
        {
        
        }
        }
    }
}


the randoms are for basically randomizing the damage output. i need to tweek it a bit to get it right but yeah any way. my program creats a stat for crit rate. i think i decided that i wanted crit rate to max out at 999. should i create a new random number and say something like:

1
2
3
4
if (critRate > somenumber)
{
int newrandomnumber rand() 100 + 1
}


and have it basically guess itself. if that makes sense. i would write it to have newrandomnumber somehow choose a few numbers (depending on how high the crit rate is) and if it guesses correctly when generating a random number, then you do a crit strike.

im not really sure how i should go about doing this.
Topic archived. No new replies allowed.