Advertisement
melzneni

sys2_syslib

Feb 19th, 2020
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. function split(s, delimiter)
  2. local result = {};
  3. for match in (s .. delimiter):gmatch("(.-)" .. delimiter) do
  4. table.insert(result, match);
  5. end
  6. return result;
  7. end
  8.  
  9. function getMsgData(msg)
  10. local i, j = string.find(msg, ":")
  11. local tag = string.sub(msg, 1, i - 1)
  12. local pts = split(string.sub(msg, i + 1, -1), ",")
  13. return tag, pts
  14. end
  15.  
  16. function log(group, txt)
  17. rednet.broadcast("@log:" .. group .. "," .. txt)
  18. end
  19.  
  20. function receiveRednet()
  21. while true do
  22. local id, msg = rednet.receive()
  23. if type(msg) == "string" then
  24. if string.len(msg) > 13 and string.sub(msg, 1, 14) == "<transmitted>:" then
  25. msg = string.sub(msg, 15, -1)
  26. local i=string.find(msg,",")
  27. id=tonumber(string.sub(msg,1,i-1))
  28. msg=string.sub(msg,i+1,-1)
  29. end
  30. if string.find(msg, ":") ~= nil then
  31. return id, msg
  32. end
  33. end
  34. end
  35. end
  36.  
  37. function getRawLabel(label)
  38. local l,l2=getLabelParts(label)
  39. if l2=="" then l2=label end
  40. return l2
  41. end
  42.  
  43. function getLabelParts(label)
  44. local i=string.find(label,"/")
  45. if i~=nil then
  46. return string.sub(label,0,i-1),string.sub(label,i+1,-1)
  47. end
  48. return label,nil
  49. end
  50.  
  51. function sendRednet(id,msg)
  52. rednet.send(id,msg)
  53. rednet.broadcast("@other:"..id..","..msg)
  54. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement