forcefield_gen.lua 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. local formspec_good =
  2. 'formspec_version[3]'..
  3. 'size[10,12]'..
  4. 'bgcolor[;neither]'..
  5. 'background[-1,-1;12,14;tasks_forcefield_working_bg.png]'..
  6. 'image[3,1;1,1;tasks_quantum_coil.png]'..
  7. 'hypertext[0,4.75;4.,3;nil;<global halign=center valign=middle><style color=black size=30>Shields at 100%<style>]'
  8. local function formspec_bad(pos)
  9. local spos = pos.x ..','.. pos.y ..','.. pos.z
  10. local formspec =
  11. 'formspec_version[3]'..
  12. 'size[10,12]'..
  13. 'bgcolor[;neither]'..
  14. 'background[-1,-1;12,14;tasks_forcefield_bg.png]'..
  15. 'hypertext[0,4.75;4.,3;nil;<global halign=center valign=middle><style color=black size=30>Shields down!!! New Quantum coil needed ASAP.<style>]'..
  16. 'button_exit[6.25,6.25;3,1;gimme;Grab A Request Form]'..
  17. 'list[nodemeta:'..spos..';part;3,1;1,1;]'..
  18. 'listcolors[#10101020;#7DA3CC20]'..
  19. 'list[current_player;main;.125,9.75;8,2;]'..
  20. 'listring[current_player;main]'..
  21. 'listring[nodemeta:'..spos..';part]'..
  22. 'image[3,1;1,1;tasks_quantum_coil_line.png]'
  23. return formspec
  24. end
  25. local on_box = {
  26. type = 'fixed',
  27. fixed = {
  28. {-.5, -.5, -.5, .5, .5, .5},
  29. {-1.5, -.5, 1.45, 1.5, 1.5, 1.5}},}
  30. local off_box = {
  31. type = 'fixed',
  32. fixed = {
  33. {-.5, -.5, -.5, .5, .5, .5},},}
  34. minetest.register_node('tasks:forcefield_gen_on',{
  35. description = 'Forcefield Generator',
  36. drawtype = 'mesh',
  37. mesh = 'tasks_forcefield_gen.obj',
  38. tiles = {name = 'tasks_forcefield_gen_on.png'},
  39. paramtype = 'light',
  40. paramtype2 = 'facedir',
  41. light_source = 12,
  42. selection_box = on_box,
  43. collision_box = on_box,
  44. groups = {breakable = 1, tasks=1},
  45. on_construct = function(pos)
  46. tasks.on_construct(pos, 'Forcefield Generator', 'More like hole Generator')
  47. end,
  48. on_rightclick = function(pos, node, clicker)
  49. tasks.right_click_on(pos, node, clicker, formspec_good)
  50. end,
  51. on_timer = function(pos)
  52. local node = minetest.get_node(pos)
  53. local meta = minetest.get_meta(pos)
  54. local infotext = meta:get_string('info_repair')
  55. meta:set_string('infotext', infotext)
  56. minetest.swap_node(pos, {name = 'tasks:forcefield_gen_off', param2 = node.param2})
  57. end,
  58. })
  59. minetest.register_node('tasks:forcefield_gen_off',{
  60. description = 'Forcefield Generator',
  61. drawtype = 'mesh',
  62. mesh = 'tasks_forcefield_gen.obj',
  63. tiles = {name = 'tasks_forcefield_gen_off.png'},
  64. paramtype = 'light',
  65. paramtype2 = 'facedir',
  66. selection_box = off_box,
  67. collision_box = off_box,
  68. groups = {breakable = 1, not_in_creative_inventory=1, tasks=1},
  69. drop = 'tasks:forcefield_gen_on',
  70. req_form = 'tasks:quantum_coil_req',
  71. req_count = 2,
  72. on_rightclick = function(pos, node, clicker)
  73. tasks.right_click_off(pos, node, clicker, formspec_bad(pos))
  74. end,
  75. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  76. if listname == 'part' then
  77. if stack:get_name() == 'tasks:quantum_coil' then
  78. local player_attributes = player:get_meta()
  79. local luck = player_attributes:get_int('luck')
  80. if luck*2 < math.random(10) then
  81. minetest.chat_send_player(player:get_player_name(), 'You drop the coil, fortunately it doesn\'t break.')
  82. return 0
  83. else
  84. return 1
  85. end
  86. end
  87. return 0
  88. end
  89. end,
  90. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  91. local name = player:get_player_name()
  92. local meta = minetest.get_meta(pos)
  93. local xp = meta:get_int('xp') or 10
  94. local inv = meta:get_inventory()
  95. local node = minetest.get_node(pos)
  96. local timer = minetest.get_node_timer(pos)
  97. local min = meta:get_int('time_min') or 300
  98. local max = meta:get_int('time_max') or 600
  99. local random_number = math.random(min,max)
  100. local infotext = meta:get_string('info_working')
  101. inv:set_stack('part', 1, '')
  102. minetest.swap_node(pos, {name = 'tasks:forcefield_gen_on', param2 = node.param2})
  103. minetest.close_formspec(name, 'tasks:part_req_form')
  104. meta:set_string('infotext', infotext)
  105. tasks.only_add_xp(xp, name)
  106. timer:start(random_number)
  107. end,
  108. })