123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- local formspec_config =
- 'size[6,3]'..
- 'label[.5,.25;Please enter XP to be earned upon repairing a damaged engine.\nIntegers only!]'..
- 'field[1,1.5;5,1;input;;]'..
- 'button_exit[2,2;2,1;save;Submit]'
- local formspec_good =
- 'size[6,3]'..
- 'textarea[1,1;5,2;;;This plasma accelerator is performing at peak efficiency.]'
- local formspec_bad =
- 'size[8,6]'..
- 'textarea[.5,;5,2;;;Looks like something is broke.\nGet a new part from a storage locker.]' ..
- 'button_exit[2.5,1.5;3,1;gimme;Grab a part request form]'..
- 'list[current_name;part;6,1;1,1;]'..
- 'list[current_player;main;0,3;8,3;]'
- minetest.register_node('tasks:engine_1_setup',{
- description = 'Plasma Accelerator (setup)',
- drawtype = 'mesh',
- mesh = 'tasks_engine_1.obj',
- tiles = {{name = 'tasks_pedestal.png'},
- {name = 'tasks_engine_1_off.png'},
- {name='tasks_plasma_tube.png'},
- },
- use_texture_alpha = true,
- light_source = 2,
- groups = {breakable = 1},
- on_construct = function(pos)
- local meta = minetest.get_meta(pos)
- meta:set_string('infotext', 'Unconfigured Arc Reactor')
- meta:set_string('formspec', formspec_config)
- meta:set_string('xp', '')
- end,
- on_receive_fields = function(pos, formname, fields, sender)
- local meta = minetest.get_meta(pos)
- if fields ['save'] then
- if not fields.input or fields.input == "" then
- return
- end
- local node = minetest.get_node(pos)
- local inv = meta:get_inventory()
- meta:set_string('xp', fields.input)
- inv:set_size('part', 1)
- meta:set_string('infotext', 'Plasma Accelerator')
- meta:set_string('formspec', formspec_good)
- minetest.swap_node(pos, {name = 'tasks:engine_1_on', param2 = node.param2})
- end
- end,
- })
- minetest.register_node('tasks:engine_1_on',{
- description = 'Plasma Accelerator',
- drawtype = 'mesh',
- mesh = 'tasks_engine_1.obj',
- tiles = {{name = 'tasks_pedestal.png'},
- {name = 'tasks_engine_1_on.png'},
- {name='tasks_plasma_tube_anim.png',
- animation = {
- type = 'vertical_frames',
- aspect_w = 32,
- aspect_h = 4,
- length = 0.5,},},
- },
- use_texture_alpha = true,
- light_source = 13,
- groups = {breakable = 1, not_in_creative_inventory=1},
- drop = 'tasks:engine_1_setup',
- on_rightclick = function(pos, node, clicker)
- local timer = minetest.get_node_timer(pos)
- local random_number = math.random(60,300)
- timer:start(random_number)
- end,
- on_timer = function(pos)
- local node = minetest.get_node(pos)
- local meta = minetest.get_meta(pos)
- minetest.swap_node(pos, {name = 'tasks:engine_1_off', param2 = node.param2})
- meta:set_string('formspec', formspec_bad)
- end,
- })
- minetest.register_node('tasks:engine_1_off',{
- description = 'Plasma Accelerator',
- drawtype = 'mesh',
- mesh = 'tasks_engine_1.obj',
- tiles = {{name = 'tasks_pedestal.png'},
- {name = 'tasks_engine_1_off.png'},
- {name='tasks_plasma_tube.png'},
- },
- use_texture_alpha = true,
- light_source = 2,
- groups = {breakable = 1, not_in_creative_inventory=1},
- drop = 'tasks:engine_1_setup',
- on_receive_fields = function(pos, formname, fields, sender)
- if fields ['gimme'] then
- local player_inv = sender:get_inventory()
- if not player_inv:contains_item('main', {name='tasks:plasma_core_req', count = 4}) then
- player_inv:add_item('main', 'tasks:plasma_core_req')
- else
- minetest.chat_send_player(sender:get_player_name(), 'You have too many of these already.')
- end
- end
- end,
- allow_metadata_inventory_put = function(pos, listname, index, stack)
- if listname == 'part' then
- if stack:get_name() == 'tasks:plasma_core' then
- return 1
- else
- return 0
- end
- end
- end,
- on_metadata_inventory_put = function(pos, listname, index, stack, player)
- local name = player:get_player_name()
- local meta = minetest.get_meta(pos)
- local xp = tonumber(meta:get_string('xp')) or 1
- local inv = meta:get_inventory()
- local node = minetest.get_node(pos)
- local timer = minetest.get_node_timer(pos)
- local random_number = math.random(60,300)
- inv:set_stack('part', 1, '')
- minetest.swap_node(pos, {name = 'tasks:engine_1_on', param2 = node.param2})
- meta:set_string('formspec', formspec_good)
- tasks.only_add_xp(xp, name)
- timer:start(random_number)
- end,
- })
|