respawn

ok i am working on a code and i want the player to start at a certain part of the code when he dies instead of having to restart the whole thing. any help is greatly appreciated
Can you describe what you want in more detail? Depending on the circumstances this might warrant a simple loop, a function/functions you can call repeatedly, or a whole bunch of classes.
1
2
3
4
5
if(!player_alive)
{
   player_position = wherever_you_want_to_put_him;
   player_alive = true;
}
Can you describe what you want in more detail?


ok the player has 50 hp. whenever it runs out and he dies i want him to respawn at his last level-up. so they dont have to enter their name again.

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
#include <iostream>
#include <windows.h>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::numeric_limits;
using std::streamsize;
int main()
{    
     system("TITLE TEXTVENTURE!!");
    string name;
    int echp, hp, strength, pet_hp, pet_lvl, lvl, ap;
    char choice;
    pet_hp = 0;
    pet_lvl = 0;
    echp = 0;
    hp = 10;
    lvl = 1;
    ap = 0;
    strength = 10;
    cout << "                                                               pet hp = " << pet_hp << "\n";
    cout << "                                                               pet lvl = " << pet_lvl << "\n";
    cout << "                                                               hp = " << hp << "\n";
    cout << "                                                               strength = " << strength << "\n";
    cout << "                                                               level " << lvl << "\n";
    cout << "                                                               ap = " << ap << "\n";
    cout << "\n\n\n\t\t--WELCOME TO TEXTVENTURE--\n";
   cout << "Hello. What is your name?\n";
   cin >> name;
   cout << "So your name is " << name << " now is it?..... \n";
   cout << "Hello, and welcome, " << name << ", you are about to enter the world";
   cout << " of Textventure.";
   cout << "\nThis all takes place in medieval times. The king is power mad and the sorcerer, ";
   cout << "\nmerlin is at his side You make selections on what you do by typing any letter \noption given.";
   cout << "You have health. You may be damaged by monsters, or the result of \n";
   cout << "another choice you made. You will encounter monsters and must fight.\n";
   cout << "When you fight, or complete other special encounters, you will earn,\n";
   cout << "Adventure Points (AP), which you can use to buy weapons and other stuff.\n";
   cout << "You can raise your stats by beating monsters and getting passed puzzles,\n anyways, good luck!\n";
   cout << "Did you get that? ^^ ";
   system("PAUSE");
   
   //DUNGEON CELL//
   
   cout << "\n\nYou awake in a dungeon cell.\n";
   cout << "It's dark and you can only remember your name.\n";
   cout << "In this room is only one cell, and a door out. Your cell is locked however.\n";
   cout << "What would you like to do?\n";
   cout << "a. Try and break the lock with your fists.\nb. Try and squeeze through the bars.\n";
    echp = echp + 5;
    do
    {
    cin >> choice;
    switch (choice)
           {
           case 'a':
           case 'A':
           echp = echp - 1;
           if (echp == 4)
           {
                    cout << "                                        enemy hp = " << echp << "\n";
                    cout << " you inflicted some damage but not enough to break it what is your next move?\n";
                    break;
                    }
                    if (echp == 3)
                    {
                             cout << "                                        enemy hp = " << echp << "\n";
                         cout << "it made a weird noise that time something is happening in it. what is your next move?\n ";
                     }
                     if (echp == 2)
                     {
                              cout << "                                        enemy hp = " << echp << "\n";
                              cout << "it looks kinda beat up.what is your next move?\n" ;
                     }
                     if (echp == 1)
                     {
                              cout << "                                        enemy hp = " << echp << "\n";
                              cout << "one more should do it.....";
                              }
           break;
           case 'b':
           case 'B':
           cout << "you try and try but you cant get through ";
           system("PAUSE");
           break;
           }
    }
           while (echp > 0);
           if (echp <= 0);
           {
                    cout << "the lock busts open\n\n\n\n ";
                    cout << "\t\t\t**YOU LEVELED UP**\n";
    echp = 0;
    hp = hp + 5;
    lvl = lvl + 1;
    ap = ap + 300;
    strength = strength + 5;
        cout << "                                                               hp = " << hp << "\n";
    cout << "                                                               strength = " << strength << "\n";
    cout << "                                                               level " << lvl << "\n";
    cout << "                                                               ap = " << ap << "\n\n\n";
                    
                    }
    cout << "you slowly slip out and go out of the room..... but as the door creeps open you start to hear footsteps. " ;
    cout << "you know 2 people are coming but you dont know who they are. In front " ;
    cout << "of you is 2 hallways, and some horse stalls to the side of you\n what do you want to do?\n" ;
    cout << "A. take left hallway\nC. hide in stalls\n\n";
    system("PAUSE");
    cin >> choice;
    switch (choice)
    {
           case 'a':
           case 'A':
                cout << "you take the left hallway. then you see the 2 knights. they instantly throw\n";
                cout << "their fists at you and alert the king. you didnt even have a chance to\n fight back.";
                system("PAUSE");
           break;
           case 'c':
           case 'C':
                cout << "you choose to hide in the stalls. then just as you see two of the kings men.\n ";
                cout << " you see a man in a cloak come up and take the two knights down\n from behind ";
                cout << "he goes towards the room with your cell he opens the door and\n freezes.... he starts to panick. just then one of the horses ";
                cout << "starts to freak out. the man walks over to the stalls and opens them up one by one. he sees you and seizes your arm. he asks what you are doing.\n ";
                cout << "what do you want to say?\n ";
                system("PAUSE");
           break;
           
           cout << " ";
           cout << " ";
           cout << " ";
           cout << " ";
           cout << " ";
           cout << " ";
           system ("PAUSE");
    }
}


