engine_1.lua 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 plasma accelerator 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_1_broken.png]'..
  14. 'hypertext[6.5,.5;6,4;nil;<global halign=center valign=middle><style color=#94c6f5 size=30>Looks like the plasma core failed. You can get a new one 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_1_on',{
  26. description = 'Plasma Accelerator',
  27. drawtype = 'mesh',
  28. mesh = 'tasks_engine_1.obj',
  29. tiles = {{name = 'tasks_pedestal.png'},
  30. {name = 'tasks_engine_1_on.png'},
  31. {name='tasks_plasma_tube_anim.png',
  32. animation = {
  33. type = 'vertical_frames',
  34. aspect_w = 32,
  35. aspect_h = 4,
  36. length = 0.5,},},
  37. },
  38. light_source = 13,
  39. _sound = 'tasks_engine_1_run',
  40. groups = {breakable = 1, tasks=1, plays_sound=1},
  41. on_construct = function(pos)
  42. tasks.on_construct(pos, 'Plasma Accelerator', 'Plasma Accelerator went too fast, needs repair.')
  43. end,
  44. on_rightclick = function(pos, node, clicker)
  45. tasks.right_click_on(pos, node, clicker, formspec_good)
  46. end,
  47. on_timer = function(pos)
  48. local node = minetest.get_node(pos)
  49. local meta = minetest.get_meta(pos)
  50. local infotext = meta:get_string('info_repair')
  51. minetest.sound_play('tasks_engine_1_stop', {pos = pos, gain = 1, max_hear_distance = 5})
  52. meta:set_string('infotext', infotext)
  53. minetest.after(5, function()
  54. minetest.swap_node(pos, {name = 'tasks:engine_1_off', param2 = node.param2})
  55. end)
  56. end,
  57. })
  58. minetest.register_node('tasks:engine_1_off',{
  59. description = 'Plasma Accelerator',
  60. drawtype = 'mesh',
  61. mesh = 'tasks_engine_1.obj',
  62. tiles = {{name = 'tasks_pedestal.png'},
  63. {name = 'tasks_engine_1_off.png'},
  64. {name='tasks_plasma_tube.png'},
  65. },
  66. light_source = 2,
  67. groups = {breakable = 1, not_in_creative_inventory=1, tasks=1},
  68. drop = 'tasks:engine_1_on',
  69. req_form = 'tasks:plasma_core_req',
  70. req_count = 4,
  71. on_rightclick = function(pos, node, clicker)
  72. tasks.right_click_off(pos, node, clicker, formspec_bad(pos))
  73. end,
  74. allow_metadata_inventory_put = function(pos, listname, index, stack)
  75. if listname == 'part' then
  76. if stack:get_name() == 'tasks:plasma_core' then
  77. return 1
  78. else
  79. return 0
  80. end
  81. end
  82. end,
  83. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  84. local name = player:get_player_name()
  85. local meta = minetest.get_meta(pos)
  86. local xp = meta:get_int('xp') or 1
  87. local inv = meta:get_inventory()
  88. local node = minetest.get_node(pos)
  89. local timer = minetest.get_node_timer(pos)
  90. local min = meta:get_int('time_min') or 30
  91. local max = meta:get_int('time_max') or 60
  92. local random_number = math.random(min,max)
  93. local infotext = meta:get_string('info_working')
  94. inv:set_stack('part', 1, '')
  95. minetest.sound_play('tasks_engine_1_start', {pos = pos, gain = 1, max_hear_distance = 10})
  96. minetest.swap_node(pos, {name = 'tasks:engine_1_on', param2 = node.param2})
  97. minetest.close_formspec(name, 'tasks:part_req_form')
  98. meta:set_string('infotext', infotext)
  99. tasks.only_add_xp(xp, name)
  100. timer:start(random_number)
  101. end,
  102. })