Random D&D Character Generator on R
I have been doing a lot of work on R for my research and decided to give it a go and write the script for a random D&D character generator.
It is a very simplified version and there is definitely room for improvement and expansion, but I wanted to share it with everyone for those who want to tinker with it:
#Install Packages#
install.packages("randomNames")
library("randomNames")
#Function to generate a random character sheet#
generate_random_character <- function() {
# Sample races, classes, and backgrounds#
races <- c(
"Dwarf",
"Elf",
"Halfling",
"Human",
"Dragonborn",
"Gnome",
"Half-Elf",
"Half-Orc",
"Tiefling",
"Aasimar",
"Firbolg",
"Genasi",
"Goliath",
"Hobgoblin",
"Kenku",
"Kobold",
"Lizardfolk",
"Tabaxi",
"Triton",
"Bugbear",
"Goblin",
"Hobgoblin",
"Orc",
"Fairy",
"Satyr",
"Yuan-ti Pureblood",
"Aarakocra",
"Aasimar",
"Changeling",
"Kalashtar",
"Shifter",
"Warforged",
"Centaur",
"Loxodon",
"Minotaur",
"Simic Hybrid",
"Vedalken",
"Gith (Githyanki, Githzerai)"
)
classes <- c( "Barbarian",
"Bard",
"Cleric",
"Druid",
"Fighter",
"Monk",
"Paladin",
"Ranger",
"Rogue",
"Sorcerer",
"Warlock",
"Wizard",
"Artificer",
"Blood Hunter"
)
subclass_Barbarian <- c(
"Path of the Berserker",
"Path of the Totem Warrior",
"Path of the Ancestral Guardian",
"Path of the Storm Herald",
"Path of the Zealot"
)
subclass_Bard <- c(
"College of Lore",
"College of Valor",
"College of Glamour",
"College of Swords",
"College of Whispers",
"College of Eloquence"
)
subclass_Cleric <- c(
"Knowledge Domain",
"Life Domain",
"Light Domain",
"Nature Domain",
"Tempest Domain",
"Trickery Domain",
"War Domain",
"Forge Domain",
"Grave Domain",
"Order Domain",
"Peace Domain",
"Twilight Domain"
)
subclass_Druid <- c(
"Circle of the Land",
"Circle of the Moon",
"Circle of Dreams",
"Circle of the Shepherd",
"Circle of Twilight"
)
subclass_Fighter <- c(
"Champion",
"Battle Master",
"Eldritch Knight",
"Arcane Archer",
"Cavalier",
"Samurai"
)
subclass_Monk <- c(
"Way of the Open Hand",
"Way of Shadow",
"Way of the Four Elements",
"Way of the Drunken Master",
"Way of the Kensei",
"Way of the Sun Soul"
)
subclass_Paladin <- c(
"Oath of Devotion",
"Oath of the Ancients",
"Oath of Vengeance",
"Oath of the Crown",
"Oath of Conquest",
"Oath of Redemption",
"Oath of the Watchers"
)
subclass_Ranger <- c(
"Hunter",
"Beast Master",
"Gloom Stalker",
"Horizon Walker",
"Monster Slayer"
)
subclass_Rogue <- c(
"Thief",
"Assassin",
"Arcane Trickster",
"Mastermind",
"Swashbuckler",
"Inquisitive",
"Scout"
)
subclass_Sorcerer <- c(
"Draconic Bloodline",
"Wild Magic",
"Divine Soul",
"Shadow Magic",
"Storm Sorcery",
"Aberrant Mind"
)
subclass_Warlock <- c(
"The Archfey",
"The Fiend",
"The Great Old One",
"The Undying",
"The Celestial",
"The Hexblade",
"The Raven Queen"
)
subclass_Wizard <- c(
"School of Abjuration",
"School of Conjuration",
"School of Divination",
"School of Enchantment",
"School of Evocation",
"School of Illusion",
"School of Necromancy",
"School of Transmutation",
"War Magic",
"Bladesinging"
)
subclass_Artificer <- c(
"Alchemist",
"Artillerist",
"Battle Smith",
"Armorer"
)
subclass_BloodHunter <- c(
"Order of the Ghostslayer",
"Order of the Lycan",
"Order of the Profane Soul"
)
backgrounds <- c( "Acolyte",
"Charlatan",
"Criminal",
"Entertainer",
"Folk Hero",
"Guild Artisan",
"Hermit",
"Noble",
"Outlander",
"Sage",
"Sailor",
"Soldier",
"Urchin",
"City Watch",
"Clan Crafter",
"Cloistered Scholar",
"Courtier",
"Far Traveler",
"Inheritor",
"Knight",
"Knight of the Order",
"Mercenary Veteran",
"Urban Bounty Hunter",
"Uthgardt Tribe Member",
"Waterdhavian Noble",
"Haunted One",
"Anthropologist",
"Archaeologist",
"Azorius Functionary",
"Boros Legionnaire",
"Dimir Operative",
"Izzet Engineer",
"Rakdos Cultist",
"Selesnya Initiate",
"Simic Scientist",
"Criminal (Spy)",
"Gladiator",
"Knight (Free Agent)"
)
gender <- c("Male", "Female")
# Randomly select a race, class, subclass, gender, name and background#
race <- sample(races, 1)
character_class <- sample(classes, 1)
# Select subclass based on the character class
subclass <- character_class
switch(character_class,
"Barbarian" = subclass <- sample(subclass_Barbarian, 1),
"Bard" = subclass <- sample(subclass_Bard, 1),
"Cleric" = subclass <- sample(subclass_Cleric, 1),
"Druid" = subclass <- sample(subclass_Druid,1),
"Fighter" = subclass <- sample(subclass_Fighter,1),
"Monk" = subclass <- sample(subclass_Monk, 1),
"Paladin" = subclass <- sample(subclass_Paladin, 1),
"Ranger" = subclass <- sample(subclass_Ranger,1),
"Rogue" = subclass <- sample(subclass_Rogue,1),
"Sorcerer" = subclass <- sample(subclass_Sorcerer,1),
"Warlock" = subclass <- sample(subclass_Warlock,1),
"Wizard" = subclass <- sample(subclass_Wizard,1),
"Blood Hunter" = subclass <- sample(subclass_BloodHunter,1)
)
background <- sample(backgrounds, 1)
gender <- sample(gender, 1)
name <- gender
switch(gender,
"Male" = name <- randomNames(gender = 0,ethnicity = 5,name.order = "first.last", name.sep = " "),
"Female" = name <- randomNames(gender = 1,ethnicity = 5,name.order = "first.last", name.sep = " ")
)
# Generate random ability scores#
ability_scores <- sample(6:18, 6, replace = TRUE)
# Create a character sheet data frame#
character_sheet <- data.frame(
Name = name,
Race = race,
Class = character_class,
Subclass = subclass,
Background = background,
Gender = gender,
Strength = ability_scores[1],
Dexterity = ability_scores[2],
Constitution = ability_scores[3],
Intelligence = ability_scores[4],
Wisdom = ability_scores[5],
Charisma = ability_scores[6]
)
return(character_sheet)
}
#Generate a random character sheet#
random_character_sheet <- generate_random_character()
#Print the character sheet#
print(random_character_sheet)
9 notes
·
View notes