Compare commits
3 Commits
creative_a
...
master
Author | SHA1 | Date | |
---|---|---|---|
cf6e03939f | |||
|
3264945c6d | ||
|
870fbb9c21 |
|
@ -1,6 +1,6 @@
|
|||
# Creative Areas
|
||||
|
||||
Creative Areas is a minetest mod allowing areas defined by the Areas mod to be designated as creative/sandbox areas adjusting players privliges and inventory formspecs appropriately as they leave or enter these areas. Items mined or taken from creative inventory inside creative area will be removed from players inventories upon leaving creative areas.
|
||||
Creative Areas is a minetest mod allowing areas defined by the Areas mod to be designated as creative/sandbox areas adjusting players privileges and inventory formspecs appropriately as they leave or enter these areas. Items mined or taken from creative inventory inside creative area will be removed from players inventories upon leaving creative areas.
|
||||
|
||||
Players with the 'privs' priv will not have privileges or inventories affected moving in and out of these areas.
|
||||
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
Minetest Game mod: creative
|
||||
===========================
|
||||
See license.txt for license information.
|
||||
|
||||
Authors of source code
|
||||
----------------------
|
||||
Originally by Perttu Ahola (celeron55) <celeron55@gmail.com> (MIT)
|
||||
Jean-Patrick G. (kilbith) <jeanpatrick.guerrero@gmail.com> (MIT)
|
||||
|
||||
Author of media (textures)
|
||||
--------------------------
|
||||
paramat (CC BY-SA 3.0):
|
||||
* creative_prev_icon.png
|
||||
* creative_next_icon.png
|
||||
* creative_search_icon.png
|
||||
* creative_clear_icon.png
|
||||
* creative_trash_icon.png derived from a texture by kilbith (CC BY-SA 3.0)
|
|
@ -1,2 +0,0 @@
|
|||
default
|
||||
sfinv
|
|
@ -1,70 +0,0 @@
|
|||
creative = {}
|
||||
|
||||
minetest.register_privilege("creative", {
|
||||
description = "Allow player to use creative inventory",
|
||||
give_to_singleplayer = false,
|
||||
give_to_admin = false
|
||||
})
|
||||
|
||||
local creative_mode_cache = minetest.settings:get_bool("creative_mode")
|
||||
|
||||
function creative.is_enabled_for(name)
|
||||
return creative_mode_cache or
|
||||
minetest.check_player_privs(name, {creative = true})
|
||||
end
|
||||
|
||||
dofile(minetest.get_modpath("creative") .. "/inventory.lua")
|
||||
|
||||
if creative_mode_cache then
|
||||
-- Dig time is modified according to difference (leveldiff) between tool
|
||||
-- 'maxlevel' and node 'level'. Digtime is divided by the larger of
|
||||
-- leveldiff and 1.
|
||||
-- To speed up digging in creative, hand 'maxlevel' and 'digtime' have been
|
||||
-- increased such that nodes of differing levels have an insignificant
|
||||
-- effect on digtime.
|
||||
local digtime = 42
|
||||
local caps = {times = {digtime, digtime, digtime}, uses = 0, maxlevel = 256}
|
||||
|
||||
minetest.register_item(":", {
|
||||
type = "none",
|
||||
wield_image = "wieldhand.png",
|
||||
wield_scale = {x = 1, y = 1, z = 2.5},
|
||||
range = 10,
|
||||
tool_capabilities = {
|
||||
full_punch_interval = 0.5,
|
||||
max_drop_level = 3,
|
||||
groupcaps = {
|
||||
crumbly = caps,
|
||||
cracky = caps,
|
||||
snappy = caps,
|
||||
choppy = caps,
|
||||
oddly_breakable_by_hand = caps,
|
||||
},
|
||||
damage_groups = {fleshy = 10},
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
-- Unlimited node placement
|
||||
minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack)
|
||||
if placer and placer:is_player() then
|
||||
return creative.is_enabled_for(placer:get_player_name())
|
||||
end
|
||||
end)
|
||||
|
||||
-- Don't pick up if the item is already in the inventory
|
||||
local old_handle_node_drops = minetest.handle_node_drops
|
||||
function minetest.handle_node_drops(pos, drops, digger)
|
||||
if not digger or not digger:is_player() or
|
||||
not creative.is_enabled_for(digger:get_player_name()) then
|
||||
return old_handle_node_drops(pos, drops, digger)
|
||||
end
|
||||
local inv = digger:get_inventory()
|
||||
if inv then
|
||||
for _, item in ipairs(drops) do
|
||||
if not inv:contains_item("main", item, true) then
|
||||
inv:add_item("main", item)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,193 +0,0 @@
|
|||
local player_inventory = {}
|
||||
local inventory_cache = {}
|
||||
|
||||
local function init_creative_cache(items)
|
||||
inventory_cache[items] = {}
|
||||
local i_cache = inventory_cache[items]
|
||||
|
||||
for name, def in pairs(items) do
|
||||
if def.groups.not_in_creative_inventory ~= 1 and
|
||||
def.description and def.description ~= "" then
|
||||
i_cache[name] = def
|
||||
end
|
||||
end
|
||||
table.sort(i_cache)
|
||||
return i_cache
|
||||
end
|
||||
|
||||
function creative.init_creative_inventory(player)
|
||||
local player_name = player:get_player_name()
|
||||
player_inventory[player_name] = {
|
||||
size = 0,
|
||||
filter = "",
|
||||
start_i = 0
|
||||
}
|
||||
|
||||
minetest.create_detached_inventory("creative_" .. player_name, {
|
||||
allow_move = function(inv, from_list, from_index, to_list, to_index, count, player2)
|
||||
local name = player2 and player2:get_player_name() or ""
|
||||
if not creative.is_enabled_for(name) or
|
||||
to_list == "main" then
|
||||
return 0
|
||||
end
|
||||
return count
|
||||
end,
|
||||
allow_put = function(inv, listname, index, stack, player2)
|
||||
return 0
|
||||
end,
|
||||
allow_take = function(inv, listname, index, stack, player2)
|
||||
local name = player2 and player2:get_player_name() or ""
|
||||
if not creative.is_enabled_for(name) then
|
||||
return 0
|
||||
end
|
||||
return -1
|
||||
end,
|
||||
on_move = function(inv, from_list, from_index, to_list, to_index, count, player2)
|
||||
end,
|
||||
on_take = function(inv, listname, index, stack, player2)
|
||||
if stack and stack:get_count() > 0 then
|
||||
minetest.log("action", player_name .. " takes " .. stack:get_name().. " from creative inventory")
|
||||
end
|
||||
end,
|
||||
}, player_name)
|
||||
|
||||
return player_inventory[player_name]
|
||||
end
|
||||
|
||||
function creative.update_creative_inventory(player_name, tab_content)
|
||||
local creative_list = {}
|
||||
local inv = player_inventory[player_name] or
|
||||
creative.init_creative_inventory(minetest.get_player_by_name(player_name))
|
||||
local player_inv = minetest.get_inventory({type = "detached", name = "creative_" .. player_name})
|
||||
|
||||
local items = inventory_cache[tab_content] or init_creative_cache(tab_content)
|
||||
|
||||
for name, def in pairs(items) do
|
||||
if def.name:find(inv.filter, 1, true) or
|
||||
def.description:lower():find(inv.filter, 1, true) then
|
||||
creative_list[#creative_list+1] = name
|
||||
end
|
||||
end
|
||||
|
||||
table.sort(creative_list)
|
||||
player_inv:set_size("main", #creative_list)
|
||||
player_inv:set_list("main", creative_list)
|
||||
inv.size = #creative_list
|
||||
end
|
||||
|
||||
-- Create the trash field
|
||||
local trash = minetest.create_detached_inventory("creative_trash", {
|
||||
-- Allow the stack to be placed and remove it in on_put()
|
||||
-- This allows the creative inventory to restore the stack
|
||||
allow_put = function(inv, listname, index, stack, player)
|
||||
return stack:get_count()
|
||||
end,
|
||||
on_put = function(inv, listname)
|
||||
inv:set_list(listname, {})
|
||||
end,
|
||||
})
|
||||
trash:set_size("main", 1)
|
||||
|
||||
creative.formspec_add = ""
|
||||
|
||||
function creative.register_tab(name, title, items)
|
||||
sfinv.register_page("creative:" .. name, {
|
||||
title = title,
|
||||
is_in_nav = function(self, player, context)
|
||||
return creative.is_enabled_for(player:get_player_name())
|
||||
end,
|
||||
get = function(self, player, context)
|
||||
local player_name = player:get_player_name()
|
||||
creative.update_creative_inventory(player_name, items)
|
||||
local inv = player_inventory[player_name]
|
||||
local start_i = inv.start_i or 0
|
||||
local pagenum = math.floor(start_i / (3*8) + 1)
|
||||
local pagemax = math.ceil(inv.size / (3*8))
|
||||
return sfinv.make_formspec(player, context,
|
||||
"label[6.2,3.35;" .. minetest.colorize("#FFFF00", tostring(pagenum)) .. " / " .. tostring(pagemax) .. "]" ..
|
||||
[[
|
||||
image[4.06,3.4;0.8,0.8;creative_trash_icon.png]
|
||||
listcolors[#00000069;#5A5A5A;#141318;#30434C;#FFF]
|
||||
list[current_player;main;0,4.7;8,1;]
|
||||
list[current_player;main;0,5.85;8,3;8]
|
||||
list[detached:creative_trash;main;4,3.3;1,1;]
|
||||
listring[]
|
||||
image_button[5.4,3.25;0.8,0.8;creative_prev_icon.png;creative_prev;]
|
||||
image_button[7.2,3.25;0.8,0.8;creative_next_icon.png;creative_next;]
|
||||
image_button[2.1,3.25;0.8,0.8;creative_search_icon.png;creative_search;]
|
||||
image_button[2.75,3.25;0.8,0.8;creative_clear_icon.png;creative_clear;]
|
||||
tooltip[creative_search;Search]
|
||||
tooltip[creative_clear;Reset]
|
||||
tooltip[creative_prev;Previous page]
|
||||
tooltip[creative_next;Next page]
|
||||
listring[current_player;main]
|
||||
field_close_on_enter[creative_filter;false]
|
||||
]] ..
|
||||
"field[0.3,3.5;2.2,1;creative_filter;;" .. minetest.formspec_escape(inv.filter) .. "]" ..
|
||||
"listring[detached:creative_" .. player_name .. ";main]" ..
|
||||
"list[detached:creative_" .. player_name .. ";main;0,0;8,3;" .. tostring(start_i) .. "]" ..
|
||||
default.get_hotbar_bg(0,4.7) ..
|
||||
default.gui_bg .. default.gui_bg_img .. default.gui_slots
|
||||
.. creative.formspec_add, false)
|
||||
end,
|
||||
on_enter = function(self, player, context)
|
||||
local player_name = player:get_player_name()
|
||||
local inv = player_inventory[player_name]
|
||||
if inv then
|
||||
inv.start_i = 0
|
||||
end
|
||||
end,
|
||||
on_player_receive_fields = function(self, player, context, fields)
|
||||
local player_name = player:get_player_name()
|
||||
local inv = player_inventory[player_name]
|
||||
assert(inv)
|
||||
|
||||
if fields.creative_clear then
|
||||
inv.start_i = 0
|
||||
inv.filter = ""
|
||||
creative.update_creative_inventory(player_name, items)
|
||||
sfinv.set_player_inventory_formspec(player, context)
|
||||
elseif fields.creative_search or
|
||||
fields.key_enter_field == "creative_filter" then
|
||||
inv.start_i = 0
|
||||
inv.filter = fields.creative_filter:lower()
|
||||
creative.update_creative_inventory(player_name, items)
|
||||
sfinv.set_player_inventory_formspec(player, context)
|
||||
elseif not fields.quit then
|
||||
local start_i = inv.start_i or 0
|
||||
|
||||
if fields.creative_prev then
|
||||
start_i = start_i - 3*8
|
||||
if start_i < 0 then
|
||||
start_i = inv.size - (inv.size % (3*8))
|
||||
if inv.size == start_i then
|
||||
start_i = math.max(0, inv.size - (3*8))
|
||||
end
|
||||
end
|
||||
elseif fields.creative_next then
|
||||
start_i = start_i + 3*8
|
||||
if start_i >= inv.size then
|
||||
start_i = 0
|
||||
end
|
||||
end
|
||||
|
||||
inv.start_i = start_i
|
||||
sfinv.set_player_inventory_formspec(player, context)
|
||||
end
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
creative.register_tab("all", "All", minetest.registered_items)
|
||||
creative.register_tab("nodes", "Nodes", minetest.registered_nodes)
|
||||
creative.register_tab("tools", "Tools", minetest.registered_tools)
|
||||
creative.register_tab("craftitems", "Items", minetest.registered_craftitems)
|
||||
|
||||
local old_homepage_name = sfinv.get_homepage_name
|
||||
function sfinv.get_homepage_name(player)
|
||||
if creative.is_enabled_for(player:get_player_name()) then
|
||||
return "creative:all"
|
||||
else
|
||||
return old_homepage_name(player)
|
||||
end
|
||||
end
|
|
@ -1,61 +0,0 @@
|
|||
License of source code
|
||||
----------------------
|
||||
|
||||
The MIT License (MIT)
|
||||
Copyright (C) 2012-2016 Perttu Ahola (celeron55) <celeron55@gmail.com>
|
||||
Copyright (C) 2015-2016 Jean-Patrick G. (kilbith) <jeanpatrick.guerrero@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
software and associated documentation files (the "Software"), to deal in the Software
|
||||
without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
||||
persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more details:
|
||||
https://opensource.org/licenses/MIT
|
||||
|
||||
|
||||
Licenses of media (textures)
|
||||
----------------------------
|
||||
|
||||
Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
|
||||
Copyright (C) 2016 Jean-Patrick G. (kilbith) <jeanpatrick.guerrero@gmail.com>
|
||||
Copyright (C) 2018 paramat
|
||||
|
||||
You are free to:
|
||||
Share — copy and redistribute the material in any medium or format.
|
||||
Adapt — remix, transform, and build upon the material for any purpose, even commercially.
|
||||
The licensor cannot revoke these freedoms as long as you follow the license terms.
|
||||
|
||||
Under the following terms:
|
||||
|
||||
Attribution — You must give appropriate credit, provide a link to the license, and
|
||||
indicate if changes were made. You may do so in any reasonable manner, but not in any way
|
||||
that suggests the licensor endorses you or your use.
|
||||
|
||||
ShareAlike — If you remix, transform, or build upon the material, you must distribute
|
||||
your contributions under the same license as the original.
|
||||
|
||||
No additional restrictions — You may not apply legal terms or technological measures that
|
||||
legally restrict others from doing anything the license permits.
|
||||
|
||||
Notices:
|
||||
|
||||
You do not have to comply with the license for elements of the material in the public
|
||||
domain or where your use is permitted by an applicable exception or limitation.
|
||||
No warranties are given. The license may not give you all of the permissions necessary
|
||||
for your intended use. For example, other rights such as publicity, privacy, or moral
|
||||
rights may limit how you use the material.
|
||||
|
||||
For more details:
|
||||
http://creativecommons.org/licenses/by-sa/3.0/
|
Before Width: | Height: | Size: 708 B |
Before Width: | Height: | Size: 728 B |
Before Width: | Height: | Size: 729 B |
Before Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 712 B |
|
@ -1,147 +0,0 @@
|
|||
local storage = minetest.get_mod_storage()
|
||||
local cr_areas = minetest.deserialize(storage:get_string("cr_areas")) or {}
|
||||
---------------
|
||||
-- Functions
|
||||
---------------
|
||||
-- Add creative area to list.
|
||||
local function make_cr_area(name, areaID)
|
||||
local id = tonumber(areaID)
|
||||
if areas.areas[id] ~= nil then
|
||||
if cr_areas ~= {} then
|
||||
for i = 1, #cr_areas do
|
||||
if cr_areas[i] == id then
|
||||
return minetest.chat_send_player(name, "Area " ..id.." is already a creative area.")
|
||||
end
|
||||
end
|
||||
end
|
||||
table.insert(cr_areas, id)
|
||||
storage:set_string("cr_areas", minetest.serialize(cr_areas))
|
||||
minetest.chat_send_player(name, "Area added to Creative Areas!")
|
||||
else minetest.chat_send_player(name, "Not a valid area ID")
|
||||
end
|
||||
end
|
||||
--Removes Creative Area
|
||||
local function rm_cr_area(name, areaID)
|
||||
local id = tonumber(areaID)
|
||||
for i = 1, #cr_areas do
|
||||
if cr_areas[i] == id then
|
||||
table.remove(cr_areas, i)
|
||||
storage:set_string("cr_areas", minetest.serialize(cr_areas))
|
||||
return minetest.chat_send_player(name, "Creative area removed!")
|
||||
end
|
||||
end
|
||||
return minetest.chat_send_player(name, "Not a creative area ID")
|
||||
end
|
||||
-- Checks players location against listed creative areas.
|
||||
function check_cr_area(player)
|
||||
local pos = player:get_pos()
|
||||
local area_at_pos = areas:getAreasAtPos(pos)
|
||||
local status = false
|
||||
if cr_areas ~= {} then
|
||||
for i = 1, #cr_areas do
|
||||
local areaID = cr_areas[i]
|
||||
-- Clean up creative areas which are have been deleted from Areas mod
|
||||
if areas.areas[areaID] == nil then
|
||||
table.remove(cr_areas, i)
|
||||
storage:set_string("cr_areas", minetest.serialize(cr_areas))
|
||||
end
|
||||
-- Compare Areas which player are in with Creative Area. Grant/revoke creative priv accordingly."
|
||||
for _, in_area in pairs(area_at_pos) do
|
||||
if in_area["pos1"] == areas.areas[areaID]["pos1"] --make sure the areas are not just the same name.
|
||||
and in_area["name"] == areas.areas[areaID]["name"] then
|
||||
status = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return status
|
||||
end
|
||||
--------------------
|
||||
-- Chat Commands
|
||||
-------------------
|
||||
minetest.register_chatcommand("creative_area", {
|
||||
description = "Sets area to grant players creative priv while inside it",
|
||||
params = "<AreaID>",
|
||||
privs = {privs = true},
|
||||
func = function(name, param)
|
||||
make_cr_area(name, param)
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("rm_creative_area", {
|
||||
description = "Revokes area from list of creative areas",
|
||||
params = "<AreaID>",
|
||||
privs = {privs = true},
|
||||
func = function(name, param)
|
||||
rm_cr_area(name, param)
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("ls_creative_areas", {
|
||||
description = "List creative areas and IDs",
|
||||
params = "",
|
||||
func = function(name, params)
|
||||
local list = ""
|
||||
if cr_areas ~= {} then
|
||||
for i = 1, #cr_areas do
|
||||
local id = tonumber(cr_areas[i])
|
||||
local area_name = areas.areas[ id ]["name"]
|
||||
list = list .. " " .. area_name .. " (ID="..id..")"
|
||||
end
|
||||
minetest.chat_send_player(name, "Creative Area (ID): "..list)
|
||||
else minetest.chat_send_player(name, "No creative areas found")
|
||||
end
|
||||
end
|
||||
})
|
||||
-------------------------------------------------
|
||||
-- Check location and Grant/revoke creative priv
|
||||
-------------------------------------------------
|
||||
local timer = 0
|
||||
minetest.register_globalstep(function(dtime)
|
||||
timer = timer + dtime
|
||||
if timer >= math.random(1,3) then
|
||||
for _, player in ipairs(minetest.get_connected_players()) do
|
||||
local pname = player:get_player_name()
|
||||
local privs = minetest.get_player_privs(pname)
|
||||
local inv = minetest.get_inventory({type="player", name=pname})
|
||||
if minetest.get_player_privs(pname).privs == nil then --Players with the "privs" priv will not have privileges effected.
|
||||
if check_cr_area(player) == true then
|
||||
if not minetest.check_player_privs(pname, {creative = true}) then
|
||||
privs.creative = true
|
||||
minetest.set_player_privs(pname, privs)
|
||||
if not minetest.get_modpath("unified_inventory") then
|
||||
local context = {page = sfinv.get_homepage_name(player)}--minetest.get_inventory{{type="detached", name="creative_"..pname}}--{page = sfinv.pages["creative_"..pname]}
|
||||
sfinv.set_player_inventory_formspec(player, context)
|
||||
end
|
||||
--unified_inventory.get_formspec(player, page)
|
||||
local invlist = inv:get_list("main")
|
||||
inv:set_list("saved", invlist)
|
||||
local list = ""
|
||||
for i = 1, #invlist do
|
||||
list = list .." "..dump(invlist[i])
|
||||
end
|
||||
--write_file(inv_file,)
|
||||
minetest.chat_send_player(pname, "You are in creative area.")
|
||||
|
||||
end
|
||||
else
|
||||
if minetest.check_player_privs(pname, {creative=true}) then
|
||||
privs.creative = nil
|
||||
minetest.set_player_privs(pname, privs)
|
||||
local saved = inv:get_list("saved")
|
||||
if saved ~= nil then
|
||||
inv:set_list("main", saved)
|
||||
end
|
||||
if not minetest.get_modpath("unified_inventory") then
|
||||
local context = {page = sfinv.get_homepage_name(player)}
|
||||
sfinv.set_player_inventory_formspec(player, context)
|
||||
end
|
||||
--unified_inventory.get_formspec(player, page)
|
||||
minetest.chat_send_player(pname, "You have left creative area.")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
timer = 0
|
||||
end
|
||||
end)
|
349
init.lua
Normal file
|
@ -0,0 +1,349 @@
|
|||
local storage = minetest.get_mod_storage()
|
||||
local cr_areas = minetest.deserialize(storage:get_string("cr_areas")) or {}
|
||||
local privtbl = {["interact"] = false, ["fast"] = false, ["fly"] = false,
|
||||
["noclip"] = false, ["creative"] = false, ["teleport"] = false, ["worldedit"] = false}
|
||||
|
||||
---------------
|
||||
-- Functions
|
||||
---------------
|
||||
-- Check for intersecting creative areas
|
||||
function intersects_cr_area(areaID)
|
||||
local ID = areaID
|
||||
local newarea = areas.areas[ID]
|
||||
local np1, np2 = newarea["pos1"], newarea["pos2"]
|
||||
if cr_areas == {} then
|
||||
return false
|
||||
end
|
||||
for k, v in pairs(cr_areas) do
|
||||
local id = tonumber(k)
|
||||
local area = areas.areas[tonumber(id)]
|
||||
if area ~= nil then
|
||||
local p1, p2 = area["pos1"], area["pos2"]
|
||||
for cx = p1.x, p2.x do
|
||||
for cy = p1.y, p2.y do
|
||||
for cz = p1.z, p2.z do
|
||||
for nx = np1.x, np2.x do
|
||||
for ny = np1.y, np2.y do
|
||||
for nz = np1.z, np2.z do
|
||||
if cx == nx and cy == ny and cz == nz then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
-- Add creative area to list.
|
||||
local function make_cr_area(name, areaID)
|
||||
local id = tonumber(areaID)
|
||||
local intersects = intersects_cr_area(id)
|
||||
if intersects == true then
|
||||
return minetest.chat_send_player(name, "This area interesects another creative area.")
|
||||
end
|
||||
if privs == nil then privs = privtbl end
|
||||
if areas.areas[id] ~= nil then
|
||||
id = tostring(id)
|
||||
if cr_areas ~= {} then
|
||||
if cr_areas[id] then
|
||||
cr_areas[id]["privs"] = privs
|
||||
return minetest.chat_send_player(name, "Creative Area " ..id.." updated")
|
||||
end
|
||||
end
|
||||
local cr_area = {}
|
||||
cr_area["privs"] = privs
|
||||
cr_areas[id] = cr_area
|
||||
storage:set_string("cr_areas", minetest.serialize(cr_areas))
|
||||
minetest.chat_send_player(name, "Area added to Creative Areas!")
|
||||
else minetest.chat_send_player(name, "Not a valid area ID")
|
||||
end
|
||||
end
|
||||
--Removes Creative Area
|
||||
local function rm_cr_area(name, ID)
|
||||
local id = tostring(ID)
|
||||
local i = 1
|
||||
if cr_areas[id] then
|
||||
for k,v in pairs(cr_areas) do
|
||||
if k == id then
|
||||
cr_areas[k] = nil
|
||||
storage:set_string("cr_areas", minetest.serialize(cr_areas))
|
||||
return minetest.chat_send_player(name, "Creative area removed!")
|
||||
end
|
||||
end
|
||||
else
|
||||
return minetest.chat_send_player(name, "Not a creative area ID")
|
||||
end
|
||||
end
|
||||
--Remove creative area which are no longer stored by areas mod
|
||||
local function rm_nil_areas(areaID)
|
||||
if areas.areas[areaID] == nil then
|
||||
cr_areas[tostring(areaID)] = nil
|
||||
storage:set_string("cr_areas", minetest.serialize(cr_areas))
|
||||
end
|
||||
end
|
||||
-- Checks players location against listed creative areas.
|
||||
local function check_cr_area(player)
|
||||
local pos = player:get_pos()
|
||||
local area_at_pos = areas:getAreasAtPos(pos)
|
||||
local status = false
|
||||
local ID = 0
|
||||
--if area_at_pos ~= {} then
|
||||
for k, v in pairs(cr_areas) do
|
||||
if tonumber(k) ~= nil then
|
||||
local areaID = tonumber(k)
|
||||
--Compare Areas which player are in with Creative Area. Grant/revoke creative priv accordingly."
|
||||
for _, in_area in pairs(area_at_pos) do
|
||||
if in_area["pos1"] == areas.areas[areaID]["pos1"] --make sure the areas are not just the same name.
|
||||
and in_area["name"] == areas.areas[areaID]["name"] then
|
||||
status = true
|
||||
ID = tostring(areaID)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return status, ID
|
||||
end
|
||||
--------------------
|
||||
-- Chat Commands
|
||||
-------------------
|
||||
minetest.register_chatcommand("creative_area", {
|
||||
description = "Sets area to grant players creative priv while inside it",
|
||||
params = "<AreaID> <Privs>",
|
||||
privs = {privs = true},
|
||||
func = function(name, param)
|
||||
make_cr_area(name, param)
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("rm_creative_area", {
|
||||
description = "Revokes area from list of creative areas",
|
||||
params = "<AreaID>",
|
||||
privs = {privs = true},
|
||||
func = function(name, param)
|
||||
rm_cr_area(name, param)
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("ls_creative_areas", {
|
||||
description = "List creative areas and IDs",
|
||||
params = "",
|
||||
func = function(name, params)
|
||||
local list = ""
|
||||
if cr_areas ~= {} then
|
||||
for i = 1, #cr_areas do
|
||||
for k, v in pairs(cr_areas[i]) do
|
||||
if k == "id" then
|
||||
local id = tonumber(v)
|
||||
local area_name = areas.areas[id]["name"]
|
||||
list = list .. " " .. area_name .. " (ID="..id..")"
|
||||
end
|
||||
end
|
||||
minetest.chat_send_player(name, "Creative Area (ID): "..list)
|
||||
end
|
||||
else minetest.chat_send_player(name, "No creative areas found")
|
||||
end
|
||||
end
|
||||
})
|
||||
------------------------------------------------------------------------
|
||||
-- Store players default privs on joining first time incase spawning in creative area.
|
||||
------------------------------------------------------------------------
|
||||
local function store_privs(player)
|
||||
local status = check_cr_area(player)
|
||||
if status == false then
|
||||
pname = player:get_player_name()
|
||||
cr_areas[pname] = minetest.get_player_privs(pname)
|
||||
storage:set_string("cr_areas", minetest.serialize(cr_areas))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
minetest.register_on_newplayer(function(player)
|
||||
store_privs(player)
|
||||
end)
|
||||
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
local status = check_cr_area(player)
|
||||
if status == false then
|
||||
pname = player:get_player_name()
|
||||
cr_areas[pname] = nil
|
||||
storage:set_string("cr_areas", minetest.serialize(cr_areas))
|
||||
end
|
||||
end)
|
||||
-------------------------------------------------
|
||||
-- Check location and Grant/revoke indicated privs
|
||||
-------------------------------------------------
|
||||
local timer = 0
|
||||
minetest.register_globalstep(function(dtime)
|
||||
timer = timer + dtime
|
||||
if timer >= math.random(1,3) then
|
||||
for _, player in ipairs(minetest.get_connected_players()) do
|
||||
local pname = player:get_player_name()
|
||||
local privs = minetest.get_player_privs(pname)
|
||||
local inv = minetest.get_inventory({type="player", name=pname})
|
||||
if minetest.get_player_privs(pname).privs == nil then --Players with the "privs" priv will not have privileges effected.
|
||||
local status, id = check_cr_area(player)
|
||||
if status == true then
|
||||
if not cr_areas[pname] then
|
||||
store_privs(player)
|
||||
end
|
||||
for k, v in pairs(cr_areas[id]["privs"]) do
|
||||
if v == true then
|
||||
privs[k] = true
|
||||
end
|
||||
end
|
||||
minetest.set_player_privs(pname, privs)
|
||||
-- Reload inventory formspec
|
||||
if not minetest.get_modpath("unified_inventory") then
|
||||
local context = {page = sfinv.get_homepage_name(player)}--minetest.get_inventory{{type="detached", name="creative_"..pname}}--{page = sfinv.pages["creative_"..pname]}
|
||||
sfinv.set_player_inventory_formspec(player, context)
|
||||
end
|
||||
-- Store inventory for restoration after leaving creative area
|
||||
local invlist = inv:get_list("main")
|
||||
inv:set_list("saved", invlist)
|
||||
local list = ""
|
||||
for i = 1, #invlist do
|
||||
list = list .." "..dump(invlist[i])
|
||||
end
|
||||
--[[]if not minetest.check_player_privs(pname, {creative = true}) then
|
||||
privs.creative = true
|
||||
minetest.set_player_privs(pname, privs)
|
||||
if not minetest.get_modpath("unified_inventory") then
|
||||
local context = {page = sfinv.get_homepage_name(player)}--minetest.get_inventory{{type="detached", name="creative_"..pname}}--{page = sfinv.pages["creative_"..pname]}
|
||||
sfinv.set_player_inventory_formspec(player, context)
|
||||
end
|
||||
--unified_inventory.get_formspec(player, page)
|
||||
local invlist = inv:get_list("main")
|
||||
inv:set_list("saved", invlist)
|
||||
local list = ""
|
||||
for i = 1, #invlist do
|
||||
list = list .." "..dump(invlist[i])
|
||||
end
|
||||
--write_file(inv_file,)
|
||||
minetest.chat_send_player(pname, "You are in creative area.")
|
||||
|
||||
end]]--
|
||||
elseif status == false then
|
||||
if cr_areas[pname] then
|
||||
minetest.set_player_privs(pname, cr_areas[pname])
|
||||
end
|
||||
end
|
||||
|
||||
--[[] if minetest.check_player_privs(pname, {creative=true}) then
|
||||
privs.creative = nil
|
||||
minetest.set_player_privs(pname, privs)
|
||||
local saved = inv:get_list("saved")
|
||||
if saved ~= nil then
|
||||
inv:set_list("main", saved)
|
||||
end
|
||||
if not minetest.get_modpath("unified_inventory") then
|
||||
local context = {page = sfinv.get_homepage_name(player)}
|
||||
sfinv.set_player_inventory_formspec(player, context)
|
||||
end
|
||||
--unified_inventory.get_formspec(player, page)
|
||||
minetest.chat_send_player(pname, "You have left creative area.")
|
||||
]]--
|
||||
end
|
||||
end
|
||||
timer = 0
|
||||
end
|
||||
end)
|
||||
|
||||
----------------------------------
|
||||
--Formspec for SVINV
|
||||
----------------------------------
|
||||
|
||||
local function set_switches(area_id)
|
||||
local tbl = privtbl
|
||||
local id = tostring(area_id)
|
||||
local X, Y = 0.5, 5.5
|
||||
local j = 1
|
||||
local switches, state = "", ""
|
||||
local function form(t)
|
||||
local switches = ""
|
||||
for k, v in pairs(tbl) do
|
||||
local priv = k
|
||||
if v == true then
|
||||
state = "on"
|
||||
else state = "off"
|
||||
end
|
||||
switches = switches .. "label["..tostring(X)..","..tostring(Y-0.5)..";"..priv.."]"
|
||||
.."image_button["..tostring(X)..","..tostring(Y)..";0.8,0.5;switch_"..state..".png;"..priv..";]"
|
||||
if X < 5.75 then
|
||||
X=X+2
|
||||
else X = 0.5
|
||||
end
|
||||
if j == 4 or j == 8 then
|
||||
Y = Y + 1.25
|
||||
end
|
||||
if j < 12 then
|
||||
j = j+1
|
||||
elseif j >= 12 then break
|
||||
end
|
||||
end
|
||||
return switches
|
||||
end
|
||||
if id ~= 0 then
|
||||
if cr_areas[id] then
|
||||
tbl = cr_areas[id]["privs"]
|
||||
end
|
||||
end
|
||||
local switches = form(tbl)
|
||||
return switches
|
||||
end
|
||||
|
||||
local function toggle_switch(ID, priv)
|
||||
|
||||
end
|
||||
|
||||
sfinv.register_page("creative_areas:areas", {
|
||||
title = "Creative Areas",
|
||||
is_in_nav = function(self, player, context)
|
||||
local privs = minetest.get_player_privs(player:get_player_name())
|
||||
return privs.privs
|
||||
end,
|
||||
get = function(self, player, context)
|
||||
local status, areaid = check_cr_area(player)
|
||||
local privs = privtbl
|
||||
|
||||
local formspec = {
|
||||
"label[1.75,1;Add or Remove a Creative Area]"
|
||||
.."label[0.5,2;Area ID]"
|
||||
.."field[2.5,2;1,1;areaid;;"..areaid.."]"
|
||||
|
||||
.."label[0.5,4;Check privs to be granted in this area]"
|
||||
..set_switches(areaid)
|
||||
.."button[3.5,1.75;2,1;mkcrarea;Add]"
|
||||
.."button[5.5,1.75;2,1;rmcrarea;Remove]"
|
||||
}
|
||||
return sfinv.make_formspec(player, context, table.concat(formspec, ""), false)
|
||||
end,
|
||||
on_player_receive_fields = function(self, player, formname, fields)
|
||||
local tbl = {}
|
||||
if fields.rmcrarea and fields.areaid then
|
||||
return rm_cr_area(player:get_player_name(), fields.areaid)
|
||||
elseif fields.mkcrarea and fields.areaid then
|
||||
return make_cr_area(player:get_player_name(), fields.areaid)
|
||||
elseif fields.areaid then
|
||||
local id = fields.areaid
|
||||
if cr_areas[id] ~= nil then
|
||||
for k, v in pairs(cr_areas[id]["privs"]) do
|
||||
if fields[k] then
|
||||
minetest.chat_send_all(k)
|
||||
if v == false then
|
||||
cr_areas[id]["privs"][k] = true
|
||||
elseif v == true then
|
||||
cr_areas[id]["privs"][k] = false
|
||||
end
|
||||
storage:set_string("cr_areas", minetest.serialize(cr_areas))
|
||||
sfinv.set_player_inventory_formspec(player)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
BIN
textures/reload.png
Normal file
After Width: | Height: | Size: 278 B |
BIN
textures/switch_off.png
Normal file
After Width: | Height: | Size: 270 B |
BIN
textures/switch_on.png
Normal file
After Width: | Height: | Size: 278 B |