(i havent gotten to B for the 2nd choice yet.)
updated my code and i still need help.........

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
#include <iostream>
#include <windows.h>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::numeric_limits;
using std::streamsize;
int main()
{    
     system("TITLE TEXTVENTURE!!");
    string name;
    int echp, hp, strength, pet_hp, pet_lvl, lvl, ap, dmg;
    char choice;
    pet_hp = 0;
    pet_lvl = 0;
    echp = 0;
    hp = 10;
    lvl = 1;
    ap = 0;
    dmg = rand();
    strength = 10;
    srand(static_cast<unsigned int>(time(0)));
    cout << "                                                               pet hp = " << pet_hp << "\n";
    cout << "                                                               pet lvl = " << pet_lvl << "\n";
    cout << "                                                               hp = " << hp << "\n";
    cout << "                                                               strength = " << strength << "\n";
    cout << "                                                               level " << lvl << "\n";
    cout << "                                                               ap = " << ap << "\n";
    cout << "\n\n\n\t\t--WELCOME TO TEXTVENTURE--\n";
   cout << "Hello. What is your name?\n";
   cin >> name;
   cout << "So your name is " << name << " now is it?..... \n";
   cout << "Hello, and welcome, " << name << ", you are about to enter the world";
   cout << " of Textventure.";
   cout << "\nThis all takes place in medieval times. The king is power mad and the sorcerer, ";
   cout << "merlin is at his side You make selections on what you do by typing any letter \noption given.";
   cout << "You have health. You may be damaged by monsters, or the result of \n";
   cout << "another choice you made. You will encounter monsters and must fight.\n";
   cout << "When you fight, or complete other special encounters, you will earn,\n";
   cout << "Adventure Points (AP), which you can use to buy weapons and other stuff.\n";
   cout << "You can raise your stats by beating monsters and getting passed puzzles,\n anyways, good luck!\n";
   cout << "Did you get that? ^^ ";
   system("PAUSE");
   
   //DUNGEON CELL//
   
   cout << "\n\nYou awake in a dungeon cell.\n";
   cout << "It's dark and you can only remember your name.\n";
   cout << "In this room is only one cell, and a door out. Your cell is locked however.\n";
   cout << "What would you like to do?\n";
   cout << "a. Try and break the lock with your fists.\nb. Try and squeeze through the bars.\n";
    echp = echp + 5;
    do
    {
    cin >> choice;
    switch (choice)
           {
           case 'a':
           case 'A':
           dmg = (dmg % 2) + 1;
           echp = echp - dmg;
           if (echp == 4)
           {
                    cout << "                                        enemy hp = " << echp << "\n";
                    cout << " you inflicted some damage but not enough to break it what is your next move?\n";
                    break;
                    }
                    if (echp == 3)
                    {
                             cout << "                                        enemy hp = " << echp << "\n";
                         cout << "it made a weird noise that time something is happening in it. what is your next move?\n ";
                     }
                     if (echp == 2)
                     {
                              cout << "                                        enemy hp = " << echp << "\n";
                              cout << "it looks kinda beat up. what is your next move?\n" ;
                     }
                     if (echp == 1)
                     {
                              cout << "                                        enemy hp = " << echp << "\n";
                              cout << "one more should do it.....";
                              }
           break;
           case 'b':
           case 'B':
           cout << "you try and try but you cant get through ";
           system("PAUSE");
           break;
           }
    }
           while (echp > 0);
           if (echp <= 0);
           {
                    cout << "the lock busts open\n\n\n\n ";
                    cout << "\t\t\t**YOU LEVELED UP**\n";
    echp = 0;
    hp = hp + 5;
    lvl = lvl + 1;
    ap = ap + 300;
    strength = strength + 5;
        cout << "                                                               hp = " << hp << "\n";
    cout << "                                                               strength = " << strength << "\n";
    cout << "                                                               level " << lvl << "\n";
    cout << "                                                               ap = " << ap << "\n\n\n";
                    
                    }
    cout << "you slowly slip out and go out of the room..... but as the door creeps open you start to hear footsteps. " ;
    cout << "you know 2 people are coming but you dont know who they are. In front " ;
    cout << "of you is 2 hallways, and some horse stalls to the side of you\n what do you want to do?\n" ;
    cout << "A. take left hallway\nB. freak out\nC. hide in stalls\n\n";
    cin >> choice;
    switch (choice)
    {
           case 'a':
           case 'A':
                cout << "you take the left hallway. then you see the 2 knights. they instantly throw\n";
                cout << "their fists at you and alert the king. you didnt even have a chance to\n fight back.";
                system("PAUSE");
           break;
           case 'b':
           case 'B':
                cout << "you start runing around in circles and banging your head \n";
                cout << "furiously against the horse stalls... and then everything went\n";
                cout << "black.";
           case 'c':
           case 'C':
                cout << "you choose to hide in the stalls. then just as you see two of the kings men.\n ";
                cout << " you see a man in a cloak come up and take the two knights down\n from behind ";
                cout << "he goes towards the room with your cell he opens the door and\n freezes.... he starts to panick. just then one of the horses ";
                cout << "starts to freak out. the man walks over to the stalls and opens them up one by one. he sees you and seizes your arm. he asks what you are doing.\n ";
                cout << "what do you want to say?\n ";
                cout << "a. i accidentaly wondered into the building and i am trying to\nfind a way out.";
                cout << "b. i have no idea.\nc. i am a huge celebrity from a far away land that was kidnapped by a\nflying pig.\n";
                     cin >> choice;
                     switch (choice)
                     case 'a':
                     case 'A':
                         cout << "well you see...";
                     break;
                     case 'b':
                     case 'B':
                          cout << "to be honest.. i have no....";
                     break;
                     case 'c':
                     case 'C':
                          cout << "yo! yo! yo! im am the next top celeb. but this..." ; // lol
                system("PAUSE");
           break;
           
           cout << " ";
           cout << " ";
           cout << " ";
           cout << " ";
           cout << " ";
           cout << " ";
           system ("PAUSE");
    }
}
Last edited on
Topic archived. No new replies allowed.