Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tree = {}
- TREE = tree
- local function insert(sentence, path)
- local words = sentence:Split(" ")
- local current = tree
- for k, v in pairs(words) do
- current[v] = current[v] or {}
- current = current[v]
- end
- current[#current + 1] = path
- end
- local function clean(text)
- return text:gsub("[^%w ]+", ""):gsub(" +", " "):lower():Trim()
- end
- local function index()
- for k1, v1 in pairs(chatsounds.List) do
- for k2, v2 in pairs(v1) do
- if type(v2) == "table" then
- for k3, v3 in ipairs(v2) do
- insert(clean(k2), v3.path)
- end
- end
- end
- end
- end
- index()
- function match(text)
- local words = clean(text):Split(" ")
- local node = tree
- local current
- local found = {}
- local sentence = {}
- for i = 1, #words+1 do
- local word = words[i]
- ::SIGH::
- if node[word] then
- table.insert(sentence, word)
- node = node[word]
- elseif #sentence > 0 then
- sentence = table.concat(sentence, " ")
- table.insert(found, {key = sentence, data = node})
- sentence = {}
- node = tree
- goto SIGH
- end
- end
- for k,v in pairs(found) do
- chat.AddText(v.key)
- end
- end
- hook.Remove("OnPlayerChat", "a", function(a, b)
- match(b)
- end)
Advertisement
Add Comment
Please, Sign In to add comment