spawn.lua 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. potions.utils.spawn_up = function(nodes, height, node, delay, nmax, cb)
  2. local h = 0
  3. local i = 1
  4. local function go()
  5. for n = 1,nmax do
  6. if i > #nodes then
  7. i = 1
  8. h = h + 1
  9. if h > height then
  10. if type(cb) == 'function' then
  11. minetest.after(0, cb)
  12. end
  13. return
  14. end
  15. end
  16. local p = nodes[i]
  17. minetest.set_node({x=p.x, y=p.y+h, z=p.z}, {name=node})
  18. i = i + 1
  19. end
  20. minetest.after(delay, go)
  21. end
  22. go()
  23. end
  24. potions.utils.spawn_up_fn = function(nodes, height, node, delay, nmax, fn, cb)
  25. local h = 0
  26. local i = 1
  27. local function go()
  28. for n = 1,nmax do
  29. if i > #nodes then
  30. i = 1
  31. h = h + 1
  32. if h > height then
  33. if type(cb) == 'function' then
  34. minetest.after(0, cb)
  35. end
  36. return
  37. end
  38. end
  39. local p = nodes[i]
  40. minetest.set_node({x=p.x, y=p.y+h, z=p.z}, {name=node})
  41. fn(p, node)
  42. i = i + 1
  43. end
  44. minetest.after(delay, go)
  45. end
  46. go()
  47. end
  48. potions.utils.spawn_set_fn = function(nodes, delay, nmax, fn, cb)
  49. local i = 1
  50. local function go()
  51. for n = 1,nmax do
  52. if i > #nodes then
  53. if type(cb) == 'function' then
  54. minetest.after(0, cb)
  55. end
  56. return
  57. end
  58. local pn = nodes[i]
  59. minetest.set_node(pn[1], pn[2])
  60. fn(pn[1], pn[2])
  61. i = i + 1
  62. end
  63. minetest.after(delay, go)
  64. end
  65. go()
  66. end
  67. potions.utils.spawn_set = function(nodes, delay, nmax, cb)
  68. local i = 1
  69. local function go()
  70. for n = 1,nmax do
  71. if i > #nodes then
  72. if type(cb) == 'function' then
  73. minetest.after(0, cb)
  74. end
  75. return
  76. end
  77. local pn = nodes[i]
  78. minetest.set_node(pn[1], pn[2])
  79. if pn[3] then
  80. local meta = minetest.get_meta(pn[1])
  81. local inv = meta:get_inventory()
  82. for k,v in pairs(pn[3]) do
  83. inv:set_list(k, v)
  84. end
  85. end
  86. i = i + 1
  87. end
  88. minetest.after(delay, go)
  89. end
  90. go()
  91. end