Advertisement
DracoFAAD

CmdHandler

Feb 13th, 2023
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. local module = {}
  2. module.createHandler = function(prefix, wl)
  3. local handler = {}
  4.  
  5. handler.prefix = prefix
  6. handler.commands = {}
  7.  
  8. handler.createCommand = function(name, callback)
  9. table.insert(handler.commands, {name, callback})
  10. end
  11.  
  12. local function checkIfCommand(plr, msg)
  13. do --CheckPlr
  14. if wl ~= "all" then
  15. if typeof(wl) == "Instance" then if wl:IsA("Team") then if plr.Team ~= wl then return end end if wl:IsA("Player") then if plr ~= wl then return end end
  16. elseif typeof(wl) == "table" then local y = false for i, v in pairs(wl) do if v == plr.UserId then y = true end end if y == false then return end
  17. elseif typeof(wl) == "string" then if plr.Name ~= wl then return end
  18. elseif typeof(wl) == "number" then if plr.UserId ~= wl then return end end
  19. end
  20. end
  21.  
  22. local args = string.split(msg, " ")
  23. local prefix = args[1]
  24. table.remove(args, 1)
  25.  
  26. for i, v in pairs(handler.commands) do
  27. if string.lower(prefix) == handler.prefix .. string.lower(v[1]) then
  28. v[2](plr, args)
  29. return
  30. end
  31. end
  32. end
  33.  
  34. --[[ PLAYER LOOP :]] for i, v in pairs(game:GetService("Players"):GetPlayers()) do v.Chatted:Connect(function(msg) checkIfCommand(v, msg) end) end game:GetService("Players").PlayerAdded:Connect(function(plr) plr.Chatted:Connect(function(msg) checkIfCommand(plr, msg) end) end)
  35. return handler
  36. end
  37. return module
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement