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))
#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<unsignedint>(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"; }
elseif (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"; }
elseif (classNum == 2) { playerClass = "Bard"; }
elseif (classNum == 3) { playerClass = "Cleric"; }
elseif (classNum == 4) { playerClass = "Paladin"; }
elseif (classNum == 5) { playerClass = "Ranger"; }
elseif (classNum == 6) { playerClass = "Rogue"; }
elseif (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++;
}
elseif (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).
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.