food_crates.lua 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. --Variations on this task could include;
  2. --Oranges, Turnips, Beets, Carrots, Cabbage, Pears, Bananas
  3. local formspec_apple_good =
  4. 'formspec_version[3]'..
  5. 'size[10,7]'..
  6. 'image[0,0;10,7;tasks_food_crate_apples.png]'
  7. local function formspec_apple_bad()
  8. local x = math.random(10,80)/10
  9. local y = math.random(10,50)/10
  10. local formspec =
  11. 'formspec_version[3]'..
  12. 'size[10,7]'..
  13. 'image[0,0;10,7;tasks_food_crate_apples.png]'..
  14. 'image_button['..x..','..y..';1,1;tasks_food_crate_apple_rotten.png;rotten;;true;false;]'..
  15. 'image[0,0;10,7;tasks_food_crate_apples_overlay.png]'
  16. return formspec
  17. end
  18. local formspec_carrot_good =
  19. 'formspec_version[3]'..
  20. 'size[10,7]'..
  21. 'image[0,0;10,7;tasks_food_crate_carrots.png]'
  22. local function formspec_carrot_bad()
  23. local x = math.random(10,80)/10
  24. local y = math.random(10,50)/10
  25. local formspec =
  26. 'formspec_version[3]'..
  27. 'size[10,7]'..
  28. 'image[0,0;10,7;tasks_food_crate_carrots.png]'..
  29. 'image_button['..x..','..y..';1,1;tasks_food_crate_carrot_rotten.png;rotten;;true;false;]'..
  30. 'image[0,0;10,7;tasks_food_crate_carrots_overlay.png]'
  31. return formspec
  32. end
  33. local box = {
  34. type = 'fixed',
  35. fixed = {
  36. {-.5, -.5, -.4375, .5, .4375, .4375}}}
  37. minetest.register_node('tasks:food_crate_apple_idle',{
  38. description = 'Apple Crate',
  39. drawtype = 'mesh',
  40. mesh = 'tasks_food_crate.obj',
  41. tiles = {'tasks_food_crate.png', 'tasks_food_crate_apples_node.png'},
  42. paramtype = 'light',
  43. paramtype2 = 'facedir',
  44. selection_box = box,
  45. collision_box = box,
  46. groups = {breakable = 1, tasks=1},
  47. on_construct = function(pos)
  48. tasks.on_construct(pos, 'Apple Crate', 'Apple Crate with Rotten Fruit')
  49. end,
  50. on_rightclick = function(pos, node, clicker)
  51. tasks.right_click_on(pos, node, clicker, formspec_apple_good)
  52. end,
  53. on_timer = function(pos)
  54. local node = minetest.get_node(pos)
  55. local meta = minetest.get_meta(pos)
  56. local infotext = meta:get_string('info_repair')
  57. meta:set_string('infotext', infotext)
  58. minetest.swap_node(pos, {name = 'tasks:food_crate_apple_active', param2 = node.param2})
  59. end,
  60. })
  61. minetest.register_node('tasks:food_crate_apple_active',{
  62. description = 'Apple Crate',
  63. drawtype = 'mesh',
  64. mesh = 'tasks_food_crate.obj',
  65. tiles = {'tasks_food_crate.png', 'tasks_food_crate_apples_node_spoiled.png'},
  66. paramtype = 'light',
  67. paramtype2 = 'facedir',
  68. selection_box = box,
  69. collision_box = box,
  70. drop = 'tasks:food_crate_apple_idle',
  71. groups = {breakable = 1, tasks=1, not_in_creative_inventory=1},
  72. on_rightclick = function(pos, node, clicker)
  73. local name = clicker:get_player_name()
  74. local map_id = lobby.game[name]
  75. local sabotage_level = lobby.sabotage_level[map_id] or 5
  76. local meta = minetest.get_meta(pos)
  77. local level = meta:get_int('level') or 0
  78. if level < sabotage_level then
  79. tasks.player_config[name] = pos
  80. minetest.show_formspec(name, 'tasks:food_crate_apple', formspec_apple_bad())
  81. else
  82. minetest.chat_send_player(name, 'level is currently sabotaged, and you can\'t do this now.')
  83. end
  84. end,
  85. })
  86. minetest.register_node('tasks:food_crate_carrot_idle',{
  87. description = 'Carrot Crate',
  88. drawtype = 'mesh',
  89. mesh = 'tasks_food_crate.obj',
  90. tiles = {'tasks_food_crate.png', 'tasks_food_crate_carrots_node.png'},
  91. paramtype = 'light',
  92. paramtype2 = 'facedir',
  93. selection_box = box,
  94. collision_box = box,
  95. groups = {breakable = 1, tasks=1},
  96. on_construct = function(pos)
  97. tasks.on_construct(pos, 'Carrot Crate', 'Carrot Crate with Rotten Carrot')
  98. end,
  99. on_rightclick = function(pos, node, clicker)
  100. tasks.right_click_on(pos, node, clicker, formspec_carrot_good)
  101. end,
  102. on_timer = function(pos)
  103. local node = minetest.get_node(pos)
  104. local meta = minetest.get_meta(pos)
  105. local infotext = meta:get_string('info_repair')
  106. meta:set_string('infotext', infotext)
  107. minetest.swap_node(pos, {name = 'tasks:food_crate_carrot_active', param2 = node.param2})
  108. end,
  109. })
  110. minetest.register_node('tasks:food_crate_carrot_active',{
  111. description = 'Carrot Crate',
  112. drawtype = 'mesh',
  113. mesh = 'tasks_food_crate.obj',
  114. tiles = {'tasks_food_crate.png', 'tasks_food_crate_carrots_node_spoiled.png'},
  115. paramtype = 'light',
  116. paramtype2 = 'facedir',
  117. selection_box = box,
  118. collision_box = box,
  119. drop = 'tasks:food_crate_carrot_idle',
  120. groups = {breakable = 1, tasks=1, not_in_creative_inventory=1},
  121. on_rightclick = function(pos, node, clicker)
  122. local name = clicker:get_player_name()
  123. local map_id = lobby.game[name]
  124. local sabotage_level = lobby.sabotage_level[map_id] or 5
  125. local meta = minetest.get_meta(pos)
  126. local level = meta:get_int('level') or 0
  127. if level < sabotage_level then
  128. tasks.player_config[name] = pos
  129. minetest.show_formspec(name, 'tasks:food_crate_carrot', formspec_carrot_bad())
  130. else
  131. minetest.chat_send_player(name, 'level is currently sabotaged, and you can\'t do this now.')
  132. end
  133. end,
  134. })
  135. minetest.register_on_player_receive_fields(function(player, formname, fields)
  136. local name = player:get_player_name()
  137. if formname == 'tasks:food_crate_apple'then
  138. if fields.rotten then
  139. local pos = tasks.player_config[name]
  140. local node = minetest.get_node(pos)
  141. local meta = minetest.get_meta(pos)
  142. local infotext = meta:get_string('info_working')
  143. meta:set_string('infotext', infotext)
  144. tasks.add_xp(pos, node, player, 'tasks:food_crate_apple_idle')
  145. minetest.close_formspec(name, 'tasks:food_crate_apple')
  146. end
  147. elseif formname == 'tasks:food_crate_carrot'then
  148. if fields.rotten then
  149. local pos = tasks.player_config[name]
  150. local node = minetest.get_node(pos)
  151. local meta = minetest.get_meta(pos)
  152. local infotext = meta:get_string('info_working')
  153. meta:set_string('infotext', infotext)
  154. tasks.add_xp(pos, node, player, 'tasks:food_crate_carrot_idle')
  155. minetest.close_formspec(name, 'tasks:food_crate_carrot')
  156. end
  157. end
  158. end)