engine_0.lua 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. local formspec_good =
  2. 'formspec_version[3]'..
  3. 'size[8,5]'..
  4. 'bgcolor[;neither]'..
  5. 'background[-1,-1;10,7;tasks_engines_working.png]'..
  6. 'hypertext[.5,.5;7,4;nil;<global halign=center valign=middle><style color=green size=30>This reactor is performing at peak efficiency.</style>]'
  7. local function formspec_bad(pos)
  8. local spos = pos.x ..','.. pos.y ..','.. pos.z
  9. local formspec =
  10. 'formspec_version[3]'..
  11. 'size[13,9]'..
  12. 'bgcolor[;neither]'..
  13. 'background[-1,-1;15,11;tasks_engine_0_broken.png]'..
  14. 'hypertext[6.5,.5;6,4;nil;<global halign=center valign=middle><style color=#94c6f5 size=30>Looks like a gear broke. You can get a new part from a storage locker with a request form.<style>]'..
  15. 'style_type[button;bgcolor=#97c3cd]'..
  16. 'button_exit[1,5.25;3,1;gimme;Grab A Request Form]'..
  17. 'button_exit[5,5.25;3,1;close;Close Window]'..
  18. 'listcolors[#10101020;#7DA3CC20]'..
  19. 'list[nodemeta:'..spos..';part;9,5.25;1,1;]'..
  20. 'list[current_player;main;.25,6.5;8,2;]'..
  21. 'listring[current_player;main]'..
  22. 'listring[nodemeta:'..spos..';part]'
  23. return formspec
  24. end
  25. minetest.register_node('tasks:engine_0_on',{
  26. description = 'Arc Reactor',
  27. drawtype = 'mesh',
  28. mesh = 'tasks_engine_0.obj',
  29. tiles = {{name = 'tasks_pedestal.png'},
  30. {name = 'tasks_engine_0_on.png'},
  31. {name='tasks_engine_arc_0.png',
  32. animation = {
  33. type = 'vertical_frames',
  34. aspect_w = 64,
  35. aspect_h = 32,
  36. length = 2.0,},},
  37. },
  38. use_texture_alpha = 'blend',
  39. light_source = 13,
  40. groups = {breakable = 1, tasks=1, plays_sound=1},
  41. _sound = 'tasks_engine_0_run',
  42. on_construct = function(pos)
  43. tasks.on_construct(pos, 'Arc Reactor', 'Broken Arc Reactor')
  44. end,
  45. on_rightclick = function(pos, node, clicker)
  46. tasks.right_click_on(pos, node, clicker, formspec_good)
  47. end,
  48. on_timer = function(pos)
  49. local node = minetest.get_node(pos)
  50. local meta = minetest.get_meta(pos)
  51. local infotext = meta:get_string('info_repair')
  52. minetest.sound_play('tasks_engine_0_stop', {pos = pos, gain = 1, max_hear_distance = 10})
  53. meta:set_string('infotext', infotext)
  54. minetest.after(11, function()
  55. minetest.swap_node(pos, {name = 'tasks:engine_0_off', param2 = node.param2})
  56. end)
  57. end,
  58. })
  59. minetest.register_node('tasks:engine_0_off',{
  60. description = 'Arc Reactor',
  61. drawtype = 'mesh',
  62. mesh = 'tasks_engine_0.obj',
  63. tiles = {{name = 'tasks_pedestal.png'},
  64. {name = 'tasks_engine_0_off.png'},
  65. {name='tasks_blank.png'},
  66. },
  67. use_texture_alpha = 'clip',
  68. light_source = 2,
  69. groups = {breakable = 1, not_in_creative_inventory=1, tasks=1},
  70. drop = 'tasks:engine_0_on',
  71. req_form = 'tasks:gear_req',
  72. req_count = 4,
  73. on_rightclick = function(pos, node, clicker)
  74. tasks.right_click_off(pos, node, clicker, formspec_bad(pos))
  75. end,
  76. allow_metadata_inventory_put = function(pos, listname, index, stack)
  77. if listname == 'part' then
  78. if stack:get_name() == 'tasks:gear' then
  79. return 1
  80. else
  81. return 0
  82. end
  83. end
  84. end,
  85. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  86. local name = player:get_player_name()
  87. local meta = minetest.get_meta(pos)
  88. local xp = meta:get_int('xp') or 1
  89. local inv = meta:get_inventory()
  90. local node = minetest.get_node(pos)
  91. local timer = minetest.get_node_timer(pos)
  92. local min = meta:get_int('time_min') or 30
  93. local max = meta:get_int('time_max') or 60
  94. local random_number = math.random(min,max)
  95. local infotext = meta:get_string('info_working')
  96. inv:set_stack('part', 1, '')
  97. minetest.sound_play('tasks_engine_0_start', {pos = pos, gain = 1, max_hear_distance = 10})
  98. minetest.swap_node(pos, {name = 'tasks:engine_0_on', param2 = node.param2})
  99. minetest.close_formspec(name, 'tasks:part_req_form')
  100. meta:set_string('infotext', infotext)
  101. tasks.only_add_xp(xp, name)
  102. timer:start(random_number)
  103. end,
  104. })