Browse Source

initial noflyzone-block

main
Hendrik Langer 5 years ago
parent
commit
c743399a38
  1. 12
      chatcommands.lua
  2. 4
      init.lua
  3. 96
      items.lua
  4. 14
      region.lua
  5. 2
      settingtypes.txt
  6. BIN
      textures/creative_regions_protector_nofly.png

12
chatcommands.lua

@ -17,9 +17,9 @@ minetest.register_chatcommand("creative_region", {
local data = region_name local data = region_name
local astore_id = creative_regions.astore:insert_area(edge1, edge2, tostring(data)) local astore_id = creative_regions.astore:insert_area(edge1, edge2, tostring(data))
if astore_id then if astore_id then
creative_regions:set_region_privs("r"..tostring(astore_id), nil) creative_regions.set_region_privs("r"..tostring(astore_id), nil)
minetest.chat_send_player(name, "[creative_regions] New region set. ID: " .. "r"..astore_id) minetest.chat_send_player(name, "[creative_regions] New region set. ID: " .. "r"..astore_id)
creative_regions:save_regions() creative_regions.save_regions()
return true, "Done" return true, "Done"
else else
return false, "Failed" return false, "Failed"
@ -41,9 +41,9 @@ minetest.register_chatcommand("creative_region_privs", {
return false, "Syntax error" return false, "Syntax error"
end end
creative_regions:set_region_privs(tostring(region_id), privstring) creative_regions.set_region_privs(tostring(region_id), privstring)
minetest.chat_send_player(name, "[creative_regions] Privstring set for region " .. region_id .. ": " .. privstring) minetest.chat_send_player(name, "[creative_regions] Privstring set for region " .. region_id .. ": " .. privstring)
creative_regions:save_regions() creative_regions.save_regions()
return true, "Done" return true, "Done"
end, end,
}) })
@ -65,12 +65,12 @@ minetest.register_chatcommand("creative_region_rm", {
local success = creative_regions.astore:remove_area(astore_id) local success = creative_regions.astore:remove_area(astore_id)
if success then if success then
minetest.chat_send_player(name, "[creative_regions] Region " .. region_id .. "removed") minetest.chat_send_player(name, "[creative_regions] Region " .. region_id .. "removed")
creative_regions:set_region_privs(tostring(region_id), nil) creative_regions.set_region_privs(tostring(region_id), nil)
else else
minetest.chat_send_player(name, "Failed to remove region " .. region_id) minetest.chat_send_player(name, "Failed to remove region " .. region_id)
return false, "Region not found" return false, "Region not found"
end end
creative_regions:save_regions() creative_regions.save_regions()
return true, "Done." return true, "Done."
end, end,
}) })

4
init.lua

@ -37,7 +37,7 @@ function creative_regions:update_player(player)
end end
-- find active regions -- find active regions
local current_regions = self.astore:get_areas_for_pos(pos, true, true) local current_regions = creative_regions.astore:get_areas_for_pos(pos, true, true)
for astore_id, astore_area in pairs( current_regions ) do for astore_id, astore_area in pairs( current_regions ) do
local id = "r"..tostring(astore_id) local id = "r"..tostring(astore_id)
local size = creative_regions:get_region_size(astore_area) local size = creative_regions:get_region_size(astore_area)
@ -100,7 +100,7 @@ function creative_regions:update_player(player)
end end
creative_regions:load_regions() creative_regions.load_regions()
local timer = 0 local timer = 0
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)

96
items.lua

@ -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

14
region.lua

@ -3,19 +3,19 @@ creative_regions.mod_storage = minetest.get_mod_storage()
creative_regions.region_privs = {} creative_regions.region_privs = {}
function creative_regions:load_regions() function creative_regions.load_regions()
self.astore:from_file(minetest.get_worldpath().."/creative_regions_regions") creative_regions.astore:from_file(minetest.get_worldpath().."/creative_regions_regions")
creative_regions.region_privs = minetest.deserialize(creative_regions.mod_storage:get_string("astore_privs")) or {} creative_regions.region_privs = minetest.deserialize(creative_regions.mod_storage:get_string("astore_privs")) or {}
-- local edge1 = { x=-10, y=-10, z=-10 } -- local edge1 = { x=-10, y=-10, z=-10 }
-- local edge2 = { x=10, y=10, z=10 } -- local edge2 = { x=10, y=10, z=10 }
-- local data = "Testregion" -- local data = "Testregion"
-- local astore_id = self.astore:insert_area(edge1, edge2, tostring(data)) -- local astore_id = creative_regions.astore:insert_area(edge1, edge2, tostring(data))
-- --
-- creative_regions:set_region_privs("r"..astore_id, "+creative, +fast, +fly") -- creative_regions.set_region_privs("r"..astore_id, "+creative, +fast, +fly")
end end
function creative_regions:save_regions() function creative_regions.save_regions()
self.astore:to_file(minetest.get_worldpath().."/creative_regions_regions") creative_regions.astore:to_file(minetest.get_worldpath().."/creative_regions_regions")
local datastr = minetest.serialize(creative_regions.region_privs) local datastr = minetest.serialize(creative_regions.region_privs)
if not datastr then if not datastr then
minetest.log("error", "[creative_regions] Failed to serialize region_privs data!") minetest.log("error", "[creative_regions] Failed to serialize region_privs data!")
@ -32,7 +32,7 @@ function creative_regions:get_region_size(astore_area)
return x*z return x*z
end end
function creative_regions:set_region_privs(id, privs_string) function creative_regions.set_region_privs(id, privs_string)
creative_regions.region_privs[tostring(id)] = privs_string creative_regions.region_privs[tostring(id)] = privs_string
end end

2
settingtypes.txt

@ -2,7 +2,7 @@
creative_regions.owner_privs (Owner privs) string "+creative, +fast, +fly" creative_regions.owner_privs (Owner privs) string "+creative, +fast, +fly"
# Privs of an areas mod guest # Privs of an areas mod guest
creative_regions.guest_privs (Guest privs) string "-fly, -fast" creative_regions.guest_privs (Guest privs) string "-fast, -fly"
# Default privs when not in an area # Default privs when not in an area
creative_regions.noregion_privs (Noregion default privs) string "-creative, -fast, -fly" creative_regions.noregion_privs (Noregion default privs) string "-creative, -fast, -fly"

BIN
textures/creative_regions_protector_nofly.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Loading…
Cancel
Save