Advertisement
Guest User

Untitled

a guest
Oct 5th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. ==SERVER==
  2. ==========
  3. -- Mod Channels
  4. -- Requires dcbl_csm clientmod.
  5. local channel = minetest.mod_channel_join("dcbl")
  6. print(channel:is_writeable())
  7.  
  8. minetest.register_on_modchannel_message(function(channel_name, sender, message)
  9. print("channel_name:", channel_name)
  10. print("sender:", sender)
  11. print("message:", message)
  12. end)
  13.  
  14. --[[minetest.register_on_modchannel_signal(function(channel_name, signal)
  15. print("channel_name:", channel_name)
  16. print("signal:", signal)
  17. end)]]
  18.  
  19. minetest.register_chatcommand("c", {
  20. func = function(name, param)
  21. channel:send_all("hi")
  22. end,
  23. })
  24.  
  25. ==CLIENT==
  26. ==========
  27. local hl = minetest.sound_play("dcbl_front_center")
  28. local hr = minetest.sound_play("default_place_node_hard")
  29.  
  30. local player
  31. local channel
  32. local t = 0
  33.  
  34. minetest.register_on_connect(function()
  35. player = minetest.localplayer
  36. channel = minetest.mod_channel_join("dcbl")
  37. end)
  38.  
  39. minetest.register_on_modchannel_signal(function(
  40. channel_name, signal)
  41. print("channel_name:", channel_name)
  42. print("signal:", signal)
  43. end)
  44.  
  45. minetest.register_on_modchannel_message(function(
  46. channel_name, sender, message)
  47. print("channel_name:", channel_name)
  48. print("sender:", sender)
  49. print("message:", message)
  50. end)
  51.  
  52. -- STEP
  53. minetest.register_globalstep(function(dtime)
  54. if t > 10 then
  55. t = 0
  56. print("ping")
  57. end
  58. t = dtime + t
  59. end)
  60.  
  61. -- COMMANDS
  62. minetest.register_chatcommand("dcbl", {
  63. description = "Interface with dcbl.",
  64. params = "hr, hl, send, join, leave, list, test",
  65. func = function(param)
  66. if param == "hr" then
  67. return hr
  68. elseif param == "hl" then
  69. return hl
  70. elseif param == "send" then
  71. channel:send_all("Hello world!")
  72. elseif param == "join" then
  73. channel = minetest.mod_channel_join("dcbl")
  74. elseif param == "leave" then
  75. channel:leave()
  76. elseif param == "list" then
  77. print(dump(channel))
  78. elseif param == "test" then
  79. print(channel:is_writeable())
  80. else
  81. return false, "No parameter specified."
  82. end
  83. end,
  84. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement