Compare commits
5 Commits
a633c77da1
...
cf71c5d87d
Author | SHA1 | Date |
---|---|---|
Maksym H | cf71c5d87d | |
Maksym H | 5d6efc741a | |
Maksim | f809000bde | |
luk3yx | e8ee792fc6 | |
Maksim | ef9d5f454d |
|
@ -276,6 +276,7 @@ minetest.register_chatcommand("change_owner", {
|
|||
.." or is not owned by you.", id)
|
||||
end
|
||||
areas.areas[id].owner = newOwner
|
||||
areas.areas[id].name = areas.areas[id].name .. " " .. S("(by @1)", name)
|
||||
areas:save()
|
||||
minetest.chat_send_player(newOwner,
|
||||
S("@1 has given you control over the area \"@2\" (ID @3).",
|
||||
|
|
51
hud.lua
51
hud.lua
|
@ -5,24 +5,13 @@ local S = areas.S
|
|||
areas.hud = {}
|
||||
|
||||
local vround = vector.round
|
||||
local tconcat = table.concat
|
||||
|
||||
hud.register("areas", {
|
||||
hud_elem_type = "text",
|
||||
position = {x = 0, y = 1},
|
||||
alignment = {x = 1, y = -1},
|
||||
offset = {x = 8, y = -8},
|
||||
scale = {x = 200, y = 60},
|
||||
text = "",
|
||||
number = 0xFFFFFF
|
||||
})
|
||||
local tconcat, tinsert = table.concat, table.insert
|
||||
|
||||
local function update_hud(player, name, pos)
|
||||
local areaStrings = {
|
||||
S("Areas:")
|
||||
}
|
||||
local areaStrings = {}
|
||||
local getAreasAtPos = areas:getAreasAtPos(pos)
|
||||
|
||||
for id, area in pairs(areas:getAreasAtPos(pos)) do
|
||||
for id, area in pairs(getAreasAtPos) do
|
||||
areaStrings[#areaStrings + 1] = ("%s [%u] (%s)%s%s")
|
||||
:format(area.name, id, area.owner,
|
||||
area.open and (" [" .. S("Open") .. "]") or "",
|
||||
|
@ -37,13 +26,33 @@ local function update_hud(player, name, pos)
|
|||
areaStrings[#areaStrings + 1] = str
|
||||
end
|
||||
|
||||
-- "Areas:" text has index 1
|
||||
local areaString = #areaStrings > 1 and tconcat(areaStrings, "\n") or ""
|
||||
if areas.invite_code then
|
||||
areaStrings[#areaStrings + 1] = areas.invite_code
|
||||
end
|
||||
|
||||
local phud = areas.hud[name] or {}
|
||||
if not phud.oldAreas or phud.oldAreas ~= areaString then
|
||||
hud.change_item(player, "areas", {text = areaString})
|
||||
phud.oldAreas = areaString
|
||||
if next(getAreasAtPos) then
|
||||
tinsert(areaStrings, 1, S("Areas:"))
|
||||
end
|
||||
|
||||
local areaString = tconcat(areaStrings, "\n")
|
||||
local hud = areas.hud[name]
|
||||
if not hud then
|
||||
hud = {}
|
||||
areas.hud[name] = hud
|
||||
hud.areasId = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
name = "Areas",
|
||||
number = 0xFFFFFF,
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = 8, y = -8},
|
||||
scale = {x = 200, y = 60},
|
||||
alignment = {x = 1, y = -1},
|
||||
text = areaString
|
||||
})
|
||||
hud.oldAreas = areaString
|
||||
elseif hud.oldAreas ~= areaString then
|
||||
player:hud_change(hud.areasId, "text", areaString)
|
||||
hud.oldAreas = areaString
|
||||
end
|
||||
end
|
||||
|
||||
|
|
59
interact.lua
59
interact.lua
|
@ -29,16 +29,24 @@ minetest.register_on_protection_violation(function(pos, name)
|
|||
end
|
||||
local player_pos = player:get_pos()
|
||||
if pos.y < player_pos.y then
|
||||
player:set_pos({
|
||||
x = player_pos.x,
|
||||
y = player_pos.y + 1,
|
||||
z = player_pos.z
|
||||
})
|
||||
player_pos.y = player_pos.y + 1
|
||||
player:set_pos(player_pos)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
local function can_pvp_at(pos)
|
||||
for id in pairs(areas:getAreasAtPos(pos)) do
|
||||
-- This uses areas:canPvP instead of area.canPvP in case areas:canPvP
|
||||
-- is overridden
|
||||
if areas:canPvP(id) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch)
|
||||
if not enable_damage then
|
||||
return true
|
||||
|
@ -57,37 +65,22 @@ minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch)
|
|||
return true
|
||||
end
|
||||
|
||||
local hitterInPvP
|
||||
-- Check if the hitter is in an area with allowed PvP
|
||||
local hitterAreas = areas:getAreasAtPos(hitter:get_pos())
|
||||
-- If the table is empty, PvP is not allowed
|
||||
if not next(hitterAreas) then
|
||||
return true
|
||||
end
|
||||
-- Do any of the areas have allowed PvP?
|
||||
for _, area in pairs(hitterAreas) do
|
||||
if area.canPvP then
|
||||
hitterInPvP = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if hitterInPvP then
|
||||
-- Check if the victim is in an area with allowed PvP
|
||||
local victimAreas = areas:getAreasAtPos(player:get_pos())
|
||||
-- If the table is empty, PvP is not allowed
|
||||
if not next(victimAreas) then
|
||||
return true
|
||||
end
|
||||
-- Do any of the areas have allowed PvP?
|
||||
for _, area in pairs(victimAreas) do
|
||||
if area.canPvP then
|
||||
return false
|
||||
end
|
||||
end
|
||||
-- Allow PvP if both players are in a PvP area
|
||||
if can_pvp_at(hitter:get_pos()) and can_pvp_at(player:get_pos()) then
|
||||
return false
|
||||
end
|
||||
|
||||
-- Otherwise, it doesn't do damage
|
||||
minetest.chat_send_player(player_name, S("PvP is not allowed in this area!"))
|
||||
return true
|
||||
end)
|
||||
|
||||
local old_calculate_knockback = minetest.calculate_knockback
|
||||
function minetest.calculate_knockback(player, hitter, time_from_last_punch, ...)
|
||||
if player:is_player() and hitter and hitter:is_player() and
|
||||
(time_from_last_punch < 0.25 or not can_pvp_at(player:get_pos()) or
|
||||
not can_pvp_at(hitter:get_pos())) then
|
||||
return 0
|
||||
end
|
||||
return old_calculate_knockback(player, hitter, time_from_last_punch, ...)
|
||||
end
|
||||
|
|
164
protector.lua
164
protector.lua
|
@ -1,160 +1,6 @@
|
|||
local S = areas.S
|
||||
|
||||
local radius = minetest.settings:get("areasprotector_radius") or 8
|
||||
|
||||
local function cyan(str)
|
||||
return minetest.colorize("#7CFC00", str)
|
||||
end
|
||||
|
||||
local function red(str)
|
||||
return minetest.colorize("#FF0000", str)
|
||||
end
|
||||
|
||||
local vadd, vnew = vector.add, vector.new
|
||||
|
||||
minetest.register_node("areas:protector", {
|
||||
description = S("Protector Block"),
|
||||
tiles = {
|
||||
"default_stonebrick_carved.png",
|
||||
"default_stonebrick_carved.png",
|
||||
"default_stonebrick_carved.png^areas_protector_stone.png"
|
||||
},
|
||||
paramtype = "light",
|
||||
groups = {cracky = 1, not_cuttable = 1},
|
||||
node_placement_prediction = "",
|
||||
|
||||
on_place = function(itemstack, player, pointed_thing)
|
||||
local pos = pointed_thing.above
|
||||
local name = player and player:get_player_name()
|
||||
|
||||
if not name or not minetest.is_protected(pos, name) then
|
||||
-- Don't replace nodes that aren't buildable to
|
||||
local old_node = minetest.get_node(pos)
|
||||
local def = minetest.registered_nodes[old_node.name]
|
||||
if not def or not def.buildable_to then
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local pos1 = vadd(pos, vnew(radius, radius, radius))
|
||||
local pos2 = vadd(pos, vnew(-radius, -radius, -radius))
|
||||
local perm, err = areas:canPlayerAddArea(pos1, pos2, name)
|
||||
|
||||
if not perm then
|
||||
minetest.chat_send_player(name,
|
||||
red(S("You are not allowed to protect that area: @1", err)))
|
||||
return itemstack
|
||||
end
|
||||
|
||||
if minetest.find_node_near(pos, radius / 2, {"areas:protector"}) then
|
||||
minetest.chat_send_player(name, red(S("You have already protected this area.")))
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local id = areas:add(name, S("Protector Block"), pos1, pos2)
|
||||
areas:save()
|
||||
minetest.chat_send_player(name,
|
||||
S("The area from @1 to @2 has been protected as ID @3",
|
||||
cyan(minetest.pos_to_string(pos1)), cyan(minetest.pos_to_string(pos2)), cyan(id))
|
||||
)
|
||||
|
||||
minetest.set_node(pos, {name = "areas:protector"})
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("infotext", S("Protected area @1, Owned by @2", id, name))
|
||||
meta:set_int("area_id", id)
|
||||
itemstack:take_item()
|
||||
end
|
||||
|
||||
return itemstack
|
||||
end,
|
||||
|
||||
after_dig_node = function(_, _, oldmetadata, digger)
|
||||
if oldmetadata and oldmetadata.fields then
|
||||
local id = tonumber(oldmetadata.fields.area_id)
|
||||
local name = digger and digger:get_player_name() or ""
|
||||
if areas.areas[id] and areas:isAreaOwner(id, name) then
|
||||
areas:remove(id)
|
||||
areas:save()
|
||||
minetest.chat_send_player(name, S("Removed area @1", cyan(id)))
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
on_punch = function(pos)
|
||||
-- a radius of 0.5 since the entity serialization seems to be not that precise
|
||||
local objs = minetest.get_objects_inside_radius(pos, 0.5)
|
||||
for _, obj in pairs(objs) do
|
||||
if not obj:is_player() and obj:get_luaentity().name == "areas:display" then
|
||||
obj:remove()
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
minetest.add_entity(pos, "areas:display")
|
||||
end
|
||||
})
|
||||
|
||||
-- entities code below (and above) mostly copied-pasted from Zeg9's protector mod
|
||||
minetest.register_entity("areas:display", {
|
||||
physical = false,
|
||||
collisionbox = {0},
|
||||
visual = "wielditem",
|
||||
-- wielditem seems to be scaled to 1.5 times original node size
|
||||
visual_size = {x = 1.0 / 1.5, y = 1.0 / 1.5},
|
||||
textures = {"areas:display_node"},
|
||||
timer = 0,
|
||||
on_step = function(self, dtime)
|
||||
self.timer = self.timer + dtime
|
||||
if self.timer > 4 or
|
||||
minetest.get_node(self.object:get_pos()).name ~= "areas:protector" then
|
||||
self.object:remove()
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
local nb_radius = radius + 0.55
|
||||
|
||||
minetest.register_node("areas:display_node", {
|
||||
tiles = {"areas_protector_display.png"},
|
||||
use_texture_alpha = "clip",
|
||||
walkable = false,
|
||||
drawtype = "nodebox",
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
-- sides
|
||||
{-nb_radius, -nb_radius, -nb_radius, -nb_radius, nb_radius, nb_radius},
|
||||
{-nb_radius, -nb_radius, nb_radius, nb_radius, nb_radius, nb_radius},
|
||||
{nb_radius, -nb_radius, -nb_radius, nb_radius, nb_radius, nb_radius},
|
||||
{-nb_radius, -nb_radius, -nb_radius, nb_radius, nb_radius, -nb_radius},
|
||||
-- top
|
||||
{-nb_radius, nb_radius, -nb_radius, nb_radius, nb_radius, nb_radius},
|
||||
-- bottom
|
||||
{-nb_radius, -nb_radius, -nb_radius, nb_radius, -nb_radius, nb_radius},
|
||||
-- middle (surround protector)
|
||||
{-0.55, -0.55, -0.55, 0.55, 0.55, 0.55}
|
||||
}
|
||||
},
|
||||
selection_box = {type = "regular"},
|
||||
paramtype = "light",
|
||||
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
|
||||
drop = ""
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "areas:protector",
|
||||
type = "shapeless",
|
||||
recipe = {
|
||||
"default:stonebrickcarved", "default:stonebrickcarved", "default:stonebrickcarved",
|
||||
"default:stonebrickcarved", "mesecons:wire_00000000_off", "default:stonebrickcarved",
|
||||
"default:stonebrickcarved", "default:stonebrickcarved", "default:stonebrickcarved"
|
||||
}
|
||||
})
|
||||
|
||||
-- MVPS stopper
|
||||
if mesecon and mesecon.register_mvps_stopper then
|
||||
mesecon.register_mvps_stopper("areas:protector")
|
||||
end
|
||||
|
||||
-- Aliases
|
||||
minetest.register_alias("areasprotector:protector", "areas:protector")
|
||||
minetest.register_alias("areasprotector:display_node", "areas:display_node")
|
||||
minetest.register_alias("areasprotector:protector", "default:stonebrickcarved")
|
||||
minetest.register_alias("areasprotector:display_node", "air")
|
||||
|
||||
minetest.register_alias("areas:protector", "default:stonebrickcarved")
|
||||
minetest.register_alias("areas:display_node", "air")
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 88 B |
Binary file not shown.
Before Width: | Height: | Size: 272 B |
Loading…
Reference in New Issue