rubbish.lua 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. local trash_bin_setup =
  2. 'size[6,3]'..
  3. 'label[.5,.25;How much XP should be given for picking up trash?]'..
  4. 'field[1,1.5;5,1;input;;]'..
  5. 'button_exit[2,2;2,1;save;Submit]'
  6. local trash_bin_formspec =
  7. 'size[8,6]'..
  8. 'textarea[.5,;5,2;;;Put trash in its place]' ..
  9. 'list[current_name;trash;6,1;1,1;]'..
  10. 'list[current_player;main;0,3;8,2;]'..
  11. 'listring[current_player;main]'..
  12. 'listring[current_name;trash]'
  13. minetest.register_node('tasks:trash_bin', { --This is the node that can be placed.
  14. description = 'Trash Bin',
  15. drawtype = 'mesh',
  16. mesh = 'tasks_trash_bin.obj',
  17. tiles = {'tasks_trash_bin.png'},
  18. paramtype2 = 'facedir',
  19. groups = {breakable=1, tasks=1},
  20. collision_box = {
  21. type = 'fixed',
  22. fixed = {{-.4, -.5, -.3, .4, .35, .3}}
  23. },
  24. selection_box = {
  25. type = 'fixed',
  26. fixed = {{-.4, -.5, -.3, .4, .35, .3}}
  27. },
  28. on_construct = function(pos)
  29. local meta = minetest.get_meta(pos)
  30. local inv = meta:get_inventory()
  31. inv:set_size('trash', 1)
  32. meta:set_string('infotext', 'Trash bin')
  33. meta:set_string('formspec', trash_bin_formspec)
  34. meta:set_int('xp', 1)
  35. end,
  36. on_receive_fields = function(pos, forname, fields, sender)
  37. local meta = minetest.get_meta(pos)
  38. if fields ['save'] then
  39. if not fields.input or fields.input == "" then
  40. return
  41. end
  42. if tasks.is_integer(fields.input) then
  43. meta:set_int('xp', fields.input)
  44. meta:set_string('infotext', 'Trash Bin')
  45. meta:set_string('formspec', trash_bin_formspec)
  46. else
  47. minetest.chat_send_player(sender:get_player_name(), 'Double check your input please.')
  48. end
  49. end
  50. end,
  51. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  52. local name = player:get_player_name()
  53. local meta = minetest.get_meta(pos)
  54. local inv = meta:get_inventory()
  55. local input_stack = inv:get_stack(listname, 1)
  56. local input = input_stack:get_name()
  57. local item = string.sub(stack:get_name(), -7, -3)
  58. if item == 'trash' then
  59. local xp = meta:get_int('xp') or 1
  60. tasks.only_add_xp(xp, name)
  61. minetest.chat_send_player(name, 'Thanks for doing your part!')
  62. end
  63. inv:set_stack(listname, index, nil)
  64. end,
  65. })
  66. minetest.register_node('tasks:trash_1', {
  67. description = 'Rubbish',
  68. drawtype = 'mesh',
  69. mesh = 'decals_mesh.obj',
  70. tiles = {'tasks_trash_1.png'},
  71. use_texture_alpha = 'clip',
  72. inventory_image = 'tasks_trash_1.png',
  73. wield_image = 'tasks_trash_1.png',
  74. paramtype = 'light',
  75. paramtype2 = 'facedir',
  76. walkable = false,
  77. sunlight_propagates = true,
  78. buildable_to = true,
  79. stack_max = 1,
  80. groups = {breakable=1},
  81. selection_box = {
  82. type = 'fixed',
  83. fixed = {{-.4, -.5, -.4, .4, -.45, .4}}
  84. },
  85. on_drop = lobby.no_drop,
  86. after_place_node = function(pos, placer)
  87. if not minetest.check_player_privs(placer, {creative = true}) then
  88. minetest.chat_send_player(placer:get_player_name(), 'Don\'t be a litter bug!')
  89. minetest.remove_node(pos)
  90. return true
  91. else
  92. return false
  93. end
  94. end,
  95. on_punch = function(pos, node, puncher, pointed_thing)
  96. local player_inv = puncher:get_inventory()
  97. if not player_inv:contains_item('main', {name='tasks:trash_1', count = 1}) then
  98. local timer = minetest.get_node_timer(pos)
  99. player_inv:add_item('main', 'tasks:trash_1')
  100. minetest.set_node(pos, {name = 'tasks:trash', param2 = 1})
  101. local time = math.random(30,600)
  102. timer:start(time)
  103. else
  104. minetest.chat_send_player(puncher:get_player_name(), 'You can only carry one piece of trash at a time.')
  105. end
  106. end,
  107. })
  108. for i = 2,8 do
  109. minetest.register_node('tasks:trash_'..i, {
  110. description = 'Rubbish',
  111. drawtype = 'mesh',
  112. mesh = 'decals_mesh.obj',
  113. tiles = {'tasks_trash_'..i..'.png'},
  114. use_texture_alpha = 'clip',
  115. inventory_image = 'tasks_trash_'..i..'.png',
  116. wield_image = 'tasks_trash_'..i..'.png',
  117. paramtype = 'light',
  118. paramtype2 = 'facedir',
  119. walkable = false,
  120. sunlight_propagates = true,
  121. buildable_to = true,
  122. stack_max = 1,
  123. groups = {not_in_creative_inventory=1, breakable=1},
  124. selection_box = {
  125. type = 'fixed',
  126. fixed = {{-.4, -.5, -.4, .4, -.45, .4}}
  127. },
  128. on_drop = lobby.no_drop,
  129. after_place_node = function(pos, placer)
  130. if not minetest.check_player_privs(placer, {creative = true}) then
  131. minetest.chat_send_player(placer:get_player_name(), 'Don\'t be a litter bug!')
  132. minetest.remove_node(pos)
  133. return true
  134. else
  135. return false
  136. end
  137. end,
  138. on_punch = function(pos, node, puncher, pointed_thing)
  139. local player_inv = puncher:get_inventory()
  140. if not player_inv:contains_item('main', {name='tasks:trash_'..i, count = 1}) then
  141. local timer = minetest.get_node_timer(pos)
  142. player_inv:add_item('main', 'tasks:trash_'..i)
  143. minetest.set_node(pos, {name = 'tasks:trash', param2 = 1})
  144. local time = math.random(30,600)
  145. timer:start(time)
  146. else
  147. minetest.chat_send_player(puncher:get_player_name(), 'You can only carry one piece of trash at a time.')
  148. end
  149. end,
  150. })
  151. end
  152. minetest.register_node('tasks:trash', {
  153. description = 'Invisible Rubbish',
  154. drawtype = 'airlike',
  155. paramtype = 'light',
  156. walkable = false,
  157. pointable = false,
  158. sunlight_propagates = true,
  159. buildable_to = true,
  160. groups = {not_in_creative_inventory=1, breakable=1},
  161. on_timer = function(pos)
  162. local ran_param2 = math.random(0,3)
  163. local trash_ran = math.random(1,8)
  164. minetest.set_node(pos, {name = 'tasks:trash_'..trash_ran, param2 = ran_param2})
  165. end,
  166. })