Guest User

Stutter System, for Edric

a guest
Nov 25th, 2013
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.88 KB | None | 0 0
  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. local stutter = function (word)--[[
  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. }
  44.  
  45. local stutterWords = {              -- Your guaranteed stutter words. These
  46.                                             -- are words you always want to check for
  47.                                             -- stuttering.
  48.     "gods", "focus", "boobies"
  49. }
  50.  
  51. local stutterChance = 75                -- Chance (in percentage) of how likely
  52.                                             -- stuttering will occur.
  53.  
  54. local stuttersPerLine = 2           -- Hard limit for how many words to use
  55.                                             -- for generating stutter.
  56.  
  57. local stutterPlosives = true            -- true: Will try to stutter words beginning
  58.                                             -- in plosive sounds (hard d, g, t, etc.).
  59.                                             -- false: only uses the stutterWords.
  60.  
  61. StutterText = function (str)
  62.     if type(str) ~= "string" then
  63.         error("Passed a non-string value to StutterText()!")
  64.         return
  65.     end
  66.  
  67.     local splCount = 0 -- Number to check against stuttersPerLine.
  68.  
  69.     str = str:gsub("(%w+)", function (word)
  70.         -- Using gsub, we'll run over every word in the string and check to see if we
  71.         -- should stutter it. Each word is run through this instanced function, with
  72.         -- the word object itself named (appropriately) "word".
  73.  
  74.         if splCount <= stuttersPerLine then -- Only generate stutter if within the limit.
  75.             if table.contains(stutterWords, word) then -- Check our stutterWords first.
  76.                 if math.random(100) <= stutterChance then
  77.                     word = stutter(word)
  78.                 end
  79.  
  80.                 -- Stuttered a word, so make sure to increment how many stutters we've used.
  81.                 splCount = splCount + 1
  82.  
  83.             elseif stutterPlosives == true then -- If allowed, try to stutter plosive sounds.
  84.                 if table.contains(plosives, word:sub(1, 1)) then
  85.                     if math.random(100) <= stutterChance then
  86.                         word = stutter(word)
  87.                     end
  88.                 end
  89.  
  90.                 splCount = splCount + 1
  91.  
  92.             end
  93.         end
  94.  
  95.         return word
  96.     end)
  97.  
  98.     return str -- Return the modified text.
  99. end
Advertisement
Add Comment
Please, Sign In to add comment