engine_0.lua 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. local formspec_config =
  2. 'size[6,3]'..
  3. 'label[.5,.25;Please enter XP to be earned upon repairing a damaged engine.\nIntegers only!]'..
  4. 'field[1,1.5;5,1;input;;]'..
  5. 'button_exit[2,2;2,1;save;Submit]'
  6. local formspec_good =
  7. 'size[6,3]'..
  8. 'textarea[1,1;5,2;;;This reactor is performing at peak efficiency.]'
  9. local formspec_bad =
  10. 'size[8,6]'..
  11. 'textarea[.5,;5,2;;;Looks like something is broke.\nGet a new part from a storage locker.]' ..
  12. 'button_exit[2.5,1.5;3,1;gimme;Grab a part request form]'..
  13. 'list[current_name;part;6,1;1,1;]'..
  14. 'list[current_player;main;0,3;8,3;]'
  15. minetest.register_node('tasks:engine_0_setup',{
  16. description = 'Arc Reactor (setup)',
  17. drawtype = 'mesh',
  18. mesh = 'tasks_engine_0.obj',
  19. tiles = {{name = 'tasks_pedestal.png'},
  20. {name = 'tasks_engine_0_off.png'},
  21. {name='tasks_blank.png'},
  22. },
  23. use_texture_alpha = true,
  24. light_source = 2,
  25. groups = {breakable = 1},
  26. on_construct = function(pos)
  27. local meta = minetest.get_meta(pos)
  28. meta:set_string('infotext', 'Unconfigured Arc Reactor')
  29. meta:set_string('formspec', formspec_config)
  30. meta:set_string('xp', '')
  31. end,
  32. on_receive_fields = function(pos, formname, fields, sender)
  33. local meta = minetest.get_meta(pos)
  34. if fields ['save'] then
  35. if not fields.input or fields.input == "" then
  36. return
  37. end
  38. local node = minetest.get_node(pos)
  39. local inv = meta:get_inventory()
  40. meta:set_string('xp', fields.input)
  41. inv:set_size('part', 1)
  42. meta:set_string('infotext', 'Arc Reactor')
  43. meta:set_string('formspec', formspec_good)
  44. minetest.swap_node(pos, {name = 'tasks:engine_0_on', param2 = node.param2})
  45. end
  46. end,
  47. })
  48. minetest.register_node('tasks:engine_0_on',{
  49. description = 'Arc Reactor',
  50. drawtype = 'mesh',
  51. mesh = 'tasks_engine_0.obj',
  52. tiles = {{name = 'tasks_pedestal.png'},
  53. {name = 'tasks_engine_0_on.png'},
  54. {name='tasks_engine_arc_0.png',
  55. animation = {
  56. type = 'vertical_frames',
  57. aspect_w = 64,
  58. aspect_h = 32,
  59. length = 2.0,},},
  60. },
  61. use_texture_alpha = true,
  62. light_source = 13,
  63. groups = {breakable = 1, not_in_creative_inventory=1},
  64. drop = 'tasks:engine_0_setup',
  65. on_rightclick = function(pos, node, clicker)
  66. local timer = minetest.get_node_timer(pos)
  67. local random_number = math.random(60,300)
  68. timer:start(random_number)
  69. end,
  70. on_timer = function(pos)
  71. local node = minetest.get_node(pos)
  72. local meta = minetest.get_meta(pos)
  73. minetest.swap_node(pos, {name = 'tasks:engine_0_off', param2 = node.param2})
  74. meta:set_string('formspec', formspec_bad)
  75. end,
  76. })
  77. minetest.register_node('tasks:engine_0_off',{
  78. description = 'Arc Reactor',
  79. drawtype = 'mesh',
  80. mesh = 'tasks_engine_0.obj',
  81. tiles = {{name = 'tasks_pedestal.png'},
  82. {name = 'tasks_engine_0_off.png'},
  83. {name='tasks_blank.png'},
  84. },
  85. use_texture_alpha = true,
  86. light_source = 2,
  87. groups = {breakable = 1, not_in_creative_inventory=1},
  88. drop = 'tasks:engine_0_setup',
  89. on_receive_fields = function(pos, formname, fields, sender)
  90. if fields ['gimme'] then
  91. local player_inv = sender:get_inventory()
  92. if not player_inv:contains_item('main', {name='tasks:gear_req', count = 4}) then
  93. player_inv:add_item('main', 'tasks:gear_req')
  94. else
  95. minetest.chat_send_player(sender:get_player_name(), 'You have too many of these already.')
  96. end
  97. end
  98. end,
  99. allow_metadata_inventory_put = function(pos, listname, index, stack)
  100. if listname == 'part' then
  101. if stack:get_name() == 'tasks:gear' then
  102. return 1
  103. else
  104. return 0
  105. end
  106. end
  107. end,
  108. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  109. local name = player:get_player_name()
  110. local meta = minetest.get_meta(pos)
  111. local xp = tonumber(meta:get_string('xp')) or 1
  112. local inv = meta:get_inventory()
  113. local node = minetest.get_node(pos)
  114. local timer = minetest.get_node_timer(pos)
  115. local random_number = math.random(60,300)
  116. inv:set_stack('part', 1, '')
  117. minetest.swap_node(pos, {name = 'tasks:engine_0_on', param2 = node.param2})
  118. meta:set_string('formspec', formspec_good)
  119. tasks.only_add_xp(xp, name)
  120. timer:start(random_number)
  121. end,
  122. })