transformer.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. local col_box = {
  2. type = 'fixed',
  3. fixed = {{-.45, -.5, -.45, 1.5, .4, .5},
  4. {.7, .4, -.35, 1.4, 1, .35}}}
  5. local formspec_good =
  6. 'size[6,3]'..
  7. 'textarea[1,1;5,2;;;Everything is functioning properly]'
  8. local function formspec_bad(pos)
  9. local spos = pos.x ..','.. pos.y ..','.. pos.z
  10. local formspec =
  11. 'size[8,6]'..
  12. 'textarea[.5,;5,2;;;There must have been a power surge.\nGet a new part from a storage locker.]' ..
  13. 'button_exit[2.5,1.5;3,1;gimme;Grab a part request form]'..
  14. 'list[nodemeta:'..spos..';part;6,1;1,1;]'..
  15. 'list[current_player;main;0,3;8,2;]'..
  16. 'listring[current_player;main]'..
  17. 'listring[nodemeta:'..spos..';part]'
  18. return formspec
  19. end
  20. minetest.register_node('tasks:transformer_0_on',{
  21. description = 'Power Transformer',
  22. drawtype = 'mesh',
  23. mesh = 'tasks_transformer.obj',
  24. tiles = {'tasks_transformer.png'},
  25. paramtype2 = 'facedir',
  26. selection_box = col_box,
  27. collision_box = col_box,
  28. groups = {breakable = 1, tasks=1},
  29. on_construct = function(pos)
  30. tasks.on_construct(pos, 'Power Transformer', 'Laughably Large Paperweight')
  31. end,
  32. on_rightclick = function(pos, node, clicker)
  33. tasks.right_click_on(pos, node, clicker, formspec_good)
  34. end,
  35. on_timer = function(pos)
  36. local node = minetest.get_node(pos)
  37. local meta = minetest.get_meta(pos)
  38. local infotext = meta:get_string('info_repair')
  39. minetest.swap_node(pos, {name = 'tasks:transformer_0_off', param2 = node.param2})
  40. meta:set_string('infotext', infotext)
  41. end
  42. })
  43. minetest.register_node('tasks:transformer_0_off',{
  44. description = 'Power Transformer',
  45. drawtype = 'mesh',
  46. mesh = 'tasks_transformer.obj',
  47. tiles = {'tasks_transformer.png'},
  48. paramtype2 = 'facedir',
  49. selection_box = col_box,
  50. collision_box = col_box,
  51. groups = {breakable = 1, not_in_creative_inventory=1, tasks=1},
  52. drop = 'tasks:transformer_0_on',
  53. req_form = 'tasks:fuse_req',
  54. req_count = 4,
  55. on_rightclick = function(pos, node, clicker)
  56. tasks.right_click_off(pos, node, clicker, formspec_bad(pos))
  57. end,
  58. allow_metadata_inventory_put = function(pos, listname, index, stack)
  59. if listname == 'part' then
  60. if stack:get_name() == 'tasks:fuse' then
  61. return 1
  62. else
  63. return 0
  64. end
  65. end
  66. end,
  67. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  68. local name = player:get_player_name()
  69. local meta = minetest.get_meta(pos)
  70. local xp = meta:get_int('xp') or 1
  71. local inv = meta:get_inventory()
  72. local node = minetest.get_node(pos)
  73. local timer = minetest.get_node_timer(pos)
  74. local min = meta:get_int('time_min') or 30
  75. local max = meta:get_int('time_max') or 60
  76. local random_number = math.random(min,max)
  77. local infotext = meta:get_string('info_working')
  78. inv:set_stack('part', 1, '')
  79. minetest.swap_node(pos, {name = 'tasks:transformer_0_on', param2 = node.param2})
  80. minetest.close_formspec(name, 'tasks:part_req_form')
  81. meta:set_string('infotext', infotext)
  82. tasks.only_add_xp(xp, name)
  83. timer:start(random_number)
  84. end
  85. })