Browse Source

working

main
Hendrik Langer 5 years ago
parent
commit
143e2a5327
  1. 62
      init.lua
  2. 4
      settingtypes.txt

62
init.lua

@ -9,9 +9,9 @@ toggle_areas.area_privs = {}
toggle_areas.registered_on_enter = {} toggle_areas.registered_on_enter = {}
toggle_areas.registered_on_leave = {} toggle_areas.registered_on_leave = {}
areas_owner_privs = minetest.settings:get("toggle_areas.owner_privs") or "+creative, +fly, +fast" areas_owner_privs = minetest.settings:get("toggle_areas.owner_privs") or "+creative, +fast, +fly"
areas_guest_privs = minetest.settings:get("toggle_areas.guest_privs") or "-fly, -fast" areas_guest_privs = minetest.settings:get("toggle_areas.guest_privs") or "-fly, -fast"
default_privs = minetest.settings:get("toggle_areas.default_privs") or "+fast, -creative" default_privs = minetest.settings:get("toggle_areas.default_privs") or "-creative, +fast, -fly"
function toggle_areas:load_areas() function toggle_areas:load_areas()
local test = minetest.deserialize(mod_storage:get_string("astore")) local test = minetest.deserialize(mod_storage:get_string("astore"))
@ -20,7 +20,7 @@ function toggle_areas:load_areas()
local data = "Testarea" local data = "Testarea"
local astore_id = self.astore:insert_area(edge1, edge2, tostring(data)) local astore_id = self.astore:insert_area(edge1, edge2, tostring(data))
self.set_area_privs(astore_id, "+fly, +fast, +creative") toggle_areas:set_area_privs(astore_id, "+creative, +fast, +fly")
self.register_on_enter(astore_id, function(player) self.register_on_enter(astore_id, function(player)
local name = player:get_player_name() local name = player:get_player_name()
@ -61,8 +61,10 @@ function toggle_areas:decode_privs_string(str)
priv = string.sub(priv, 2) priv = string.sub(priv, 2)
if toggle == '+' then if toggle == '+' then
privs_grant[priv] = true privs_grant[priv] = true
privs_revoke[priv] = nil
elseif toggle == '-' then elseif toggle == '-' then
privs_revoke[priv] = true privs_revoke[priv] = true
privs_grant[priv] = nil
end end
end end
return privs_grant, privs_revoke return privs_grant, privs_revoke
@ -149,8 +151,8 @@ function toggle_areas:update_player(player)
local pmeta = player:get_meta() local pmeta = player:get_meta()
-- pmeta:mark_as_private("toggle_areas") -- pmeta:mark_as_private("toggle_areas")
local player_last_active_area = pmeta:get_string("toggle_areas.active_area") or "-1" local player_last_active_areas = pmeta:get_string("toggle_areas.active_areas") or "-1"
local player_active_area = "-1" local player_active_areas = "-1"
local areas_owner = false local areas_owner = false
local areas_guest = false local areas_guest = false
local areas_open = false local areas_open = false
@ -162,40 +164,38 @@ function toggle_areas:update_player(player)
return return
end end
-- enter area
local current_areas = self.astore:get_areas_for_pos(pos, true, true)
for astore_id, astore_area in pairs( current_areas ) do
local areasize = toggle_areas:get_area_size(astore_area)
if not smallest_area.size or areasize < smallest_area.size then
smallest_area.id = astore_id
smallest_area.size = areasize
end
end
if smallest_area.id then
player_active_areas = tostring(smallest_area.id)
end
-- enter areas mod area -- enter areas mod area
local a_current_areas = {} local a_current_areas = {}
if minetest.get_modpath("areas") then if minetest.get_modpath("areas") then
a_current_areas = areas:getAreasAtPos(pos) a_current_areas = areas:getAreasAtPos(pos)
for a_id, a_area in pairs( a_current_areas ) do for a_id, a_area in pairs( a_current_areas ) do
player_active_areas = player_active_areas .. ", a"..a_id
if a_area.owner == name then if a_area.owner == name then
areas_owner = true areas_owner = true
player_active_area = "a"..a_id
break break
elseif a_area.open then elseif a_area.open then
areas_open = true areas_open = true
player_active_area = "a"..a_id
break break
else else
areas_guest = true areas_guest = true
player_active_area = "a"..a_id --continue
break
end end
end end
end end
-- enter area
local current_areas = self.astore:get_areas_for_pos(pos, true, true)
for astore_id, astore_area in pairs( current_areas ) do
local areasize = toggle_areas:get_area_size(astore_area)
if not smallest_area.size or areasize < smallest_area.size then
smallest_area.id = astore_id
smallest_area.size = areasize
end
end
if player_active_area == "-1" and smallest_area.id then
player_active_area = smallest_area.id
end
local privstring = default_privs local privstring = default_privs
if smallest_area.id and toggle_areas.area_privs[smallest_area.id] then if smallest_area.id and toggle_areas.area_privs[smallest_area.id] then
privstring = toggle_areas.area_privs[smallest_area.id] privstring = toggle_areas.area_privs[smallest_area.id]
@ -203,17 +203,21 @@ function toggle_areas:update_player(player)
if areas_owner or areas_open then if areas_owner or areas_open then
privstring = privstring .. ", " .. areas_owner_privs privstring = privstring .. ", " .. areas_owner_privs
elseif areas_guest then elseif areas_guest then
if toggle_areas.area_privs[player_active_area] then privstring = privstring .. ", " .. areas_guest_privs
privstring = privstring .. ", " .. toggle_areas.area_privs[player_active_area] for _, a in pairs(string.split(player_active_areas, ",")) do
else a = a:trim()
privstring = privstring .. ", " .. areas_guest_privs if string.sub(a, 1, 1) == "a" then
if toggle_areas.area_privs[a] then
privstring = privstring .. ", " .. toggle_areas.area_privs[a]
end
end
end end
end end
if player_active_area ~= player_last_active_area then if player_active_areas ~= player_last_active_areas then
minetest.log("warning", "[toggle_areas] player entering new area "..player_last_active_area.."->"..player_active_area) minetest.log("warning", "[toggle_areas] player entering new area "..player_last_active_areas.."->"..player_active_areas)
toggle_areas:player_enter_area(player, privstring) toggle_areas:player_enter_area(player, privstring)
pmeta:set_string("toggle_areas.active_area", player_active_area) pmeta:set_string("toggle_areas.active_areas", player_active_areas)
end end
-- print(dump(pmeta:to_table())) -- print(dump(pmeta:to_table()))

4
settingtypes.txt

@ -1,8 +1,8 @@
# Privs of an areas mod owner # Privs of an areas mod owner
toggle_areas.owner_privs (Owner privs) string "+creative, +fly, +fast" toggle_areas.owner_privs (Owner privs) string "+creative, +fast, +fly"
# Privs of an areas mod guest # Privs of an areas mod guest
toggle_areas.guest_privs (Guest privs) string "-fly, -fast" toggle_areas.guest_privs (Guest privs) string "-fly, -fast"
# Default privs # Default privs
toggle_areas.guest_privs (Default privs) string "+fast, -creative" toggle_areas.guest_privs (Default privs) string "-creative, -fast, -fly"

Loading…
Cancel
Save