From ebf43165941047060536f26354109d154e5ed2fa Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Wed, 28 Aug 2019 18:54:24 +0100 Subject: [PATCH] Fix issues found by luacheck --- .luacheckrc | 4 ++-- mods/ctf/ctf/teams.lua | 11 ++++------- mods/ctf/ctf_chat/init.lua | 3 +-- mods/ctf/ctf_colors/hud.lua | 2 +- mods/ctf/ctf_flag/api.lua | 8 ++++---- mods/ctf/ctf_flag/flag_func.lua | 4 ++-- 6 files changed, 14 insertions(+), 18 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index 5212fec..e884902 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -14,7 +14,8 @@ ignore = {"631"} globals = { "crafting", "vector", "table", "minetest", "worldedit", "ctf", "ctf_flag", "ctf_colors", "hudkit", "default", "treasurer", "ChatCmdBuilder", "ctf_map", - "ctf_match", "ctf_stats", "ctf_treasure", "ctf_playertag", "chatplus" + "ctf_match", "ctf_stats", "ctf_treasure", "ctf_playertag", "chatplus", "irc", + "armor", } read_globals = { @@ -23,7 +24,6 @@ read_globals = { "dump", "DIR_DELIM", "sfinv", "creative", - "irc", "VoxelArea", "ItemStack", "Settings", "prometheus", "hb", diff --git a/mods/ctf/ctf/teams.lua b/mods/ctf/ctf/teams.lua index 89f3f0f..5d79ef7 100644 --- a/mods/ctf/ctf/teams.lua +++ b/mods/ctf/ctf/teams.lua @@ -63,11 +63,8 @@ function ctf.list_teams(name) minetest.chat_send_player(name, "Teams:") for tname, team in pairs(ctf.teams) do if team and team.players then - local details = "" - local numPlayers = ctf.count_players_in_team(tname) - details = numPlayers .. " members" - + local details = numPlayers .. " members" if team.flags then local numFlags = 0 for flagid, flag in pairs(team.flags) do @@ -233,7 +230,7 @@ function ctf.can_mod(player,team) if privs then if privs.ctf_admin == true then - return true + return true end end @@ -277,10 +274,10 @@ function ctf.autoalloc(name, alloc_mode) local max_players = ctf.setting("maximum_in_team") local mtot = false -- more than one team - for key, team in pairs(ctf.teams) do + if next(ctf.teams) then mtot = true - break end + if not mtot then ctf.error("autoalloc", "No teams to allocate " .. name .. " to!") return diff --git a/mods/ctf/ctf_chat/init.lua b/mods/ctf/ctf_chat/init.lua index 12c7c77..8c037c5 100644 --- a/mods/ctf/ctf_chat/init.lua +++ b/mods/ctf/ctf_chat/init.lua @@ -327,7 +327,7 @@ minetest.register_chatcommand("t", { chatplus.log("<" .. name .. "> ** ".. param .. " **") end - tcolor = ctf_colors.get_color(ctf.player(name)) + local tcolor = ctf_colors.get_color(ctf.player(name)) for username, to in pairs(team.players) do minetest.chat_send_player(username, minetest.colorize(tcolor.css, "<" .. name .. "> ** " .. param .. " **")) @@ -344,7 +344,6 @@ minetest.register_chatcommand("t", { if minetest.global_exists("irc") then function irc.playerMessage(name, message) - local tname = ctf.player(name).team local color = ctf_colors.get_irc_color(ctf.player(name)) local clear = "\x0F" if color then diff --git a/mods/ctf/ctf_colors/hud.lua b/mods/ctf/ctf_colors/hud.lua index 40d6f47..70948a2 100644 --- a/mods/ctf/ctf_colors/hud.lua +++ b/mods/ctf/ctf_colors/hud.lua @@ -38,7 +38,7 @@ end function ctf_colors.set_skin(player, color) if minetest.global_exists("armor") then -- TODO: how should support for skin mods be done? - armor.textures[name].skin = "ctf_colors_skin_" .. color .. ".png" + armor.textures[player:get_player_name()].skin = "ctf_colors_skin_" .. color .. ".png" armor:update_player_visuals(player) else player:set_properties({ diff --git a/mods/ctf/ctf_flag/api.lua b/mods/ctf/ctf_flag/api.lua index e6c42ec..1420ecb 100644 --- a/mods/ctf/ctf_flag/api.lua +++ b/mods/ctf/ctf_flag/api.lua @@ -81,8 +81,8 @@ function ctf_flag.player_drop_flag(name) ctf.action("flag", name .. " dropped " .. flag_name) minetest.chat_send_all(flag_name.." has returned.") - for i = 1, #ctf_flag.registered_on_drop do - ctf_flag.registered_on_drop[i](name, flag) + for j = 1, #ctf_flag.registered_on_drop do + ctf_flag.registered_on_drop[j](name, flag) end end end @@ -124,7 +124,7 @@ function ctf_flag.update(pos) minetest.set_node(top,{name="air"}) return end - local topmeta = minetest.get_meta(top) + local flag_name = flag_team_data.name if flag_name and flag_name ~= "" then flagmeta:set_string("infotext", flag_name.." - "..flag_team_data.team) @@ -142,7 +142,7 @@ function ctf_flag.update(pos) minetest.set_node(top,{name="ctf_flag:flag_top_"..ctf.team(flag_team_data.team).data.color}) end - topmeta = minetest.get_meta(top) + local topmeta = minetest.get_meta(top) if flag_name and flag_name ~= "" then topmeta:set_string("infotext", flag_name.." - "..flag_team_data.team) else diff --git a/mods/ctf/ctf_flag/flag_func.lua b/mods/ctf/ctf_flag/flag_func.lua index 6bf400f..e5853f9 100644 --- a/mods/ctf/ctf_flag/flag_func.lua +++ b/mods/ctf/ctf_flag/flag_func.lua @@ -71,8 +71,8 @@ local function do_capture(attname, flag, returned) ctf_flag.delete(team, vector.new(flag)) ctf_flag.add(attacker.team, vector.new(flag)) else - minetest.set_node(pos,{name="air"}) - ctf_flag.delete(team,pos) + minetest.set_node(flag,{name="air"}) + ctf_flag.delete(team,flag) end for i = 1, #ctf_flag.registered_on_capture do