diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..995f9ab --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,21 @@ +unused_args = false +allow_defined_top = true + +globals = { + "missions", + "minetest" +} + +read_globals = { + -- Stdlib + string = {fields = {"split"}}, + table = {fields = {"copy", "getn"}}, + "call", + + -- Minetest + "vector", "ItemStack", + "dump", "VoxelArea", + + -- Deps + "unified_inventory", "default", "xp_redo" +} diff --git a/block.lua b/block.lua index f2fb12d..85a18e1 100644 --- a/block.lua +++ b/block.lua @@ -34,8 +34,6 @@ minetest.register_node("missions:mission", { -- target inv empty local steps = missions.get_steps(pos) - local meta = minetest.get_meta(pos) - local selected_step = missions.get_selected_list_item(player) local step = steps[selected_step] diff --git a/executor.hud.lua b/executor.hud.lua index 75ec22e..5d71671 100644 --- a/executor.hud.lua +++ b/executor.hud.lua @@ -64,7 +64,7 @@ missions.hud_update_status = function(player, status) player:hud_change(data.status, "text", status) end -missions.hud_update = function(player, mission, remainingTime) +missions.hud_update = function(player, mission) local playername = player:get_player_name() local data = hud[playername] diff --git a/executor.lua b/executor.lua index c0de7f9..3673b7d 100644 --- a/executor.lua +++ b/executor.lua @@ -62,7 +62,7 @@ local update_mission = function(mission, player) local success = false local failed = false - + local on_success = function() success = true end @@ -173,7 +173,6 @@ minetest.register_globalstep(function(dtime) if timer >= 0.5 then local players = minetest.get_connected_players() for i,player in ipairs(players) do - local playername = player:get_player_name() local mission = missions.get_current_mission(player) if mission then @@ -185,4 +184,4 @@ minetest.register_globalstep(function(dtime) timer = 0 end -end) \ No newline at end of file +end) diff --git a/form.missionblock_config.lua b/form.missionblock_config.lua index 2987e3c..afeefd7 100644 --- a/form.missionblock_config.lua +++ b/form.missionblock_config.lua @@ -7,7 +7,6 @@ missions.form.missionblock_config = function(pos, node, player) local name = meta:get_string("name") local time = meta:get_string("time") - local owner = meta:get_string("owner") local description = meta:get_string("description") local hidden = meta:get_int("hidden") diff --git a/form.missionblock_main.lua b/form.missionblock_main.lua index fc25946..b9b4940 100644 --- a/form.missionblock_main.lua +++ b/form.missionblock_main.lua @@ -47,7 +47,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end local pos = minetest.string_to_pos(parts[2]) - local meta = minetest.get_meta(pos) local node = minetest.get_node(pos) if not missions.check_owner(pos, player) then diff --git a/form.missionblock_stepeditor.lua b/form.missionblock_stepeditor.lua index 32712b2..cc69ad4 100644 --- a/form.missionblock_stepeditor.lua +++ b/form.missionblock_stepeditor.lua @@ -3,8 +3,6 @@ local FORMNAME = "mission_block_stepeditor" missions.form.missionblock_stepeditor = function(pos, node, player) - local meta = minetest.get_meta(pos) - local selected_step = missions.get_selected_list_item(player) local steps = missions.get_steps(pos) @@ -27,7 +25,7 @@ missions.form.missionblock_stepeditor = function(pos, node, player) "button[5.5,3;2,1;up;Up]" .. "button[5.5,4;2,1;down;Down]" .. "button[5.5,5;2,1;remove;Remove]" .. - steps_list .. + steps_list .. "button_exit[0,7;8,1;save;Save and validate]" .. missions.FORMBG diff --git a/form.missionblock_user.lua b/form.missionblock_user.lua index 2a01e75..624028d 100644 --- a/form.missionblock_user.lua +++ b/form.missionblock_user.lua @@ -32,8 +32,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end local pos = minetest.string_to_pos(parts[2]) - local meta = minetest.get_meta(pos) - local node = minetest.get_node(pos) if fields.start then local result = missions.validate_mission(pos, player) @@ -46,4 +44,4 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end -end) \ No newline at end of file +end) diff --git a/form.newstep.lua b/form.newstep.lua index 01e8d77..7f1be7d 100644 --- a/form.newstep.lua +++ b/form.newstep.lua @@ -22,9 +22,6 @@ end missions.form.newstep = function(pos, node, player) - local step_buttons = "" - local offset = 1 - local steps = get_mission_steps_for_player(player) local list = "" for i,spec in ipairs(steps) do @@ -96,7 +93,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) data = stepdata } - local steps = missions.get_steps(pos) + steps = missions.get_steps(pos) table.insert(steps, step) missions.set_steps(pos, steps) diff --git a/form.wand.lua b/form.wand.lua index b9b1a03..d95b192 100644 --- a/form.wand.lua +++ b/form.wand.lua @@ -41,8 +41,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) local meta = stack:get_meta() meta:set_string("pos", posStr) meta:set_string("name", fields.name) - meta:set_string("description", "Mission wand (" .. type .. "): " .. posStr .. - " with name: '" .. fields.name .. + meta:set_string("description", "Mission wand (" .. type .. "): " .. posStr .. + " with name: '" .. fields.name .. "' and node '" .. node.name .. "'") if inv:contains_item("main", "missions:wand") and inv:room_for_item("main", stack) then diff --git a/functions.lua b/functions.lua index fd179b4..4b9b643 100644 --- a/functions.lua +++ b/functions.lua @@ -1,4 +1,3 @@ -local has_xp_redo_mod = minetest.get_modpath("xp_redo") missions.check_owner = function(pos, player) -- check override priv @@ -40,7 +39,6 @@ minetest.register_on_joinplayer(function(player) if mission and mission.version == missions.CURRENT_MISSION_SPEC_VERSION then -- only load if compatible with current spec local step = mission.steps[mission.currentstep] - if step == nil then return end @@ -158,7 +156,7 @@ end missions.get_image = function(name) -- stolen from drawers code local texture = "blank.png" - local def = core.registered_items[name] + local def = minetest.registered_items[name] if not def then return texture end @@ -178,11 +176,11 @@ missions.get_image = function(name) -- tiles: up, down, right, left, back, front -- inventorycube: up, front, right if #tiles <= 2 then - texture = core.inventorycube(tiles[1], tiles[1], tiles[1]) + texture = minetest.inventorycube(tiles[1], tiles[1], tiles[1]) elseif #tiles <= 5 then - texture = core.inventorycube(tiles[1], tiles[3], tiles[3]) + texture = minetest.inventorycube(tiles[1], tiles[3], tiles[3]) else -- full tileset - texture = core.inventorycube(tiles[1], tiles[6], tiles[3]) + texture = minetest.inventorycube(tiles[1], tiles[6], tiles[3]) end end diff --git a/hud.lua b/hud.lua index 4458799..86932d8 100644 --- a/hud.lua +++ b/hud.lua @@ -5,36 +5,6 @@ local HUD_ALIGNMENT = {x = 1, y = 0} local hud = {} -- playerName -> {} --- returns the image (item, node, tool) or "" -local get_image = function(name) - -- minetest.registered_items[name].inventory_image - -- minetest.registered_tools[name].inventory_image - -- minetest.registered_nodes["default:stone"].tiles[1] - -- TODO: look at drawer code - - if name == nil then - return "" - end - - local node = minetest.registered_nodes[name] - if node ~= nil and node.tiles ~= nil and table.getn(node.tiles) == 1 then - return minetest.inventorycube(node.tiles[1],node.tiles[1],node.tiles[1]) - end - - local item = minetest.registered_items[name] - if item ~= nil and item.inventory_image ~= nil then - return item.inventory_image - end - - local tool = minetest.registered_tools[name] - if tool ~= nil and tool.inventory_image ~= nil then - return tool.inventory_image - end - - -- none found - return "" -end - minetest.register_on_joinplayer(function(player) local playername = player:get_player_name() @@ -161,16 +131,7 @@ missions.hud_update = function(player, playermissions) player:hud_change(data.title, "text", "") player:hud_change(data.mission, "text", "") player:hud_change(data.time, "text", "") - - local i = 1 - while i <= hud_context_count do -- 1..n - player:hud_change(data.context[i], "text", "") - player:hud_change(data.contextcount[i], "text", "") - - i = i + 1 - end end - end diff --git a/register_step.lua b/register_step.lua index 19e7a7c..d179b4f 100644 --- a/register_step.lua +++ b/register_step.lua @@ -9,7 +9,7 @@ missions.get_step_spec_by_type = function(type) for i,spec in ipairs(missions.steps) do if type == spec.type then -- step spec found - return spec + return spec end end end @@ -91,7 +91,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) missions.set_steps(pos, steps) end end - end) diff --git a/steps/build.lua b/steps/build.lua index 2e2c9e6..7731bda 100644 --- a/steps/build.lua +++ b/steps/build.lua @@ -26,7 +26,6 @@ missions.register_step({ local formspec = "size[8,8;]" .. "label[0,0;Place any nodes]" .. - "field[0,2;8,1;count;Count;" .. stepdata.count .. "]" .. "button[0,7;8,1;save;Save]" diff --git a/steps/buildspecific.lua b/steps/buildspecific.lua index ef1a108..e74f58f 100644 --- a/steps/buildspecific.lua +++ b/steps/buildspecific.lua @@ -26,7 +26,6 @@ missions.register_step({ get_status = function(ctx) local player = ctx.player - local stepdata = ctx.step.data local name = player:get_player_name() local stack = ItemStack(stacks[name] or "") @@ -116,9 +115,9 @@ missions.register_step({ end, on_step_exit = function(ctx) - local player = ctx.player; + local player = ctx.player local name = player:get_player_name() - local hud_data = hud[name]; + local hud_data = hud[name] if hud_data and hud_data.image then player:hud_remove(hud_data.image) diff --git a/steps/checkxp.lua b/steps/checkxp.lua index d0c6f80..011d860 100644 --- a/steps/checkxp.lua +++ b/steps/checkxp.lua @@ -14,7 +14,6 @@ missions.register_step({ local formspec = "size[8,8;]" .. "label[0,0;XP Check (Step #" .. stepnumber .. ")]" .. - "field[0,2;8,1;xp;XP Threshold;" .. stepdata.xp .. "]" .. "button[0,7;8,1;save;Save]" diff --git a/steps/chestput.lua b/steps/chestput.lua index ab4c10b..e9aa913 100644 --- a/steps/chestput.lua +++ b/steps/chestput.lua @@ -82,7 +82,7 @@ missions.register_step({ if stepdata.pos then local distance = vector.distance(ctx.pos, stepdata.pos) - name = name .. "Position(" .. stepdata.pos.x .. "/" .. + name = name .. "Position(" .. stepdata.pos.x .. "/" .. stepdata.pos.y .. "/" .. stepdata.pos.z ..") " .. "Distance: " .. math.floor(distance) .. " m" end @@ -204,13 +204,13 @@ missions.register_step({ local str = remainingItems[player:get_player_name()] if str then - local stack = ItemStack(str); + local stack = ItemStack(str) if stack:get_count() == 0 then ctx.on_success() end - local hud_data = hud[player:get_player_name()]; + local hud_data = hud[player:get_player_name()] player:hud_change(hud_data.counter, "text", stack:get_count() .. "x") else ctx.on_success() @@ -218,10 +218,10 @@ missions.register_step({ end, on_step_exit = function(ctx) - local player = ctx.player; + local player = ctx.player remainingItems[player:get_player_name()] = "" - local hud_data = hud[player:get_player_name()]; + local hud_data = hud[player:get_player_name()] if hud_data and hud_data.image then player:hud_remove(hud_data.image) @@ -251,7 +251,7 @@ local intercept_chest = function(name) def.on_metadata_inventory_put = function(pos, listname, index, stack, player) if player and player:is_player() then local remStack = ItemStack(remainingItems[player:get_player_name()]) - + if remStack:get_name() == stack:get_name() then local count = remStack:get_count() - stack:get_count() if count < 0 then count = 0 end diff --git a/steps/chestreward.lua b/steps/chestreward.lua index b900833..a792492 100644 --- a/steps/chestreward.lua +++ b/steps/chestreward.lua @@ -1,7 +1,5 @@ -local hud = {} -- playerName -> {} - missions.register_step({ type = "chestreward", @@ -83,7 +81,7 @@ missions.register_step({ if stepdata.pos then local distance = vector.distance(pos, stepdata.pos) - name = name .. "Position(" .. stepdata.pos.x .. "/" .. + name = name .. "Position(" .. stepdata.pos.x .. "/" .. stepdata.pos.y .. "/" .. stepdata.pos.z ..") " .. "Distance: " .. math.floor(distance) .. " m" end diff --git a/steps/dig.lua b/steps/dig.lua index 87b9ad8..ea7ef74 100644 --- a/steps/dig.lua +++ b/steps/dig.lua @@ -25,7 +25,6 @@ missions.register_step({ local formspec = "size[8,8;]" .. "label[0,0;Dig any nodes]" .. - "field[0,2;8,1;count;Count;" .. stepdata.count .. "]" .. "button[0,7;8,1;save;Save]" diff --git a/steps/digspecific.lua b/steps/digspecific.lua index 1f04fa0..a56a9c2 100644 --- a/steps/digspecific.lua +++ b/steps/digspecific.lua @@ -27,7 +27,6 @@ missions.register_step({ get_status = function(ctx) local player = ctx.player - local stepdata = ctx.step.data local name = player:get_player_name() local stack = ItemStack(stacks[name] or "") @@ -117,9 +116,9 @@ missions.register_step({ end, on_step_exit = function(ctx) - local player = ctx.player; + local player = ctx.player local name = player:get_player_name() - local hud_data = hud[name]; + local hud_data = hud[name] if hud_data and hud_data.image then player:hud_remove(hud_data.image) diff --git a/steps/followup.lua b/steps/followup.lua index 032ced6..a8eecfd 100644 --- a/steps/followup.lua +++ b/steps/followup.lua @@ -48,26 +48,22 @@ missions.register_step({ edit_formspec = function(ctx) local pos = ctx.pos - local inv = ctx.inv local stepdata = ctx.step.data local name = "" if stepdata.pos then local distance = vector.distance(pos, stepdata.pos) - name = name .. "Position(" .. stepdata.pos.x .. "/" .. + name = name .. "Position(" .. stepdata.pos.x .. "/" .. stepdata.pos.y .. "/" .. stepdata.pos.z ..") " .. "Distance: " .. math.floor(distance) .. " m" end local formspec = "size[8,8;]" .. "label[0,0;Follow-up mission]" .. - "label[3,1;Target]" .. "list[nodemeta:" .. pos.x .. "," .. pos.y .. "," .. pos.z .. ";main;4,1;1,1;0]" .. - "label[0,2;" .. name .. "]" .. - "list[current_player;main;0,6;8,1;]" .. "button[0,7;8,1;save;Save]" @@ -94,8 +90,8 @@ missions.register_step({ end, on_step_enter = function(ctx) - local stepdata = ctx.step.data - local player = ctx.player + --local stepdata = ctx.step.data + --local player = ctx.player --TODO ctx.on_success() diff --git a/steps/givebook.lua b/steps/givebook.lua index eeef8a5..befebec 100644 --- a/steps/givebook.lua +++ b/steps/givebook.lua @@ -1,6 +1,5 @@ -local FORMNAME = "mission_block_step_message" missions.register_step({ @@ -18,7 +17,6 @@ missions.register_step({ local formspec = "size[8,8;]" .. "label[0,0;Give a book]" .. - "field[0,1;8,1;title;Title;" .. stepdata.title .. "]" .. "textarea[0,2;8,4;message;Message;" .. stepdata.message .. "]" .. "button[0,7;8,1;save;Save]" @@ -46,7 +44,6 @@ missions.register_step({ local stepdata = ctx.step.data local new_stack = ItemStack("default:book_written") - local stackMeta = new_stack:get_meta() local data = {} diff --git a/steps/givexp.lua b/steps/givexp.lua index 08a821c..de66bdf 100644 --- a/steps/givexp.lua +++ b/steps/givexp.lua @@ -16,7 +16,6 @@ missions.register_step({ local formspec = "size[8,8;]" .. "label[0,0;Give XP (Step #" .. stepnumber .. ")]" .. - "field[0,2;8,1;xp;XP;" .. stepdata.xp .. "]" .. "button[0,7;8,1;save;Save]" diff --git a/steps/grant.lua b/steps/grant.lua index 73c0a88..79450c4 100644 --- a/steps/grant.lua +++ b/steps/grant.lua @@ -15,7 +15,6 @@ missions.register_step({ local formspec = "size[8,8;]" .. "label[0,0;Grant privilege]" .. - "field[0,2;8,1;priv;Privilege;" .. stepdata.priv .. "]" .. "button[0,7;8,1;save;Save]" @@ -40,7 +39,7 @@ missions.register_step({ local name = player:get_player_name() local stepdata = ctx.step.data local priv = stepdata.priv - + if priv then local privs = minetest.get_player_privs(name) privs[priv] = true diff --git a/steps/message.lua b/steps/message.lua index 0428ed1..03ab9ea 100644 --- a/steps/message.lua +++ b/steps/message.lua @@ -17,7 +17,6 @@ missions.register_step({ local formspec = "size[8,8;]" .. "label[0,0;Show a message]" .. - "field[0,1;8,1;title;Title;" .. stepdata.title .. "]" .. "textarea[0,2;8,4;message;Message;" .. stepdata.message .. "]" .. "button[0,7;8,1;save;Save]" diff --git a/steps/spawnmob.lua b/steps/spawnmob.lua index af11efb..1d72fa0 100644 --- a/steps/spawnmob.lua +++ b/steps/spawnmob.lua @@ -62,7 +62,7 @@ missions.register_step({ if stepdata.pos then local distance = vector.distance(pos, stepdata.pos) - name = name .. "Position(" .. stepdata.pos.x .. "/" .. + name = name .. "Position(" .. stepdata.pos.x .. "/" .. stepdata.pos.y .. "/" .. stepdata.pos.z ..") " .. "Distance: " .. math.floor(distance) .. " m" end @@ -70,12 +70,12 @@ missions.register_step({ local selected = 1 local list = "" - for i,name in ipairs(mob_names) do - if name == stepdata.mobname then + for i,mname in ipairs(mob_names) do + if mname == stepdata.mobname then selected = i end - list = list .. minetest.formspec_escape(name) + list = list .. minetest.formspec_escape(mname) if i < #mob_names then -- not end of list list = list .. "," diff --git a/steps/teleport.lua b/steps/teleport.lua index a85166c..cd66b73 100644 --- a/steps/teleport.lua +++ b/steps/teleport.lua @@ -41,7 +41,7 @@ missions.register_step({ if stepdata.pos then local distance = vector.distance(pos, stepdata.pos) - name = name .. "Position(" .. stepdata.pos.x .. "/" .. + name = name .. "Position(" .. stepdata.pos.x .. "/" .. stepdata.pos.y .. "/" .. stepdata.pos.z ..") " .. "Distance: " .. math.floor(distance) .. " m" end diff --git a/steps/waypoint.lua b/steps/waypoint.lua index 60b6235..7c3566d 100644 --- a/steps/waypoint.lua +++ b/steps/waypoint.lua @@ -45,7 +45,7 @@ missions.register_step({ if stepdata.pos then local distance = vector.distance(pos, stepdata.pos) - name = name .. "Position(" .. stepdata.pos.x .. "/" .. + name = name .. "Position(" .. stepdata.pos.x .. "/" .. stepdata.pos.y .. "/" .. stepdata.pos.z ..") " .. "Distance: " .. math.floor(distance) .. " m" end @@ -141,10 +141,9 @@ missions.register_step({ on_step_interval = function(ctx) local player = ctx.player local stepdata = ctx.step.data - local pos = player:get_pos() - local distance = vector.distance(player:get_pos(), stepdata.pos) + local distance = vector.distance(pos, stepdata.pos) if distance < stepdata.radius then ctx.on_success() end diff --git a/ui.lua b/ui.lua index 8c75347..084ed08 100644 --- a/ui.lua +++ b/ui.lua @@ -9,7 +9,7 @@ unified_inventory.register_page("missions", { "label[1,0;Missions]"; if mission then - formspec = formspec .. + formspec = formspec .. "label[1,1;" .. mission.name .. "]" .. "button[1,2;4,1;abort_mission;Abort mission]"; else @@ -36,4 +36,4 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) local player_name = player:get_player_name() missions.abort(player_name) end -end) \ No newline at end of file +end)