RPG battle system

im tring to get the combat system the way i want it the goblin is to attack randomly but when he attacks its always the same 2 numbers for attack how do i make it more random every time?

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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<ctime>
using namespace std;
int main()
{
    int space;
    int player1;
    //monster always attaks first
    
    ///////weapons & Damage///
    double Flint_Gun = 5;
    double Small_Dagger = 3;
    double health = 70;
    double Wooden_stick = 3;
    double Gobling_health = 30;
    double health_potion = 10;
    double bonus_10 = 10;
    ///i ran the program no loss of data found in my program.
    unsigned Gobling_Damage = time(0);
    //////////////////////////
       
     
       
        while (Gobling_health >= 1 && health >= 1)
       
       
        {///master while for combat

    srand(static_cast<unsigned int>(time(0)));      
    
    cout<<"  your health "<<health<<endl;
    cout<<"  the Gobling "<<Gobling_health<<endl;
 
    srand(Gobling_Damage);

    Gobling_Damage = (rand() % 5) + 1;
    
    cout<<"  The Goblin did "<<Gobling_Damage<<" Damage"<<endl;

    health = health - Gobling_Damage;
   
    ///1 spaces////////////////
    space = 1; 
     
        while(space <= 1)
{
            cout <<""<<endl;
            space++;
}     
    ///////////////////////////
   
    cout<<"  your health "<<health<<endl;
    cout<<"  the Gobling "<<Gobling_health<<endl;
       
    system("pause");
       
    ///1 spaces////////////////
    space = 1; 
     
        while(space <= 1)
{
            cout <<""<<endl;
            space++;
}     
    ///////////////////////////
   
    char Attack;

        //condition that player1 dies in fight
        if(Gobling_health > 0 && health < 1)
        {
            cout<<"  Your killed lolz sorry"<<endl;
       
        system("Title        Game Over          ");
       
        system ("pause");
        return 0;
        }
   
    cout<<"  pick a weapon and fight or he will kill you!"<<endl;
    cout<<"  S:Small Dagger attack 3"<<endl;
    cout<<"  F:Flint Gun attack 5"<<endl;
    cout<<"  W:Wooden stick 2"<<endl;
    cout<<"  P:health bottle"<<endl;
    cout<<"  pick or die: ";
    cin >>Attack;
   
    ///2 spaces////////////////
    space = 1; 
     
        while(space <= 2)
{
            cout <<""<<endl;
            space++;
}     
    ///////////////////////////
   
    //these are the condition of fighting
        if(Attack == 'S' || Attack == 's')
        {             
    Gobling_Damage = (rand() % 10) + 1;   
    Gobling_health = Gobling_health - Small_Dagger;
    cout<<"  Small Dagger Attack dealed 3 Damage! "<<endl; 
        }
     
       
       
        if(Attack == 'F' || Attack == 'f')
        {         
    Gobling_Damage = (rand() % 10) + 1;
    Gobling_health = bonus_10 + Gobling_health - Flint_Gun;
    cout<<"  Flint Gun attack dealed 5 Damage! "<<endl; 
    cout<<"  you hit the monster but bullets make it Stronger!!!"<<endl;
        }
     
       
        if(Attack == 'W' || Attack == 'w')
        {         
    Gobling_Damage = (rand() % 10) + 1;
    Gobling_health = Gobling_health - Wooden_stick;
    cout<<"  Wooden stick attack dealed 3 Damage! "<<endl; 
        }
           
           
    if(Attack == 'P' || Attack == 'p')
        {         
    Gobling_Damage = (rand() % 10) + 1;
    health =  health + health_potion ;
    cout<<"  Monster Attacked you but"<<endl;
    cout<<"  health bottle gave you 5 health! "<<endl; 
        }
       
    ///5 spaces////////////////
    space = 1; 
     
        while(space <= 5)
{
            cout <<""<<endl;
            space++;
}     
    ///////////////////////////


    //ondiction that player1 wins
          if(Gobling_health <= 0 && health > 0)
        {
         
        system("Title        The Tale of Argoonia          ");
        system("Color 3"); 
                 
  cout<<"  you did it "<<player1<< " the town of Argonia is safe but for how long"<<endl;
    cout<<"                          The End"<<endl;

  ///2 spaces////////////////
    space = 1; 
     
        while(space <= 2)
{
            cout <<""<<endl;
            space++;
}     
    ///////////////////////////

 cout<<"  Tale of Argonia 2:The Wizzerd and the Demon Bull King coming     soon!!!"<<endl;           
 
  
                                                
    system ("pause");                         
    return 0;                                    
                                                   
          }                                        
   
            }///master while for combat end


}
Last edited on
One problem is that you are seeding with srand() every time in the loop. You should only seed once, at the beginning of the program. Also, is that static_cast necessary?
no static_cast is not necessary but nope it still giving the same 2 random numbers each time the monster attacks
Last edited on
Take out this line:
srand(Gobling_Damage);

Like I said, you should only seed once, at the beginning.
thanks mahlerfive i got it to work but just one more question, i'm using dev c++ to make a text base rgp and i was wondering what would be the best way to store items like gold and potions using an array ect..?
You probably want to use a structure to store the player's inventory. Let's say you want to store the number of health potions, the amount of gold, and which weapons the player has. You could make a structure like this:

[code=c++]
struct inventory {
int gold;
int potions;
bool stick;
bool dagger;
bool gun;
};
[/code]

If you don't know how to use structures, now would be a good time to learn, just google c++ structures.
Hi idono can you teach me how to make RPG with C++ because i am a beginner and i don't know how the code...... Please!!!!

GBU
Thanks for posting this code, it inspired me to try to do something similar (obviously using my own knowledge) tsk. one question , where did you get the "system" commands?, I really liked them (I thought there was no way to change the font o.o at least in the command prompt....).
Topic archived. No new replies allowed.