Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- print("One Click NPC Common Generator\n")
- """print("Press Enter to run. Type 'quit' to exit.")"""
- # This run global is a reasonable way of implementing this, but I might consider
- # using command line arguments (i.e. number of NPCs to generate) instead of accepting direct
- # inputs from the user whilst running?
- # Look at https://docs.python.org/3/library/sys.html#sys.argv if you're not familiar with
- # command line arguments in Python
- run = True
- # So instead of implementing these dice rolls as global variables, it might make more sense to
- # make them methods. Since at the moment you "roll" only once and then use those values forever it actually
- # prevents certain combinations of name parts, since the d8 value is used everywhere as the list index
- # See my implementation for details of how these might work as methods
- d4 = 0
- d6 = 0
- d8 = 0
- d10 = 0
- # These lists are fine, maybe worth having a d2 method or something for the gender list so
- # it doesn't have to have duplicates, but not really a big deal. Also, why is the NPC's feature
- # called a bug lol
- race = ["Dwarf", "Elf", "Halfling", "Human", "Human", "Gnome", "Half-Elf", "Half-Orc"]
- gender = ["Male", "Female", "Male", "Female"]
- adjective = ["Tattooed/Pierced/Unusual", "Long/Large/Loud/Extravagant", "Short/Small/Quiet/Simple",
- "Missing/Injured/Damaged", "Beautiful/Ugly", "Colourful/Dyed/Painted"]
- bug = ["Nose/Voice", "Eyes/Eyebrows/Stare", "Beard/Hair/Sideburns", "Ears/Hearing", "Mouth/Lips/Laugh",
- "Head/Forehead/Face", "Clothing", "Skin/Scar", "Shoes/Hat", "Teeth/Nails/Hands"]
- # So these lists are a perfect example of a good use case for multi-dimensional lists,
- # i.e. instead of having 4 one-dimensional lists, you just have one two-dimensional list
- # that takes two indexes instead of one. This also massively simplifies the gen function lower
- # down as you don't have to use all those if statements. See my implementation for examples of this.
- d4_0 = ["rut", "en", "os", "an", "in", "ak", "il", "ik"]
- d4_1 = ["lynn", "lia", "ra", "ley", "ina", "eth", "lia", "nor"]
- d4_2 = ["li", "al", "er", "as", "riel", "urt", "on", "org"]
- d4_3 = ["na", "aya", "yn", "na", "ila", "na", "tha", "gri"]
- d6_0 = ["omma", "ryl", "", "", "", "li", "tu", "og"]
- d6_1 = ["ogg", "tha", "", "", "", "mer", "ana", "oto"]
- d6_2 = ["osgra", "ina", "ow", "", "", "wun", "dra", "ust"]
- d6_3 = ["ed", "ala", "em", "", "", "men", "ado", ""]
- d6_4 = ["tirl", "yni", "", "", "", "alv", "la", "g"]
- d6_5 = ["wod", "arun", "", "", "", "ip", "reg", "ak"]
- d10_0 = ["Dal", "Taer", "Mar", "Dyl", "Eth", "Clad", "Gal", "Bok"]
- d10_1 = ["Hour", "Keth", "Dan", "Eth", "La", "Ged", "Ari", "Gun"]
- d10_2 = ["Kal", "ELin", "San", "Jord", "Gab", "Dap", "Fae", "Ton"]
- d10_3 = ["Gat", "Ay", "Tar", "Gab", "Zach", "Jip", "Avil", "Tar"]
- d10_4 = ["Brot", "Lae", "Wil", "Zach", "Hay", "Cos", "Tyr", "Kez"]
- d10_5 = ["Har", "Sil", "Fin", "Al", "Dyl", "Glon", "Yen", "Vug"]
- d10_6 = ["Strom", "Arth", "Elk", "La", "Iv", "Smid", "Rad", "No"]
- d10_7 = ["Glor", "Sca", "Jop", "Iv", "Jord", "Jen", "Ven", "Kir"]
- d10_8 = ["Thog", "Evin", "Ric", "Kar", "Al", "Tin", "Lan", "Bro"]
- d10_9 = ["Demm", "Kyr", "Bel", "Hay", "Kar", "Deb", "Dan", "Gor"]
- def roll():
- global run
- global d4
- global d6
- global d8
- global d10
- d4 = random.randint(0, 3)
- d6 = random.randint(0, 5)
- d8 = random.randint(0, 7)
- d10 = random.randint(0, 9)
- def gen():
- # Could probably keep the run value as a global if you want to keep it around, but
- # pretty much all the others can go. You only really need to define a variable as a global if
- # it's both defines outside the scope of the method you're in (which they are) AND you need to
- # modify the values within this method (which for most of these you don't). It's fine to just have
- # static variables defined up at the top if they're never gonna change.
- global run
- global d4
- global d6
- global d8
- global d10
- global d4_0
- global d4_1
- global d4_2
- global d4_3
- global d6_0
- global d6_1
- global d6_2
- global d6_3
- global d6_4
- global d6_5
- global d10_0
- global d10_1
- global d10_2
- global d10_3
- global d10_4
- global d10_5
- global d10_6
- global d10_7
- global d10_8
- global d10_9
- start = input("Press enter to create, type 'quit' then enter to exit.\n")
- if start == "quit":
- run = False
- else:
- if d10 == 0:
- name1 = d10_0[d8]
- elif d10 == 1:
- name1 = d10_1[d8]
- elif d10 == 2:
- name1 = d10_2[d8]
- elif d10 == 3:
- name1 = d10_3[d8]
- elif d10 == 4:
- name1 = d10_4[d8]
- elif d10 == 5:
- name1 = d10_5[d8]
- elif d10 == 6:
- name1 = d10_6[d8]
- elif d10 == 7:
- name1 = d10_7[d8]
- elif d10 == 8:
- name1 = d10_8[d8]
- else:
- name1 = d10_9[d8]
- if d6 == 0:
- name2 = d6_0[d8]
- elif d6 == 1:
- name2 = d6_1[d8]
- elif d6 == 2:
- name2 = d6_2[d8]
- elif d6 == 3:
- name2 = d6_3[d8]
- elif d6 == 4:
- name2 = d6_4[d8]
- else:
- name2 = d6_5[d8]
- if d4 == 0:
- name3 = d4_0[d8]
- elif d4 == 1:
- name3 = d4_1[d8]
- elif d4 == 2:
- name3 = d4_2[d8]
- else:
- name3 = d4_3[d8]
- # Minor thing, but you could use the str.format method here to make these prints a
- # bit prettier. See here for details: https://docs.python.org/3/tutorial/inputoutput.html#the-string-format-method
- print("Name: ", name1 + name2 + name3, "\n")
- print("Gender: ", gender[d4], "\n")
- print("Race: ", race[d8], "\n")
- print("Feature: ", adjective[d6], bug[d10], "\n")
- # Should always use "if __name__ == '__main__'" in a single file script like this
- # See here for details: https://thepythonguru.com/what-is-if-__name__-__main__/
- while run:
- roll()
- gen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement