SHARE
TWEET

Untitled

a guest May 22nd, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import random
  2.  
  3. print("One Click NPC Common Generator\n")
  4. """print("Press Enter to run.  Type 'quit' to exit.")"""
  5.  
  6. # This run global is a reasonable way of implementing this, but I might consider
  7. # using command line arguments (i.e. number of NPCs to generate) instead of accepting direct
  8. # inputs from the user whilst running?
  9. # Look at https://docs.python.org/3/library/sys.html#sys.argv if you're not familiar with
  10. # command line arguments in Python
  11. run = True
  12.  
  13. # So instead of implementing these dice rolls as global variables, it might make more sense to
  14. # make them methods. Since at the moment you "roll" only once and then use those values forever it actually
  15. # prevents certain combinations of name parts, since the d8 value is used everywhere as the list index
  16. # See my implementation for details of how these might work as methods
  17. d4 = 0
  18. d6 = 0
  19. d8 = 0
  20. d10 = 0
  21.  
  22. # These lists are fine, maybe worth having a d2 method or something for the gender list so
  23. # it doesn't have to have duplicates, but not really a big deal. Also, why is the NPC's feature
  24. # called a bug lol
  25. race = ["Dwarf", "Elf", "Halfling", "Human", "Human", "Gnome", "Half-Elf", "Half-Orc"]
  26. gender = ["Male", "Female", "Male", "Female"]
  27. adjective = ["Tattooed/Pierced/Unusual", "Long/Large/Loud/Extravagant", "Short/Small/Quiet/Simple",
  28.              "Missing/Injured/Damaged", "Beautiful/Ugly", "Colourful/Dyed/Painted"]
  29. bug = ["Nose/Voice", "Eyes/Eyebrows/Stare", "Beard/Hair/Sideburns", "Ears/Hearing", "Mouth/Lips/Laugh",
  30.        "Head/Forehead/Face", "Clothing", "Skin/Scar", "Shoes/Hat", "Teeth/Nails/Hands"]
  31.  
  32. # So these lists are a perfect example of a good use case for multi-dimensional lists,
  33. # i.e. instead of having 4 one-dimensional lists, you just have one two-dimensional list
  34. # that takes two indexes instead of one. This also massively simplifies the gen function lower
  35. # down as you don't have to use all those if statements. See my implementation for examples of this.
  36. d4_0 = ["rut", "en", "os", "an", "in", "ak", "il", "ik"]
  37. d4_1 = ["lynn", "lia", "ra", "ley", "ina", "eth", "lia", "nor"]
  38. d4_2 = ["li", "al", "er", "as", "riel", "urt", "on", "org"]
  39. d4_3 = ["na", "aya", "yn", "na", "ila", "na", "tha", "gri"]
  40. d6_0 = ["omma", "ryl", "", "", "", "li", "tu", "og"]
  41. d6_1 = ["ogg", "tha", "", "", "", "mer", "ana", "oto"]
  42. d6_2 = ["osgra", "ina", "ow", "", "", "wun", "dra", "ust"]
  43. d6_3 = ["ed", "ala", "em", "", "", "men", "ado", ""]
  44. d6_4 = ["tirl", "yni", "", "", "", "alv", "la", "g"]
  45. d6_5 = ["wod", "arun", "", "", "", "ip", "reg", "ak"]
  46. d10_0 = ["Dal", "Taer", "Mar", "Dyl", "Eth", "Clad", "Gal", "Bok"]
  47. d10_1 = ["Hour", "Keth", "Dan", "Eth", "La", "Ged", "Ari", "Gun"]
  48. d10_2 = ["Kal", "ELin", "San", "Jord", "Gab", "Dap", "Fae", "Ton"]
  49. d10_3 = ["Gat", "Ay", "Tar", "Gab", "Zach", "Jip", "Avil", "Tar"]
  50. d10_4 = ["Brot", "Lae", "Wil", "Zach", "Hay", "Cos", "Tyr", "Kez"]
  51. d10_5 = ["Har", "Sil", "Fin", "Al", "Dyl", "Glon", "Yen", "Vug"]
  52. d10_6 = ["Strom", "Arth", "Elk", "La", "Iv", "Smid", "Rad", "No"]
  53. d10_7 = ["Glor", "Sca", "Jop", "Iv", "Jord", "Jen", "Ven", "Kir"]
  54. d10_8 = ["Thog", "Evin", "Ric", "Kar", "Al", "Tin", "Lan", "Bro"]
  55. d10_9 = ["Demm", "Kyr", "Bel", "Hay", "Kar", "Deb", "Dan", "Gor"]
  56.  
  57. def roll():
  58.     global run
  59.     global d4
  60.     global d6
  61.     global d8
  62.     global d10
  63.     d4 = random.randint(0, 3)
  64.     d6 = random.randint(0, 5)
  65.     d8 = random.randint(0, 7)
  66.     d10 = random.randint(0, 9)
  67.  
  68.  
  69. def gen():
  70.     # Could probably keep the run value as a global if you want to keep it around, but
  71.     # pretty much all the others can go. You only really need to define a variable as a global if
  72.     # it's both defines outside the scope of the method you're in (which they are) AND you need to
  73.     # modify the values within this method (which for most of these you don't). It's fine to just have
  74.     # static variables defined up at the top if they're never gonna change.
  75.     global run
  76.     global d4
  77.     global d6
  78.     global d8
  79.     global d10
  80.     global d4_0
  81.     global d4_1
  82.     global d4_2
  83.     global d4_3
  84.     global d6_0
  85.     global d6_1
  86.     global d6_2
  87.     global d6_3
  88.     global d6_4
  89.     global d6_5
  90.     global d10_0
  91.     global d10_1
  92.     global d10_2
  93.     global d10_3
  94.     global d10_4
  95.     global d10_5
  96.     global d10_6
  97.     global d10_7
  98.     global d10_8
  99.     global d10_9
  100.  
  101.     start = input("Press enter to create, type 'quit' then enter to exit.\n")
  102.  
  103.     if start == "quit":
  104.         run = False
  105.  
  106.     else:
  107.         if d10 == 0:
  108.             name1 = d10_0[d8]
  109.         elif d10 == 1:
  110.             name1 = d10_1[d8]
  111.         elif d10 == 2:
  112.             name1 = d10_2[d8]
  113.         elif d10 == 3:
  114.             name1 = d10_3[d8]
  115.         elif d10 == 4:
  116.             name1 = d10_4[d8]
  117.         elif d10 == 5:
  118.             name1 = d10_5[d8]
  119.         elif d10 == 6:
  120.             name1 = d10_6[d8]
  121.         elif d10 == 7:
  122.             name1 = d10_7[d8]
  123.         elif d10 == 8:
  124.             name1 = d10_8[d8]
  125.         else:
  126.             name1 = d10_9[d8]
  127.  
  128.         if d6 == 0:
  129.             name2 = d6_0[d8]
  130.         elif d6 == 1:
  131.             name2 = d6_1[d8]
  132.         elif d6 == 2:
  133.  
  134.             name2 = d6_2[d8]
  135.         elif d6 == 3:
  136.             name2 = d6_3[d8]
  137.         elif d6 == 4:
  138.             name2 = d6_4[d8]
  139.         else:
  140.             name2 = d6_5[d8]
  141.  
  142.         if d4 == 0:
  143.             name3 = d4_0[d8]
  144.         elif d4 == 1:
  145.             name3 = d4_1[d8]
  146.         elif d4 == 2:
  147.             name3 = d4_2[d8]
  148.         else:
  149.             name3 = d4_3[d8]
  150.  
  151.         # Minor thing, but you could use the str.format method here to make these prints a
  152.         # bit prettier. See here for details: https://docs.python.org/3/tutorial/inputoutput.html#the-string-format-method
  153.         print("Name:  ", name1 + name2 + name3, "\n")
  154.         print("Gender:  ", gender[d4], "\n")
  155.         print("Race:  ", race[d8], "\n")
  156.         print("Feature:  ", adjective[d6], bug[d10], "\n")
  157.  
  158. # Should always use "if __name__ == '__main__'" in a single file script like this
  159. # See here for details: https://thepythonguru.com/what-is-if-__name__-__main__/
  160. while run:
  161.     roll()
  162.     gen()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top