Fix a load of issues, add luacheck and travis

This commit is contained in:
rubenwardy 2018-04-06 14:04:56 +01:00
parent c21b192f82
commit 7bd82dca86
28 changed files with 144 additions and 107 deletions

35
.luacheckrc Normal file
View file

@ -0,0 +1,35 @@
unused_args = false
allow_defined_top = true
exclude_files = {
"mods/default",
"mods/ctf_pvp_engine",
"mods/shooter",
"mods/wield3d",
"mods/treasurer",
}
globals = {
"crafting", "vector", "table", "minetest",
"worldedit", "ctf", "ctf_flag", "ctf_colors",
"hudkit", "default", "treasurer", "ChatCmdBuilder",
}
read_globals = {
string = {fields = {"split"}},
table = {fields = {"copy", "getn"}},
"dump", "DIR_DELIM",
"sfinv", "creative",
"irc",
"VoxelArea", "ItemStack",
"Settings",
"prometheus", "hb",
-- Testing
"describe",
"it",
"assert",
}

12
.travis.yml Normal file
View file

@ -0,0 +1,12 @@
language: generic
sudo: false
addons:
apt:
packages:
- luarocks
before_install:
- luarocks install --local luacheck
script:
- $HOME/.luarocks/bin/luacheck --no-color .
notifications:
email: false

View file

