mirror of
https://github.com/kakalak-lumberJack/creative_areas.git
synced 2024-12-23 09:20:33 +01:00
Update init.lua
entering and leaving defined creative areas now correctly toggles creative/standard SFINv inventory and privs.
This commit is contained in:
parent
fea02fe040
commit
c849155d09
41
init.lua
41
init.lua
@ -35,21 +35,31 @@ function check_cr_area(player)
|
|||||||
local pos = player:get_pos()
|
local pos = player:get_pos()
|
||||||
local area_at_pos = areas:getAreasAtPos(pos)
|
local area_at_pos = areas:getAreasAtPos(pos)
|
||||||
local status = false
|
local status = false
|
||||||
--minetest.chat_send_all(minetest.serialize(area_at_pos))
|
if #cr_areas >= 1 then
|
||||||
if cr_areas ~= nil then
|
for i = 1, #cr_areas do
|
||||||
for _, areaID in ipairs(cr_areas) do
|
local areaID = cr_areas[i]
|
||||||
for _, in_area in ipairs(area_at_pos) do
|
for _, in_area in pairs(area_at_pos) do
|
||||||
if in_area["pos1"] ~= nil
|
--if in_area["pos1"] ~= nil
|
||||||
and in_area["pos1"] == areas.areas[areaID]["pos1"]
|
if in_area["pos1"] == areas.areas[areaID]["pos1"]
|
||||||
and in_area["name"] == areas.areas[areaID]["name"] then
|
and in_area["name"] == areas.areas[areaID]["name"] then
|
||||||
status = true
|
status = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
return status
|
return status
|
||||||
|
end
|
||||||
|
|
||||||
|
local function on_grant_revoke(grantee, granter, priv)
|
||||||
|
if priv == "creative" then
|
||||||
|
local player = mientest.get_player_by_name(grantee)
|
||||||
|
if player then
|
||||||
|
sfinv.set_player_inventory_formspec(player, context)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--Initialize mod
|
--Initialize mod
|
||||||
minetest.register_privilege("teacher", "Give access to teacher features.")
|
minetest.register_privilege("teacher", "Give access to teacher features.")
|
||||||
|
|
||||||
@ -72,22 +82,29 @@ minetest.register_chatcommand("creative_area", {
|
|||||||
local timer = 0
|
local timer = 0
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
timer = timer + dtime
|
timer = timer + dtime
|
||||||
if timer >= 3 then
|
if timer >= math.random(1,3) then
|
||||||
for _, player in ipairs(minetest.get_connected_players()) do
|
for _, player in ipairs(minetest.get_connected_players()) do
|
||||||
local pname = player:get_player_name()
|
local pname = player:get_player_name()
|
||||||
local privs = minetest.get_player_privs(pname)
|
local privs = minetest.get_player_privs(pname)
|
||||||
if minetest.get_player_privs(pname).teacher == nil then
|
--if minetest.get_player_privs(pname).teacher == nil then
|
||||||
if check_cr_area(player) == true then
|
if check_cr_area(player) == true then
|
||||||
privs.give = true
|
if not minetest.check_player_privs(pname, {creative = true}) then
|
||||||
|
privs.creative = true
|
||||||
minetest.set_player_privs(pname, privs)
|
minetest.set_player_privs(pname, privs)
|
||||||
|
sfinv.set_player_inventory_formspec(player)
|
||||||
|
minetest.chat_send_player(pname, "You are in creative area.")
|
||||||
|
end
|
||||||
else
|
else
|
||||||
privs.give = nil
|
if minetest.check_player_privs(pname, {creative=true}) then
|
||||||
|
privs.creative = nil
|
||||||
minetest.set_player_privs(pname, privs)
|
minetest.set_player_privs(pname, privs)
|
||||||
|
local context = {page = sfinv.get_homepage_name(player)}
|
||||||
|
sfinv.set_player_inventory_formspec(player, context)
|
||||||
|
minetest.chat_send_player(pname, "Leaving creative area.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
--end
|
||||||
end
|
end
|
||||||
timer = 0
|
timer = 0
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- AndroBuilder git-Test
|
|
||||||
|
Loading…
Reference in New Issue
Block a user