70 lines
2.0 KiB
Lua
Raw Normal View History

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
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]
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
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
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
--[[ yaw + 180°
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())
--]]
-- 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