@ -51,7 +51,7 @@ minetest.register_globalstep(function(dtime)
--Warn player if he/she has less than WARN_TIME seconds to move or be kicked
if players[playerName]["lastAction"] + MAX_INACTIVE_TIME - WARN_TIME < currGameTime then
minetest.chat_send_player(playerName, minetest.colorize(#FF8C00,"Warning, you have " .. tostring(players[playerName]["lastAction"] + MAX_INACTIVE_TIME - currGameTime) .. " seconds to move or be kicked"))
minetest.chat_send_player(playerName, minetest.colorize("#FF8C00", "Warning, you have " .. tostring(players[playerName]["lastAction"] + MAX_INACTIVE_TIME - currGameTime) .. " seconds to move or be kicked"))
end
end

View file

@ -138,9 +138,9 @@ end
minetest.after(30*60, cp_tick)
function chatplus.poke(name,player)
local function check(name,value)
if not chatplus.players[name][value] then
chatplus.players[name][value] = {}
local function check(name2, value)
if not chatplus.players[name2][value] then
chatplus.players[name2][value] = {}
end
end
if not chatplus.players[name] then

View file

@ -93,13 +93,13 @@ minetest.registered_chatcommands["msg"].func = function(name, param)
if not sendto then
return false, "Invalid usage, see /help msg."
end
if not core.get_player_by_name(sendto) then
if not minetest.get_player_by_name(sendto) then
return false, "The player " .. sendto
.. " is not online."
end
core.log("action", "PM from " .. name .. " to " .. sendto
minetest.log("action", "PM from " .. name .. " to " .. sendto
.. ": " .. message)
core.chat_send_player(sendto, minetest.colorize("#00FF55",
minetest.chat_send_player(sendto, minetest.colorize("#00FF55",
"PM from " .. name .. ": " .. message))
return true, "Message sent."
end

View file

@ -24,6 +24,16 @@ local function bounty_player(target)
bountied_player = target
-- Score * K/D
-- bounty_score = -----------, or 500 (whichever is lesser)
-- 10000
local pstat, _ = ctf_stats.player(target)
bounty_score = (pstat.score * (pstat.kills / pstat.deaths)) / 10000
if bounty_score > 500 then
bounty_score = 500
end
minetest.after(0.1, announce_all)
end
@ -31,7 +41,7 @@ local function bounty_find_new_target()
local players = {}
for _, player in pairs(minetest.get_connected_players()) do
local name = player:get_player_name()
local pstat, mstat = ctf_stats.player(name)
local pstat, _ = ctf_stats.player(name)
pstat.name = name
pstat.color = nil
if pstat.score > 1000 and pstat.kills > pstat.deaths * 1.5 then
@ -41,14 +51,6 @@ local function bounty_find_new_target()
if #players > 0 then
bounty_player(players[math.random(1, #players)].name)
-- Score * K/D
-- bounty_score = -----------, or 500 (whichever is lesser)
-- 10000
bounty_score = (pstat.score * (pstat.kills / pstat.deaths)) / 10000
if bounty_score > 500 then
bounty_score = 500
end
end
minetest.after(math.random(500, 1000), bounty_find_new_target)

View file

@ -1,5 +1,5 @@
ctf.save = function()
for i = 1, #ctf.registered_on_save do
local res = ctf.registered_on_save[i]()
ctf.registered_on_save[i]()
end
end

View file

@ -38,7 +38,7 @@ function ctf_events.update_row(i, player, name, tplayer, evt)
-- One
if evt.one then
local tone_text, tone_hex = ctf_colors.get_color(evt.one, ctf.player(evt.one))
local _, tone_hex = ctf_colors.get_color(evt.one, ctf.player(evt.one))
if hud:exists(player, idx) then
hud:change(player, idx, "text", evt.one)
hud:change(player, idx, "number", tone_hex)
@ -60,7 +60,7 @@ function ctf_events.update_row(i, player, name, tplayer, evt)
-- Two
if evt.two then
local ttwo_text, ttwo_hex = ctf_colors.get_color(evt.two, ctf.player(evt.two))
local _, ttwo_hex = ctf_colors.get_color(evt.two, ctf.player(evt.two))
if hud:exists(player, idx2) then
hud:change(player, idx2, "text", evt.two)
hud:change(player, idx2, "number", ttwo_hex)

View file

@ -4,8 +4,8 @@ local c_glass = minetest.get_content_id("ctf_map:ind_glass")
local c_glass_red = minetest.get_content_id("ctf_map:ind_glass_red")
local c_map_ignore = minetest.get_content_id("ctf_map:ignore")
local c_actual_st = minetest.get_content_id("default:stone")
local c_water = minetest.get_content_id("default:water_source")
local c_water_f = minetest.get_content_id("default:water_flowing")
-- local c_water = minetest.get_content_id("default:water_source")
-- local c_water_f = minetest.get_content_id("default:water_flowing")
local c_air = minetest.get_content_id("air")
function ctf_map.remove_middle_barrier()
@ -118,14 +118,16 @@ function ctf_map.place_outer_barrier(center, r, h)
print("Placing left wall")
-- Left
local x = center.x - r
for z = minp.z, maxp.z do
for y = minp.y, maxp.y do
local vi = a:index(x, y, z)
if data[vi] == c_air or data[vi] == c_glass or data[vi] == c_map_ignore then
data[vi] = c_glass
else
data[vi] = c_stone
do
local x = center.x - r
for z = minp.z, maxp.z do
for y = minp.y, maxp.y do
local vi = a:index(x, y, z)
if data[vi] == c_air or data[vi] == c_glass or data[vi] == c_map_ignore then
data[vi] = c_glass
else
data[vi] = c_stone
end
end
end
end
@ -133,14 +135,16 @@ function ctf_map.place_outer_barrier(center, r, h)
print("Placing right wall")
-- Right
local x = center.x + r
for z = minp.z, maxp.z do
for y = minp.y, maxp.y do
local vi = a:index(x, y, z)
if data[vi] == c_air or data[vi] == c_glass or data[vi] == c_map_ignore then
data[vi] = c_glass
else
data[vi] = c_stone
do
local x = center.x + r
for z = minp.z, maxp.z do
for y = minp.y, maxp.y do
local vi = a:index(x, y, z)
if data[vi] == c_air or data[vi] == c_glass or data[vi] == c_map_ignore then
data[vi] = c_glass
else
data[vi] = c_stone
end
end
end
end
@ -148,14 +152,16 @@ function ctf_map.place_outer_barrier(center, r, h)
print("Placing front wall")
-- Front
local z = center.z - r
for x = minp.x, maxp.x do
for y = minp.y, maxp.y do
local vi = a:index(x, y, z)
if data[vi] == c_air or data[vi] == c_glass or data[vi] == c_map_ignore then
data[vi] = c_glass
else
data[vi] = c_stone
do
local z = center.z - r
for x = minp.x, maxp.x do
for y = minp.y, maxp.y do
local vi = a:index(x, y, z)
if data[vi] == c_air or data[vi] == c_glass or data[vi] == c_map_ignore then
data[vi] = c_glass
else
data[vi] = c_stone
end
end
end
end
@ -163,14 +169,16 @@ function ctf_map.place_outer_barrier(center, r, h)
print("Placing back wall")
-- Back
local z = center.z + r
for x = minp.x, maxp.x do
for y = minp.y, maxp.y do
local vi = a:index(x, y, z)
if data[vi] == c_air or data[vi] == c_glass or data[vi] == c_map_ignore then
data[vi] = c_glass
else
data[vi] = c_stone
do
local z = center.z + r
for x = minp.x, maxp.x do
for y = minp.y, maxp.y do
local vi = a:index(x, y, z)
if data[vi] == c_air or data[vi] == c_glass or data[vi] == c_map_ignore then
data[vi] = c_glass
else
data[vi] = c_stone
end
end
end
end

View file

@ -54,6 +54,12 @@ minetest.register_node("ctf_map:flag", {
end,
})
local randint = math.random(100)
local barrier_r = 110
local mapname = "ctf_" .. randint
local maptitle = "Untitled Map " .. randint
local mapauthor = nil
local center_barrier_rot = 0
local center = { x = 0, y = 0, z = 0, r = 115, h = 140 }
local function to_2pos()
return {
@ -130,13 +136,6 @@ local function get_flag_status()
end
end
local randint = math.random(100)
local barrier_r = 110
local mapname = "ctf_" .. randint
local maptitle = "Untitled Map " .. randint
local mapauthor = nil
local center_barrier_rot = 1
local function show_gui(name)
mapauthor = mapauthor or name

View file

@ -120,11 +120,6 @@ function ctf_match.load_map_meta(idx, name)
map.teams[tname] = {
color = tcolor,
pos = vector.add(offset, tpos),
chests = {
from = chests1,
to = chests2,
n = tonumber(meta:get("team." .. i .. ".num_chests") or "23"),
},
}
i = i + 1
@ -200,8 +195,6 @@ ctf_match.register_on_new_match(function()
end)
function ctf_match.create_teams()
local number = ctf.setting("match.teams")
for key, value in pairs(ctf_map.map.teams) do
local name = key
local color = value.color

View file

@ -33,8 +33,8 @@ function ctf_match.vote_next(name, params)
end
end,
on_vote = function(self, name, value)
minetest.chat_send_all(name .. " voted " .. value .. " to '" ..
on_vote = function(self, voter, value)
minetest.chat_send_all(voter .. " voted " .. value .. " to '" ..
self.description .. "'")
end
})
@ -51,9 +51,9 @@ minetest.register_chatcommand("vote", {
minetest.register_on_chat_message(function(name, msg)
if msg == "/vote_next" and minetest.check_player_privs(name,
{interact=true, vote_starter=true}) then
local suc, msg = ctf_match.vote_next(name)
if msg then
minetest.chat_send_player(name, msg)
local _, vmsg = ctf_match.vote_next(name)
if vmsg then
minetest.chat_send_player(name, vmsg)
end
return true
end

View file

@ -15,7 +15,7 @@ local function step()
local avg = 0
if #minetest.get_connected_players() > 0 then
for _, player in pairs(minetest.get_connected_players()) do
local total, match = ctf_stats.player(player:get_player_name())
local total, _ = ctf_stats.player(player:get_player_name())
sum = sum + total.score
end
avg = sum / #minetest.get_connected_players()

View file

@ -72,7 +72,6 @@ function ctf_stats.get_html(title, players)
for i = 1, #players do
local pstat = players[i]
local color = pstat.color or "#ffffff"
local kd = pstat.kills
if pstat.deaths > 0 then
kd = kd / pstat.deaths

View file

@ -181,7 +181,7 @@ end)
ctf_flag.register_on_precapture(function(name, flag)
local tplayer = ctf.player(name)
local main, match = ctf_stats.player(name)
local main, _ = ctf_stats.player(name)
if main then
main.wins[tplayer.team] = main.wins[tplayer.team] + 1
ctf.needs_save = true

View file

@ -13,9 +13,9 @@ function ctf_team_base.place(color, pos)
for y = pos.y, pos.y + 3 do
for x = pos.x - 3, pos.x + 3 do
for z = pos.z - 3, pos.z + 3 do
local pos = {x=x, y=y, z=z}
if minetest.get_node(pos).name == "default:tree" then
minetest.set_node(pos, {name="air"})
local pos2 = {x=x, y=y, z=z}
if minetest.get_node(pos2).name == "default:tree" then
minetest.set_node(pos2, {name="air"})
end
end
end
@ -28,13 +28,13 @@ function ctf_team_base.place(color, pos)
dz = -2
chest.param2 = minetest.dir_to_facedir({x=0,y=0,z=-1})
end
local pos = {
local pos3 = {
x = pos.x,
y = pos.y,
z = pos.z + dz
}
minetest.set_node(pos, chest)
local inv = minetest.get_meta(pos):get_inventory()
minetest.set_node(pos3, chest)
local inv = minetest.get_meta(pos3):get_inventory()
inv:add_item("main", ItemStack("default:cobble 99"))
inv:add_item("main", ItemStack("default:cobble 99"))
inv:add_item("main", ItemStack("default:cobble 99"))

View file

@ -90,7 +90,6 @@ for _, chest_color in pairs(colors) do
allow_metadata_inventory_move = function(pos, from_list, from_index,
to_list, to_index, count, player)
local meta = minetest.get_meta(pos)
if chest_color ~= ctf.player(player:get_player_name()).team then
minetest.chat_send_player(player:get_player_name(), "You're not on team " .. chest_color)
return 0
@ -125,7 +124,6 @@ for _, chest_color in pairs(colors) do
end
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
if chest_color ~= ctf.player(player:get_player_name()).team then
minetest.chat_send_player(player:get_player_name(), "You're not on team " .. chest_color)
return 0

View file

@ -1,6 +1,6 @@
if minetest.register_can_bypass_userlimit then
minetest.register_can_bypass_userlimit(function(name, ip)
local pstat, discard = ctf_stats.player_or_nil(name)
local pstat, _ = ctf_stats.player_or_nil(name)
local actual_max_users = tonumber(minetest.settings:get("max_users")) +
tonumber(minetest.settings:get("max_extra_users") or "10")
local req_score = tonumber(minetest.settings:get("userlimit_bypass_required_score") or "10000")

View file

@ -15,7 +15,7 @@ local function drop(pos, itemstack)
end
end
local obj = core.add_item(pos, it)
local obj = minetest.add_item(pos, it)
if obj then
obj:setvelocity({x=math.random(-1,1), y=5, z=math.random(-1,1)})

View file

@ -79,15 +79,14 @@ end)
function email.get_formspec(name)
local inbox = email.get_inbox(name)
local fs = "vertlabel[0,0;Your Inbox]"
function row(fs, c1, date, from, msg)
local function row(fs, c1, date, from, msg)
date = minetest.formspec_escape(date)
from = minetest.formspec_escape(from)
msg = minetest.formspec_escape(msg)
return fs .. ",#d0d0d0," .. table.concat({date, c1, from, msg}, ",")
end
local fs = "vertlabel[0,0;Your Inbox]"
fs = fs .. "tablecolumns[color;text;color;text;text]"
fs = fs .. "tableoptions[highlight=#ffffff33]"
fs = fs .. "table[0.5,0;11.25,7;inbox;"
@ -138,8 +137,6 @@ function email.show_inbox(name, text_mode)
return true, "Opened inbox!"
end
return true
end
if minetest.global_exists("sfinv") then

View file

@ -51,12 +51,6 @@ end
-- Node callback functions that are the same for active and inactive furnace
--
local function can_dig(pos, player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("fuel") and inv:is_empty("dst") and inv:is_empty("src")
end
local function allow_metadata_inventory_put(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0

View file

@ -7,7 +7,7 @@ minetest.register_chatcommand("killme", {
player:set_hp(0)
return true
else
for _, callback in pairs(core.registered_on_respawnplayers) do
for _, callback in pairs(minetest.registered_on_respawnplayers) do
if callback(player) then
return true
end

View file

@ -44,7 +44,7 @@ local function remove_entity_tag(player)
local tag = nametags[player:get_player_name()]
if tag then
tag:remove()
tag = nil
nametags[player:get_player_name()] = nil
end
end

View file

@ -64,7 +64,8 @@ minetest.register_chatcommand("report", {
local toname = player:get_player_name()
if minetest.check_player_privs(toname, {kick = true, ban = true}) then
table.insert(mods, toname)
minetest.chat_send_player(toname, minetest.colorize(#FFFF00,"-!- " .. name .. " reported: " .. param))
minetest.chat_send_player(toname, minetest.colorize("#FFFF00",
"-!- " .. name .. " reported: " .. param))
end
end

View file

@ -45,7 +45,8 @@ minetest.register_on_punchplayer(function(player, hitter,
if hitter and respawn_immunity.is_immune(hitter) then
minetest.chat_send_player(hitter:get_player_name(),
minetest.colorize(#FF8C00,"Your immunity has ended because you attacked a player"))
minetest.colorize("#FF8C00",
"Your immunity has ended because you attacked a player"))
immune_players[hitter:get_player_name()] = nil
respawn_immunity.update_effects(hitter)
end

View file

@ -24,7 +24,6 @@ else
end
local players = {}
local staminaHud = {}
local function setSprinting(player, info, sprinting)
if info.sprinting ~= sprinting then

View file

@ -85,7 +85,6 @@ local t_max = 7 -- maximum amount of treasures found in a chest
local water_level = tonumber(minetest.setting_get("water_level"))
local get_node = minetest.get_node
local env = minetest.env
local function findGroundLevel(pos, y_min, y_max)
local ground = nil
@ -153,9 +152,9 @@ local function placeChest(pos, chest_pos, ground, nn)
-- Get treasure
local treasure_amount = math.ceil(math.random(t_min, t_max))
local height = math.abs(h_min) - math.abs(h_max)
local y_norm = (ground+1) - h_min
local scale = 1 - (y_norm/height)
-- local height = math.abs(h_min) - math.abs(h_max)
-- local y_norm = (ground+1) - h_min
-- local scale = 1 - (y_norm/height)
local minp = 0 --scale*4 -- minimal preciousness: 0..4
local maxp = 10 --scale*4+2.1 -- maximum preciousness: 2.1..6.1
local treasures = treasurer.select_random_treasures(treasure_amount, minp, maxp)

View file

@ -341,8 +341,8 @@ if set == nil or minetest.is_yes(set) then
end
end,
on_vote = function(self, name, value)
minetest.chat_send_all(name .. " voted " .. value .. " to '" ..
on_vote = function(self, voter, value)
minetest.chat_send_all(voter .. " voted " .. value .. " to '" ..
self.description .. "'")
end
})