summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcheapie <no-email-for-you@example.com>2017-04-02 16:41:11 -0500
committercheapie <no-email-for-you@example.com>2017-04-02 16:41:11 -0500
commit7316ba0bf8759d218ff33fa6e367ec33a2fabe22 (patch)
tree22904d9d8f9b6d1ab8973fc280f689567166403f
downloadareasprotector-7316ba0bf8759d218ff33fa6e367ec33a2fabe22.tar
areasprotector-7316ba0bf8759d218ff33fa6e367ec33a2fabe22.tar.gz
areasprotector-7316ba0bf8759d218ff33fa6e367ec33a2fabe22.tar.bz2
areasprotector-7316ba0bf8759d218ff33fa6e367ec33a2fabe22.tar.xz
areasprotector-7316ba0bf8759d218ff33fa6e367ec33a2fabe22.zip
Import existing content
-rw-r--r--depends.txt1
-rw-r--r--init.lua58
-rw-r--r--textures/areasprotector_protector.pngbin0 -> 274 bytes
3 files changed, 59 insertions, 0 deletions
diff --git a/depends.txt b/depends.txt
new file mode 100644
index 0000000..a18cd91
--- /dev/null
+++ b/depends.txt
@@ -0,0 +1 @@
+areas
diff --git a/init.lua b/init.lua
new file mode 100644
index 0000000..a2d00fa
--- /dev/null
+++ b/init.lua
@@ -0,0 +1,58 @@
+local function cyan(str)
+ return minetest.colorize("#00FFFF",str)
+end
+
+local function red(str)
+ return minetest.colorize("#FF5555",str)
+end
+
+minetest.register_node("areasprotector:protector",{
+ description = "Protector Block",
+ groups = {cracky=1},
+ tiles = {
+ "default_steel_block.png",
+ "default_steel_block.png",
+ "default_steel_block.png^areasprotector_protector.png"
+ },
+ on_place = function(itemstack,player,pointed)
+ local radius = minetest.setting_get("areasprotector_radius") or 8
+ local pos = pointed.above
+ local pos1 = vector.add(pos,vector.new(radius,radius,radius))
+ local pos2 = vector.add(pos,vector.new(-1*radius,-1*radius,-1*radius))
+ local name = player:get_player_name()
+ local perm,err = areas:canPlayerAddArea(pos1,pos2,name)
+ if not perm then
+ minetest.chat_send_player(name,red("You are not allowed to protect that area: ")..err)
+ return itemstack
+ end
+ local id = areas:add(name,"Protected by Protector Block",pos1,pos2)
+ areas:save()
+ local msg = string.format("The area from %s to %s has been protected as #%s",cyan(minetest.pos_to_string(pos1)),cyan(minetest.pos_to_string(pos2)),cyan(id))
+ minetest.chat_send_player(name,msg)
+ minetest.set_node(pos,{name="areasprotector:protector"})
+ local meta = minetest.get_meta(pos)
+ local infotext = string.format("Protecting area %d owned by %s",id,name)
+ meta:set_string("infotext",infotext)
+ meta:set_int("area_id",id)
+ meta:set_string("owner",name)
+ if not minetest.setting_getbool("creative_mode") then
+ itemstack:take_item()
+ end
+ return itemstack
+ end,
+ on_destruct = function(pos)
+ local meta = minetest.get_meta(pos)
+ local owner = meta:get_string("owner")
+ local id = meta:get_int("area_id")
+ if areas.areas[id] and areas:isAreaOwner(id,owner) then
+ areas:remove(id)
+ areas:save()
+ end
+ end,
+})
+
+minetest.register_craft({
+ output = "areasprotector:protector",
+ type = "shapeless",
+ recipe = {"default:steelblock","default:steel_ingot"},
+})
diff --git a/textures/areasprotector_protector.png b/textures/areasprotector_protector.png
new file mode 100644
index 0000000..1351832
--- /dev/null
+++ b/textures/areasprotector_protector.png
Binary files differ