luacheck
This commit is contained in:
parent
9a67d3c372
commit
02cfd18b4d
21
.luacheckrc
Normal file
21
.luacheckrc
Normal file
@ -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"
|
||||
}
|
@ -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]
|
||||
|
@ -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]
|
||||
|
@ -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)
|
||||
end)
|
||||
|
@ -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")
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
end)
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
39
hud.lua
39
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
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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]"
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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]"
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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]"
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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 = {}
|
||||
|
||||
|
@ -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]"
|
||||
|
||||
|
@ -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
|
||||
|
@ -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]"
|
||||
|
@ -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 .. ","
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
4
ui.lua
4
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)
|
||||
end)
|
||||
|
Loading…
x
Reference in New Issue
Block a user