Advertisement
Guest User

Untitled

a guest
Nov 25th, 2013
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- How to use the function in an alias. ----------------------------------------------------
  2.  
  3. 1. Create a new alias.
  4.  
  5. 2. Name it "Says (Stutter Hook)"
  6.    ( or whatever you want)
  7.  
  8. 3. Pattern:
  9.    ^(?:\"|\'|say) (.+)$
  10.  
  11. 4. Script:
  12.   local str = matches[2]
  13.   send("say " .. StutterText(str), false)
  14.  
  15. 5. If you made sure to save the script below, you're ready to rock.
  16.  
  17. -- PASTE THE BELOW CODE INTO A NEW SCRIPT IN YOUR SCRIPT EDITOR. ---------------------------
  18.  
  19. --[[
  20.     Generic Stutter Function.
  21.  
  22.     A simple function that accepts text and creates a stuttering effect
  23.     for use in roleplaying.
  24.  
  25.     by Lin, November 25, 2013
  26. ]]--
  27.  
  28. local stutter = function (word)
  29.     -- This function, available only in this script (s'why it's local),
  30.     -- draws out any word given to it.
  31.     -- Ex: gods --> g- gods
  32.     --     leyline --> l- leyline
  33.  
  34.     word = tostring(word) -- Make sure the word is a string, just in case
  35.                                 -- you pass any weirdness to it.
  36.  
  37.     return word:sub(1, 1) .. "- " .. word
  38. end
  39.  
  40. local plosives = {                      -- Hard plosive sounds. Not perfect.
  41.                                             -- See notes below.
  42.     "b", "d", "g", "k", "p", "t", "x",
  43.     "B", "D", "G", "K", "P", "T", "X"
  44. }
  45.  
  46. local stutterWords = {              -- Your guaranteed stutter words. These
  47.                                             -- are words you always want to check for
  48.                                             -- stuttering.
  49.     "gods", "focus", "boobies"
  50. }
  51.  
  52. local stutterChance = 75                -- Chance (in percentage) of how likely
  53.                                             -- stuttering will occur.
  54.  
  55. local stuttersPerLine = 2           -- Hard limit for how many words to use
  56.                                             -- for generating stutter.
  57.  
  58. local stutterPlosives = true            -- true: Will try to stutter words beginning
  59.                                             -- in plosive sounds (hard d, g, t, etc.).
  60.                                             -- false: only uses the stutterWords.
  61.  
  62. StutterText = function (str)
  63.     if type(str) ~= "string" then
  64.         error("Passed a non-string value to StutterText()!")
  65.         return
  66.     end
  67.  
  68.     local splCount = 0 -- Number to check against stuttersPerLine.
  69.  
  70.     str = str:gsub("(%w+)", function (word)
  71.         -- Using gsub, we'll run over every word in the string and check to see if we
  72.         -- should stutter it. Each word is run through this instanced function, with
  73.         -- the word object itself named (appropriately) "word".
  74.  
  75.         if splCount <= stuttersPerLine then -- Only generate stutter if within the limit.
  76.             if table.contains(stutterWords, string.lower(word)) then -- Check our stutterWords first.
  77.                 if math.random(100) <= stutterChance then
  78.                     word = stutter(word)
  79.                 end
  80.  
  81.                 -- Stuttered a word, so make sure to increment how many stutters we've used.
  82.                 splCount = splCount + 1
  83.  
  84.             elseif stutterPlosives == true then -- If allowed, try to stutter plosive sounds.
  85.                 if table.contains(plosives, word:sub(1, 1)) then
  86.                     if math.random(100) <= stutterChance then
  87.                         word = stutter(word)
  88.                     end
  89.                 end
  90.  
  91.                 splCount = splCount + 1
  92.  
  93.             end
  94.         end
  95.  
  96.         return word
  97.     end)
  98.  
  99.     return str -- Return the modified text.
  100. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement