Pirnogion

[OC]MEOW

Mar 9th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.01 KB | None | 0 0
  1. local event = require("event")
  2. local component = require("component")
  3. local chat = component.chat_box
  4. local cb = component.command_block
  5. local unicode = require "unicode"
  6.  
  7. local disableWhitelist = false
  8.  
  9. local function runCommand(command, ...)
  10.   local command = "/" .. command .. " " .. table.concat({...}, " ")
  11.   --print(command)
  12.  
  13.   cb.setCommand(command or defaultCommand)
  14.   cb.executeCommand()
  15. end
  16.  
  17. local function findKeywords(str, tbl)
  18.   local keywordsCount = {}
  19.  
  20.   for k, v in pairs(tbl) do
  21.     string.gsub(unicode.lower(str), k, function(k)
  22.       if ( not keywordsCount[k] ) then keywordsCount[k] = 0 end
  23.  
  24.       keywordsCount[k] = keywordsCount[k] + 1
  25.     end)
  26.  
  27.     --print(k, '=', keywordsCount[k])
  28.   end
  29.  
  30.   return keywordsCount
  31. end
  32.  
  33. local sounds = {
  34.   ["мяу"] = "mob.cat.meow",
  35.   ["meow"] = "mob.cat.meow",
  36.   ["мяя"] = "mob.cat.meow",
  37.   ["мур"] = "mob.cat.purreow",
  38.  
  39.   ["гав"] = "mob.wolf.bark",
  40.   ["bark"] = "mob.wolf.bark",
  41.  
  42.   ["hiss"] = "mob.cat.hiss",
  43.  
  44.   ["creeper"] = "mob.creeper.say",
  45.  
  46.   ["fuse"] = "random.fuse",
  47.  
  48.   ["хрю"] = "mob.pig.say"
  49. }
  50.  
  51. local whitelist = {
  52.   ["paladincvm"] = true,
  53.   ["pirnogion"] = true,
  54.   ["pornogion"] = true,
  55.   ["tamik_77"] = true,
  56.   ["Tinrion"] = true,
  57. }
  58.  
  59. print("Copyright 2016 (C) Pirnogion - Посвящается Пиру и Палу")
  60.  
  61. while true do
  62.  
  63.   local e = {event.pull()}
  64.  
  65.   if (e[1] == "chat_message") then
  66.     --local sound = sounds[ unicode.lower(e[4]) ]
  67.     local access = disableWhitelist or whitelist[ unicode.lower(e[3]) ]
  68.  
  69.     --print("Debug: ", sound, access)
  70.  
  71.     local keywordsCount = findKeywords(e[4], sounds)
  72.  
  73.     if ( access ) then
  74.       for k, v in pairs(sounds) do
  75.         if ( keywordsCount[k] ) then
  76.           chat.say(e[3] .. " сказал " .. keywordsCount[k] .. " раз " .. k)            
  77.           for i=1, keywordsCount[k], 1 do
  78.  
  79.             runCommand("playsound", v, "@a")
  80.             os.sleep(0.2)
  81.           end
  82.         end
  83.       end
  84.     end
  85.   end
  86. end
Add Comment
Please, Sign In to add comment