imposiblaa

Command Base

Oct 20th, 2023 (edited)
640
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.24 KB | None | 0 0
  1. globalPort = 5296
  2.  
  3. modem = peripheral.find("modem")
  4. modem.open(globalPort)
  5. db = {}
  6.  
  7.    
  8.  
  9. commands = {
  10.     alert = function(input)
  11.         assert(type(input) == "string", "helloWorld expects a string for its input")
  12.         print("ALERT: " .. input)
  13.         return true
  14.     end,
  15. }
  16.  
  17.  
  18. function commandParser(event, side, channel, replyChannel, message, distance)
  19.     print(textutils.serialise(message))
  20.     if commands[message.cmd] ~= nil and message.args ~= nil then
  21.         ran, err = pcall(commands[message.cmd], table.unpack(message.args))
  22.         if not ran then
  23.             print(("Error in \"%s\": %s"):format(message.cmd, err))
  24.         end
  25.     else
  26.         print(("No command named \"%s\" found"):format(message.cmd))
  27.     end
  28. end
  29.  
  30. function commandRunner(command, target, arguments)
  31.     assert(type(command) == "string", "commandRunner expects a string for its input \"command\"")
  32.     assert(type(target) == "number", "commandRunner expects a number for its input \"target\"")
  33.     assert(type(arguments) == "table", "commandRunner expects a table for its input \"arguments\"")
  34.     modem.transmit(5296,5296, {cmd=command, tgt=target, args=arguments})
  35. end
  36.    
  37.  
  38.  
  39. while true do
  40.     commandParser(os.pullEvent("modem_message"))
  41.            
  42. end
  43.  
Advertisement
Add Comment
Please, Sign In to add comment