Skip to content

Commit

Permalink
Fix a load of issues, add luacheck and travis
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenwardy committed Apr 6, 2018
1 parent c21b192 commit 7bd82dc
Show file tree
Hide file tree
Showing 28 changed files with 144 additions and 107 deletions.
35 changes: 35 additions & 0 deletions .luacheckrc
@@ -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 changes: 12 additions & 0 deletions .travis.yml
@@ -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
2 changes: 1 addition & 1 deletion mods/afkkick/init.lua
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions mods/chatplus/api.lua
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions mods/chatplus/init.lua
Expand Up @@ -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
20 changes: 11 additions & 9 deletions mods/ctf_bounties/init.lua
Expand Up @@ -24,14 +24,24 @@ 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

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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion mods/ctf_disable_save/init.lua
@@ -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
4 changes: 2 additions & 2 deletions mods/ctf_events/init.lua
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
76 changes: 42 additions & 34 deletions mods/ctf_map/barrier.lua
Expand Up @@ -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()
Expand Down Expand Up @@ -118,59 +118,67 @@ 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

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

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

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
Expand Down
13 changes: 6 additions & 7 deletions mods/ctf_map/map_maker.lua
Expand Up @@ -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 {
Expand Down Expand Up @@ -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

Expand Down
7 changes: 0 additions & 7 deletions mods/ctf_map/schem_map.lua
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions mods/ctf_match/vote.lua
Expand Up @@ -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
})
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mods/ctf_metrics/init.lua
Expand Up @@ -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()
Expand Down
1 change: 0 additions & 1 deletion mods/ctf_stats/gui.lua
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mods/ctf_stats/init.lua
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions mods/ctf_team_base/api.lua
Expand Up @@ -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
Expand All @@ -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"))
Expand Down

1 comment on commit 7bd82dc

@ClobberXD
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow... just WOW! :O

Please sign in to comment.