MudkipTheEpic

Command Runnah

Apr 25th, 2013
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.12 KB | None | 0 0
  1. local avp=peripheral.wrap("right")
  2. local cmd=peripheral.wrap("left")
  3. if not fs.isDir("commandsList") then fs.delete("commandsList") fs.makeDir("commandsList") end
  4.  
  5. local opList={MudkipTheEpic=true}
  6.  
  7. local function checkExists(command)
  8.     return (fs.exists("CommandsList/"..command) and not fs.isDir("CommandsList/"..command) and (string.sub(fs.combine("CommandsList/", command),1,13)=="CommandsList/" or fs.combine("",command)==("" or "/")))
  9. end
  10.  
  11. local function tellPlayer(player,text)
  12.     cmd.setCommand("tell "..player.." "..text)
  13.     return cmd.runCommand()
  14. end
  15.  
  16. while true do
  17.     local _,username,chatmessage=os.pullEvent("chat_message")--or raw
  18.     print(username.." said \""..chatmessage.."\".")
  19.     local command=nil
  20.     local commandList={}
  21.     string.gsub(chatmessage,"([^%s]+)",function(a) if not command then command=a else table.insert(commandList,a) end end)
  22.     if opList[username] and checkExists(command) then
  23.         pcall(function() shell.run("CommandsList/"..command,username,unpack(commandList)) end)
  24.     elseif not opList[username] and checkExists(command) then
  25.         tellPlayer(username,"You are not permitted to use this command.")
  26.     end
  27. end
Advertisement
Add Comment
Please, Sign In to add comment