D&D NPC Generator

I need help making an NPC Generator in codeblocks. I have gotten the name your NPC part down, I just need help on making random stuff such as numbers and bios or even names. I don't think it will be that hard

Numbers I would recommend using a random number generator. I know there's rand() which takes from <cstdlib> but I think there might be a better true random number generator in C++ I forgot the name of. You could make it so your rand() only generates between a range of 1-20 for initial roll stats. I haven't played in a while so I have no idea what each class's bonuses are and whatnot.

For names, either have an external text file list that you can pull random names/bios from, or store them in an internal vector/array (which I highly recommend against because that would just make your program bigger and slower to run).
You want to look into context-free grammar.
You declare a set of rules which are used to generate end result.

For example:
<human name> = <first name> <last name>
Your program will generate first name by further rules (probably by selecting one randomly from corresponding text file) then last name and put them in that order separated by space. Later you can add other grammars for other names (look for real world examples. Northern and Arabic naming systems, for example, would be a good start).
<north name> = <north first name> <north male first name><gender suffix>
Here you see your given name following by contacenated father name and gender suffix.

The same could be applied to bios. In this case it would look like madlibs:
1
2
3
4
5
6
7
8
9
//General grammar
<bio> = <early ages>\n<start of travels>\n<current occupation>
//One of the early ages entry in some file
Not much known about <human name>. 
Some people says that he came from a <region>, but nobody had been able to confirm such claims.
//Another early ages entry
<human name> was born in <small town> in <occupation>'s family. 
His father was killed by robbers before he was born, so he grew up with only his mother, <female human name>. 
[...] 
Hey, CodePotatoe I'm not using CodeBlocks, but I took your question as a challenge for myself and here's what I created. I spent about an hour or so, and it's really just a template. But feel free to use it however you want.

SIMPLE NPC GENERATOR:
(Will randomize Race, Gender, Class and Attributes of Gary Gygax (Lv. 1))
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
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>

int main()
{
	char answer;
	int genCount = 1;

	// Seeds the random number generator to current time/date:
	srand(static_cast<unsigned int>(time(0)));

	// INITIAL GENERATOR NOTICE:
	std::cout << "\n::::: SUPER DUPER CHARACTER GENERATOR :::::" << std::endl;
	std::cout << "(Generates character stats for either PCs or NPCs)" << std::endl;

	do
	{

		// NAME GENERATOR:

		std::string firstName;
		std::string lastName;

		firstName = "Gary";
		lastName = "Gygax";


		// LEVEL GENERATOR:

		int playerLevel;

		playerLevel = 1;


		// RACE GENERATOR:

		std::string playerRace;

		int raceRandom = rand();
		int raceNum;

		raceNum = raceRandom % 3;

		if (raceNum == 1) { playerRace = "Dwarf"; }
		else if (raceNum == 2) { playerRace = "Elf"; }
		else { playerRace = "Human"; }


		// GENDER GENERATOR:

		std::string playerGender;

		int genderRandom = rand();
		int genderNum;

		genderNum = genderRandom % 2;

		if (genderNum == 1) { playerGender = "Male"; }
		else { playerGender = "Female"; }


		// CLASS GENERATOR:

		std::string playerClass;

		int classRandom = rand();
		int classNum;

		classNum = classRandom % 8;
		//classNum = 1;

		if (classNum == 1) { playerClass = "Barbarian"; }
		else if (classNum == 2) { playerClass = "Bard"; }
		else if (classNum == 3) { playerClass = "Cleric"; }
		else if (classNum == 4) { playerClass = "Paladin"; }
		else if (classNum == 5) { playerClass = "Ranger"; }
		else if (classNum == 6) { playerClass = "Rogue"; }
		else if (classNum == 7) { playerClass = "Wizard"; }
		else { playerClass = "Fighter"; }


		// ATTRIBUTE GENERATOR:

		int strRandom = rand();
		int attr_Str = (strRandom % 13) + 6; // Random number between 6-18.

		int dexRandom = rand();
		int attr_Dex = (dexRandom % 13) + 6; // Random number between 6-18.

		int conRandom = rand();
		int attr_Con = (conRandom % 13) + 6; // Random number between 6-18.

		int intRandom = rand();
		int attr_Int = (intRandom % 13) + 6; // Random number between 6-18.

		int wisRandom = rand();
		int attr_Wis = (wisRandom % 13) + 6; // Random number between 6-18.

		int chaRandom = rand();
		int attr_Cha = (chaRandom % 13) + 6; // Random number between 6-18.


		// CLASS/ATTRIBUTE MODIFIERS (must occur AFTER both class and attribute generators):

		if (classNum == 1) // Barbarian
		{
			attr_Str += 2;
			attr_Int -= 2;

			/*
				Anything associated with the Barbarian, like Rage feat or w/e. Ignored if class != Barbarian.
			*/

		}
		else {}


		// CONSOLE OUTPUT:

		// Name (Lv. ##):
		std::cout << "\n\n=== CHARACTER: #" << genCount << " ===" << std::endl;
		std::cout << "\n" << firstName << " " << lastName << " (Lv. " << playerLevel << ")" << std::endl;

		// Race; Gender; Class:
		std::cout << "Race: " << playerRace << "; Gender: " << playerGender << "; Class: " << playerClass << std::endl;

		// Attributes:
		std::cout << "\nSTR: " << attr_Str << std::endl;
		std::cout << "DEX: " << attr_Dex << std::endl;
		std::cout << "CON: " << attr_Con << std::endl;
		std::cout << "INT: " << attr_Int << std::endl;
		std::cout << "WIS: " << attr_Wis << std::endl;
		std::cout << "CHA: " << attr_Cha << std::endl;
		std::cout << "LUC: Hey, this is DnD and not Fallout!" << std::endl;

		// Create New Character Y/N:

		std::cout << "\n\n Would you like to generate another character? ('y' or 'n')" << std::endl;

		std::cin >> answer;

		if (answer == 'y')
		{
			genCount++;
		}
		else if (answer != 'y' && answer != 'n')
		{
			std::cout << "'" << answer << "'" << " isn't a valid answer, but we don't care." << std::endl;
			std::cout << "We're driving Cadillacs in our dreams. xD" << std::endl;
			genCount++;
		}
		else
		{
			std::cout << "\nHALF-LIFE 3 CONFIRMED, M'KAY GOODBYE!!!";
			system("PAUSE");
		}
	}

	while (answer != 'n');

	return 0;
}


Note: I haven't started writing functions yet (I'm a newbie) and, as you can see, all my variables are all over the place (which I assume will break your code if you start putting everything into functions, so be sure to instantiate the vars at the start of main (if it's like Java)).

Changelog:
* Fixed some incorrect math.
* Removed a redundant if statement (that terminates program).
* Made an initial "Super Duper Notice" headline.
* Added +2 Str and -2 Int modifiers to Barbarian attributes.
* Added some easter eggs to program.
* Template program finished. (Still lacking name generator though).
Last edited on
Got a barbarian with 7 Str and 18 Int. 10/10 would generate all my characters with this :)
Haha, yeah I've added attribute modifiers to Barbarian now (but not the other classes yet).
Template program finished, CodePotatoes will have to figure out the rest on his own, hopefully with the help of my template.
Last edited on
Ok ok first try, got a female cleric with 12 str, and 15 wis/int. Above average ayyy. Not much to say about CHAR though. Not enough feminism.
Topic archived. No new replies allowed.