Advertisement
Guest User

Untitled

a guest
May 23rd, 2023
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. -- VoiceModule
  2. VoiceModule = {
  3. voices = nil,
  4. voiceCount = 0,
  5. lastVoice = 0,
  6. timeout = nil,
  7. chance = nil,
  8. npcHandler = nil
  9. }
  10.  
  11. -- Creates a new instance of VoiceModule
  12. function VoiceModule:new(voices, timeout, chance)
  13. local obj = {}
  14. setmetatable(obj, self)
  15. self.__index = self
  16.  
  17. obj.voices = voices
  18. for i = 1, #obj.voices do
  19. local voice = obj.voices[i]
  20. if voice.yell then
  21. voice.yell = nil
  22. voice.talktype = TALKTYPE_YELL
  23. else
  24. voice.talktype = TALKTYPE_SAY
  25. end
  26. end
  27.  
  28. obj.voiceCount = #voices
  29. obj.timeout = timeout or 10
  30. obj.chance = chance or 25
  31. return obj
  32. end
  33.  
  34. function VoiceModule:init(handler)
  35. return true
  36. end
  37.  
  38. function VoiceModule:callbackOnThink()
  39. if self.lastVoice < os.time() then
  40. self.lastVoice = os.time() + self.timeout
  41. if math.random(100) < self.chance then
  42. local voice = self.voices[math.random(self.voiceCount)]
  43. Npc():say(voice.text, voice.talktype)
  44. end
  45. end
  46. return true
  47. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement