Advertisement
CaptainSpaceCat

StoryGen

Sep 12th, 2015
163
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local nouns = {
  2.     "Apple",
  3.     "Car",
  4.     "Object",
  5.     "Raindrop",
  6.     "Flyer",
  7.     "Core",
  8.     "Generator",
  9.     "Ship",
  10.     "Damage",
  11.     "Space",
  12.     "Article",
  13.     "Secret"
  14. }
  15.  
  16. local verbs = {
  17.     infinitive = {
  18.         "Retract",
  19.         "Run",
  20.         "Leap",
  21.         "Jump",
  22.         "Walk",
  23.         "Glide",
  24.         "Strafe",
  25.         "Eat",
  26.         "Poop",
  27.         "Explode",
  28.         "Die",
  29.         "Open"
  30.     },
  31.     action = {
  32.         "Ran",
  33.         "Walked",
  34.         "Screamed",
  35.         "Fell",
  36.         "Ate",
  37.         "Peed",
  38.         "Flew",
  39.         "Dried",
  40.         "Created",
  41.         "Jumped",
  42.         "Slammed",
  43.         "Struck"
  44.     }
  45. }
  46.  
  47. local adjectives = {
  48.     "Vile",
  49.     "Awesome",
  50.     "Sweet",
  51.     "Gross",
  52.     "Deadly",
  53.     "Wondrous",
  54.     "Depressing",
  55.     "Exciting",
  56.     "Inciteful",
  57.     "Ingenious",
  58.     "Apathetic",
  59.     "Fascinating"
  60. }
  61.  
  62. local sentences = {
  63.     "One day, #{protagonist} #{averb}, and #{averb} a #{adjective}y #{noun}.",
  64.     "Suddenly, #{antagonist} #{averb}.",
  65.     "\"#{noun}s!\" #{protagonist} #{averb}.",
  66.     "Then, #{antagonist} #{averb} #{neutral}, a #{adjective} #{noun}!",
  67.     "Finally, #{protagonist} #{averb} the #{adjective} #{antagonist}, resulting in the #{averb} of many #{noun}s.",
  68.     "#{neutral} didn't want any #{noun}s because they were #{adjective}.",
  69.     "#{neutral} wanted to #{iverb}, yet he was #{adjective}.",
  70.     "#{protagonist} decided to #{iverb}.",
  71.     "Shockingly, #{antagonist} began to #{iverb}!",
  72.     "#{adjective}ly, #{protagonist} #{averb} #{neutral}.",
  73.     "After this, #{protagonist} #{averb} #{neutral}'s #{noun}, even though he really wanted to #{iverb}."
  74. }
  75.  
  76. local story = {
  77.     protagonist = "",
  78.     gSecondary1 = "",
  79.     gSecondary2 = "",
  80.     gSecondary3 = "",
  81.  
  82.     antagonist = "",
  83.     bSecondary1 = "",
  84.     bSecondary2 = "",
  85.     bSecondary3 = "",
  86.  
  87.     neutralMain = "",
  88.     nSecondary1 = "",
  89.     nSecondary2 = "",
  90.     nSecondary3 = "",
  91.  
  92.     goalObject = "",
  93.     setting = ""
  94. }
  95.  
  96. local vowels = {"a", "e", "i", "o", "u"}
  97. local consonants = {"b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z"}
  98.  
  99. function GetRandomName()
  100.     local name = ""
  101.     local switch = math.random(0, 1)
  102.     for i = 1, math.random(3, 8) do
  103.         if i%2 == switch then
  104.             name = name .. vowels[math.random(1, #vowels)]
  105.         else
  106.             name = name .. consonants[math.random(1, #consonants)]
  107.         end
  108.         if i == 1 then
  109.             name = string.upper(name)
  110.         end
  111.         --print(name)
  112.     end
  113.     return name
  114. end
  115.  
  116. function GenerateCharacters()
  117.     story.protagonist = GetRandomName()
  118.     story.antagonist = GetRandomName()
  119.     story.neutralMain = GetRandomName()
  120. end
  121.  
  122. function GenerateSentence()
  123.     local refrence = sentences[math.random(1, #sentences)]
  124.     local sentence = ""
  125.     while #refrence > 0 do
  126.         local _, en = refrence:find("^[^#]+")
  127.         if en then
  128.             sentence = sentence .. refrence:sub(1, en)
  129.             refrence = refrence:sub(en+2)  
  130.         else
  131.             refrence = refrence:sub(2)
  132.         end
  133.         if refrence:find("^%{.-%}") then
  134.             local _, en, type = refrence:find("^%{(.-)%}")
  135.             if type == "noun" then
  136.                 sentence = sentence .. string.lower(nouns[math.random(1, #nouns)])
  137.             elseif type == "averb" then
  138.                 sentence = sentence .. string.lower(verbs.action[math.random(1, #verbs.action)])
  139.             elseif type == "iverb" then
  140.                 sentence = sentence .. string.lower(verbs.infinitive[math.random(1, #verbs.action)])
  141.             elseif type == "adjective" then
  142.                 sentence = sentence .. string.lower(adjectives[math.random(1, #adjectives)])
  143.             elseif type == "protagonist" then
  144.                 sentence = sentence .. story.protagonist
  145.             elseif type == "antagonist" then
  146.                 sentence = sentence .. story.antagonist
  147.             elseif type == "neutral" then
  148.                 sentence = sentence .. story.neutralMain
  149.             end
  150.             refrence = refrence:sub(en+1)
  151.         end
  152.     end
  153.     return sentence
  154. end
  155.  
  156. function GenerateParagraph()
  157.     local paragraph = "\t"
  158.     local focus = math.random(1, 3)
  159.     for i = 1, math.random(3, 5) do
  160.         paragraph = paragraph .. GenerateSentence() .. "\n"
  161.     end
  162.     return paragraph
  163. end
  164.  
  165. function GenerateStory()
  166.     local story = ""
  167.     for i = 1, math.random(3, 5) do
  168.         story = story .. GenerateParagraph() .. "\n"
  169.     end
  170.     return story
  171. end
  172.  
  173. GenerateCharacters()
  174. local story = GenerateStory()
  175. local oFile = fs.open("output", "w")
  176. oFile.write(story)
  177. oFile.close()
  178. shell.run("edit output")
Advertisement
RAW Paste Data Copied
Advertisement