Hendrik Langer
5 years ago
6 changed files with 112 additions and 16 deletions
@ -0,0 +1,96 @@ |
|||||
|
if minetest.get_modpath("areas") then |
||||
|
|
||||
|
function creative_regions.protector_set_noflyzone(pos, placer, itemstack, pointed_thing) |
||||
|
if not pos or not placer then |
||||
|
return |
||||
|
end |
||||
|
local meta = minetest.get_meta(pos) |
||||
|
local name = placer:get_player_name(); |
||||
|
local player_owns_id = nil |
||||
|
|
||||
|
local current_areas = areas:getAreasAtPos(pos) |
||||
|
for areas_id, areas_area in pairs( current_areas ) do |
||||
|
if areas_area.owner == name then |
||||
|
player_owns_id = "a"..tostring(areas_id) |
||||
|
break |
||||
|
end |
||||
|
end |
||||
|
|
||||
|
if player_owns_id then |
||||
|
meta:set_string("infotext", string.format("No-Fly-Zone Protector for area %s owned by %s", player_owns_id, name) |
||||
|
meta:set_string("area_id", player_owns_id) |
||||
|
meta:set_string("owner", name) |
||||
|
|
||||
|
creative_regions.set_region_privs(tostring(player_owns_id), "-fast, -fly") |
||||
|
minetest.chat_send_player(name, "[creative_regions] No-Fly-Zone set for region " .. player_owns_id) |
||||
|
creative_regions.save_regions() |
||||
|
else |
||||
|
minetest.after(0.2, function(pos) |
||||
|
minetest.remove_node(pos) |
||||
|
end, pos) |
||||
|
end |
||||
|
|
||||
|
end |
||||
|
|
||||
|
function creative_regions.protector_can_dig(pos, player) |
||||
|
if not pos or not player then |
||||
|
return true |
||||
|
end |
||||
|
local name = player:get_player_name() |
||||
|
local meta = minetest.get_meta(pos) |
||||
|
local id = meta:get_string("area_id") |
||||
|
local owner = meta:get_string("owner") |
||||
|
|
||||
|
local player_owns_id = nil |
||||
|
|
||||
|
local current_areas = areas:getAreasAtPos(pos) |
||||
|
for areas_id, areas_area in pairs( current_areas ) do |
||||
|
if areas_area.owner == name then |
||||
|
player_owns_id = "a"..tostring(areas_id) |
||||
|
break |
||||
|
end |
||||
|
end |
||||
|
|
||||
|
if player_owns_id then |
||||
|
return true |
||||
|
else |
||||
|
minetest.chat_send_player(name, "[creative_regions] Cannot remove No-Fly-Zone "..id.." owned by "..owner) |
||||
|
return false |
||||
|
end |
||||
|
|
||||
|
end |
||||
|
|
||||
|
function creative_regions.protector_remove_noflyzone(pos, oldnode, oldmetadata, digger) |
||||
|
if not oldmetadata or not oldmetadata.fields then |
||||
|
return |
||||
|
end |
||||
|
local owner = oldmetadata.fields.owner |
||||
|
local stored_id = oldmetadata.fields.area_id |
||||
|
local name = digger:get_player_name() |
||||
|
|
||||
|
local current_areas = areas:getAreasAtPos(pos) |
||||
|
for areas_id, areas_area in pairs( current_areas ) do |
||||
|
local id = "a"..tostring(areas_id) |
||||
|
if stored_id == id then |
||||
|
creative_regions.set_region_privs(tostring(id), nil) |
||||
|
minetest.chat_send_player(name, "[creative_regions] No-Fly-Zone for area " .. id .. " removed") |
||||
|
creative_regions.save_regions() |
||||
|
end |
||||
|
end |
||||
|
|
||||
|
end |
||||
|
|
||||
|
minetest.register_node("creative_regions:protector_nofly", { |
||||
|
description = "No-Fly-Zone Protector", |
||||
|
tiles = {"creative_regions_protector_nofly.png"}, |
||||
|
is_ground_content = true, |
||||
|
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=1}, |
||||
|
light_source = 1, |
||||
|
after_place_node = creative_regions.protector_set_noflyzone, |
||||
|
can_dig = creative_regions.protector_can_dig, |
||||
|
after_dig_node = creative_regions.protector_remove_noflyzone, |
||||
|
}) |
||||
|
|
||||
|
--minetest.register_alias("noflyzone", "creative_regions:noflyprotector") |
||||
|
|
||||
|
end |
After Width: | Height: | Size: 2.1 KiB |
Loading…
Reference in new issue