Advertisement
chicka123

chatlaser

May 25th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. modules = peripheral.wrap("back")
  2. modules.capture("^!")
  3. rednet.open("right")
  4. targets = {}
  5. id = 0
  6.  
  7. function addTargets(msg)
  8. local point = string.find(msg, ",")
  9. if point and point > 2 then
  10. table.insert(targets, #targets + 1, string.sub(msg,1, point-1))
  11. print(string.sub(msg,1, point-1))
  12. addTargets(string.sub(msg, point + 1))
  13. else
  14. table.insert(targets, #targets + 1, msg)
  15. print(msg)
  16. end
  17. end
  18.  
  19. function chat()
  20. while true do
  21. local _, message, pattern = os.pullEvent("chat_capture")
  22. if string.sub(message, 1,8) == "!onsight" then
  23. if string.sub(message,10) == "default" then
  24. rednet.send(id, {"Skeleton","Creeper","Zombie","Spider","Witch"})
  25. rednet.send(id, 0.5)
  26. elseif string.len(string.sub(message,10)) > 0 then
  27. for i = 1, #targets do
  28. targets[i] = nil
  29. end
  30. addTargets(string.sub(message,10))
  31. rednet.send(id, targets)
  32. end
  33. elseif string.sub(message, 1,6) == "!power" then
  34. rednet.send(id, tonumber(string.sub(message, 8)))
  35. elseif string.sub(message, 1,3) == "!id" then
  36. id = tonumber(string.sub(message,4))
  37. elseif string.sub(message, 1,9) == "!offsight" then
  38. rednet.send(id, {})
  39. end
  40. end
  41. end
  42.  
  43. chat()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement