2018-04-25 18:51:52 -05:00
|
|
|
-- This mod is used to protect nodes in the capture the flag game
|
|
|
|
ctf.register_on_init(function()
|
|
|
|
ctf.log("chat", "Initialising...")
|
|
|
|
|
|
|
|
-- Settings: Chat
|
|
|
|
ctf._set("node_ownership", true)
|
|
|
|
end)
|
|
|
|
|
|
|
|
local old_is_protected = minetest.is_protected
|
|
|
|
|
|
|
|
function minetest.is_protected(pos, name)
|
|
|
|
if not ctf.setting("node_ownership") then
|
|
|
|
return old_is_protected(pos, name)
|
|
|
|
end
|
|
|
|
|
2018-12-15 13:06:04 -06:00
|
|
|
local team, index = ctf.get_territory_owner(pos)
|
2018-04-25 18:51:52 -05:00
|
|
|
|
|
|
|
if not team or not ctf.team(team) then
|
|
|
|
return old_is_protected(pos, name)
|
|
|
|
end
|
2018-12-15 13:06:04 -06:00
|
|
|
|
2018-12-07 01:53:10 -06:00
|
|
|
local player_team = ctf.player(name).team
|
2018-12-15 13:06:04 -06:00
|
|
|
if player_team == team then
|
|
|
|
local t = ctf.team(team)
|
|
|
|
local f = t.flags[index]
|
2018-12-16 01:14:57 +00:00
|
|
|
if true or not f.access or f.access.teams[player_team] or f.access.players[name] or f.access.open == true or not t.access or t.access.teams[player_team] or t.access.players[name] then
|
2018-12-15 13:06:04 -06:00
|
|
|
return old_is_protected(pos, name)
|
|
|
|
end
|
2018-12-16 01:14:57 +00:00
|
|
|
if f.name then
|
|
|
|
minetest.chat_send_player(name, "You need to be white listed in-order to build on flag " .. f.name .. "'s land")
|
|
|
|
else
|
|
|
|
minetest.chat_send_player(name, "You need to be white listed in-order to build on this flag's land")
|
|
|
|
end
|
2018-12-15 13:06:04 -06:00
|
|
|
return true
|
2018-04-25 18:51:52 -05:00
|
|
|
else
|
2018-06-20 09:30:53 -04:00
|
|
|
local player = minetest.get_player_by_name(name)
|
|
|
|
if player then
|
2018-12-15 13:06:04 -06:00
|
|
|
local t = ctf.team(team)
|
|
|
|
local f = t.flags[index]
|
|
|
|
if (t.access and (t.access.teams[player_team] or t.access.players[name])) or (f.access and (f.access.teams[player_team] or f.access.players[name])) then
|
|
|
|
return old_is_protected(pos, name)
|
|
|
|
end
|
2018-06-20 09:24:52 -05:00
|
|
|
--[[ yaw + 180°
|
2018-06-20 09:30:53 -04:00
|
|
|
local yaw = player:get_look_horizontal() + math.pi
|
|
|
|
if yaw > 2 * math.pi then
|
|
|
|
yaw = yaw - 2 * math.pi
|
|
|
|
end
|
|
|
|
player:set_look_yaw(yaw)
|
|
|
|
|
|
|
|
-- invert pitch
|
|
|
|
player:set_look_vertical(-player:get_look_vertical())
|
2018-06-20 09:24:52 -05:00
|
|
|
--]]
|
2018-06-20 09:30:53 -04:00
|
|
|
-- if digging below player, move up to avoid falling through hole
|
|
|
|
local pla_pos = player:get_pos()
|
|
|
|
|
|
|
|
if pos.y < pla_pos.y then
|
|
|
|
player:setpos({
|
|
|
|
x = pla_pos.x,
|
|
|
|
y = pla_pos.y + 0.8,
|
|
|
|
z = pla_pos.z
|
|
|
|
})
|
|
|
|
else
|
|
|
|
player:setpos(pla_pos)
|
|
|
|
end
|
|
|
|
end
|
2018-04-25 18:51:52 -05:00
|
|
|
minetest.chat_send_player(name, "You cannot dig on team "..team.."'s land")
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|