Use forked version of creative_areas to manage privs

This commit is contained in:
xisd 2020-08-14 15:15:40 +02:00
parent c978f07470
commit eb87009df8
35 changed files with 126 additions and 72 deletions

0
README.txt Normal file → Executable file
View File

2
beamgen.lua Normal file → Executable file
View File

@ -35,7 +35,7 @@ for _,color in ipairs(colors) do
--
-- Start timer if action on timer defined
--
if color == 'green' or color == 'red' then
if color == 'red' then
-- Start timer
local timer = minetest.get_node_timer(pos)
if not timer:is_started() then timer:start(timer_timeout) end

0
beaminit.lua Normal file → Executable file
View File

0
config.lua Normal file → Executable file
View File

0
crafts.lua Normal file → Executable file
View File

0
depends.txt Normal file → Executable file
View File

191
effects.lua Normal file → Executable file
View File

@ -4,13 +4,13 @@ local S = beacon.intllib
local timer_timeout = beacon.config.timer_timeout
local effects_radius = beacon.config.effects_radius
local msg_prefix = beacon.config.msg_prefix
local blue_field = beacon.config.blue_field
local blue_field = beacon.config.blue_field or false
local beacon_distance_check = beacon.config.beacon_distance_check
beacon.allow_fly = function(player)
return player:get_attribute("_beacon_green_fly")
end
-- beacon.allow_fly = function(player)
-- return player:get_attribute("_beacon_green_fly")
-- end
--
-- Blue Field node
@ -155,58 +155,32 @@ function remove_force_field(r, field_node)
end --]]
end
--
-- Special effects
--
--
-- Red Beacon : Regenerates health
--
beacon.effects.red = {}
beacon.effects.red.on_timer = function(pos, elapsed)
local players = get_players_inside_radius(pos, effects_radius)
for _,player in ipairs(players) do
local hp = player:get_hp()
local hp_max = 20 -- FIXME : get hp_max from player properties
if hp < hp_max then player:set_hp(hp+(0.5*2)) end
end
function init_area(pos, player, color, field_node, effect_radius)
-- Restart timer
local timer = minetest.get_node_timer(pos)
timer:start(timer_timeout)
end
--
-- TODO Purple Beacon : Double tools strength and regen
--
beacon.effects.purple = {}
beacon.effects.purple.on_timer = function(pos, elapsed)
return
end
--
-- Blue Beacon : Protect the area and draw blue field around
--
beacon.effects.blue = {}
beacon.effects.blue.after_place_node = function(pos, placer, itemstack, pointed_thing)
if not effect_radius then effect_radius = effects_radius end
-- Return if placing inside the radius of another beacon
if beacon_distance_check and beacon.is_near(pos) then return end
-- Set placer as meta
local meta = minetest.get_meta(pos)
local name = placer:get_player_name()
local name = player:get_player_name()
meta:set_string('placer', name)
meta:set_string('color', color)
meta:set_string('field_node', field_node)
meta:set_string('effect_radius', effect_radius)
-- Limits of radius
local xr = {}
xr.min = pos.x - effects_radius
xr.max = pos.x + effects_radius
xr.min = pos.x - effect_radius
xr.max = pos.x + effect_radius
local yr = {}
yr.min = pos.y - effects_radius
yr.max = pos.y + effects_radius
yr.min = pos.y - effect_radius
yr.max = pos.y + effect_radius
local zr = {}
zr.min = pos.z - effects_radius
zr.max = pos.z + effects_radius
zr.min = pos.z - effect_radius
zr.max = pos.z + effect_radius
--
-- Prevent areas intersection
@ -221,15 +195,15 @@ beacon.effects.blue.after_place_node = function(pos, placer, itemstack, pointed_
local intersect = areas:getAreasIntersectingArea(pos_min, pos_max)
-- Loop throug table element
for area in pairs(intersect) do
-- TODO : use a more subtle approch
conflict = true
break
end
end
-- TODO : Detect conflict if area is not used
-- TODO: Detect conflict if area is not used
-- (or if no protection because no areas priv)
-- TODO: maybe use a more subtle approch
if conflict then
local meta = minetest.get_meta(pos)
@ -238,20 +212,19 @@ beacon.effects.blue.after_place_node = function(pos, placer, itemstack, pointed_
return
end
--
-- Draw a blue field around
-- Draw a field around
--
local radius_table = {x=xr,y=yr,z=zr}
if blue_field then
local node = "beacon:bluefield"
if blue_field_solid then node = "beacon:bluefield_solid" end
if field_node then
draw_force_field(radius_table, node)
end
end
--
-- Protect the area
--
local area_id
if minetest.get_modpath('areas') then
local area_name = "Blue beacon at "..pos.x.." "..pos.y.." "..pos.z
local area_name = color.. " beacon at "..pos.x.." "..pos.y.." "..pos.z
local p1 = { x = xr.max, y = yr.max, z = zr.max }
local p2 = { x = xr.min, y = yr.min, z = zr.min }
@ -260,10 +233,10 @@ beacon.effects.blue.after_place_node = function(pos, placer, itemstack, pointed_
minetest.chat_send_player(name, msg_prefix.."You can't protect that area: "..errMsg)
else
p1, p2 = areas:sortPos( p1, p2 );
local id = areas:add(name, area_name, p1, p2, nil)
area_id = areas:add(name, area_name, p1, p2, nil)
areas:save()
minetest.chat_send_player(name, msg_prefix.."Your blue beacon is protecting the surrounding area.")
meta:set_int("area_id", id)
minetest.chat_send_player(name, msg_prefix.."Your ".. color .." beacon is affecting the surrounding area.")
meta:set_int("area_id", area_id)
end
end
@ -271,51 +244,106 @@ beacon.effects.blue.after_place_node = function(pos, placer, itemstack, pointed_
-- Mark as active
meta:set_string('active','yes')
return area_id
end
beacon.effects.blue.on_destruct = function(pos)
function remove_area(pos, color, field_node, effect_radius)
local meta = minetest.get_meta(pos)
if not name then name = meta:get_string('placer') end
if not color then color = meta:get_string('color') end
if not field_node then field_node = meta:get_string('field_node') end
if not effect_radius then effect_radius = meta:get_string('effect_radius') or effect_radius end
--
-- Unprotect the area
--
if minetest.get_modpath('areas') then
local meta = minetest.get_meta(pos)
-- local name = meta:get_string('placer')
local id = meta:get_int("area_id")
if id and id ~= 0 then
if minetest.get_modpath('creative_areas') then
creative_areas.remove(name, id)
end
areas:remove(id)
areas:save()
minetest.chat_send_all(msg_prefix.."Removed area "..id)
if name then minetest.chat_send_player(name, msg_prefix.."Removed area "..id) end
end
end
--
-- Remove the blue field
--
if blue_field then
if field_node then
-- Limits of radius
local xr = {}
xr.min = pos.x - effects_radius
xr.max = pos.x + effects_radius
xr.min = pos.x - effect_radius
xr.max = pos.x + effect_radius
local yr = {}
yr.min = pos.y - effects_radius
yr.max = pos.y + effects_radius
yr.min = pos.y - effect_radius
yr.max = pos.y + effect_radius
local zr = {}
zr.min = pos.z - effects_radius
zr.max = pos.z + effects_radius
zr.min = pos.z - effect_radius
zr.max = pos.z + effect_radius
local radius_table = {x=xr,y=yr,z=zr}
-- Remove field
remove_force_field(radius_table, "beacon:bluefield")
remove_force_field(radius_table, field_node)
end
end
--
-- Special effects
--
--
-- Red Beacon : Regenerates health
--
beacon.effects.red = {}
beacon.effects.red.on_timer = function(pos, elapsed)
local players = get_players_inside_radius(pos, effects_radius)
for _,player in ipairs(players) do
local hp = player:get_hp()
local hp_max = 20 -- FIXME: get hp_max from player properties
if hp < hp_max then player:set_hp(hp+(0.5*2)) end
end
-- Restart timer
local timer = minetest.get_node_timer(pos)
timer:start(timer_timeout)
end
--
-- TODO: Purple Beacon : Double tools strength and regen
--
beacon.effects.purple = {}
beacon.effects.purple.on_timer = function(pos, elapsed)
return
end
--
-- Blue Beacon : Protect the area and draw blue field around
--
beacon.effects.blue = {}
beacon.effects.blue.after_place_node = function(pos, placer, itemstack, pointed_thing)
local field_node = nil
if blue_field then
local field_node = "beacon:bluefield"
if blue_field_solid then field_node = "beacon:bluefield_solid" end
end
area_id = init_area(pos, placer, "blue", field_node, effect_radius)
end
beacon.effects.blue.on_destruct = function(pos)
remove_area(pos)
--
-- Rest of on_destruct function common with other beacons
--
beacon.on_destruct(pos)
end
beacon.effects.blue.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
local player_name = clicker:get_player_name()
@ -396,10 +424,35 @@ end
-- Green Beacon : Allow flying in the area
--
beacon.effects.green = {}
beacon.effects.green.after_place_node = function(pos, placer, itemstack, pointed_thing)
local field_node = nil
-- if green_field then
-- local field_node = "beacon:greenfield"
-- if green_field_solid then field_node = "beacon:greenfield_solid" end
-- end
area_id = init_area(pos, placer, "green", field_node, effect_radius)
if area_id and minetest.get_modpath('creative_areas') then
local name = placer:get_player_name()
creative_areas.add(name, area_id, {["interact"] = true, ["fly"] = true })
end
end
beacon.effects.green.on_destruct = function(pos)
remove_area(pos)
--
-- Rest of on_destruct function common with other beacons
--
beacon.on_destruct(pos)
end
-- Use globalstep instead of node timer for green beacon
-- beacause node can be in an unloaded area
--
-- Old globalstep, now using creative area mod
--[[
local timer = 0
minetest.register_globalstep(function(dtime)
-- Update timer
@ -460,4 +513,4 @@ minetest.register_globalstep(function(dtime)
end
end)
]]--

0
force_field.lua Normal file → Executable file
View File

5
init.lua Normal file → Executable file
View File

@ -69,10 +69,11 @@ minetest.register_node("beacon:green", {
groups = {cracky=3,oddly_breakable_by_hand=3},
drop = "beacon:green",
-- on_place = beacon.on_place,
-- on_timer = beacon.effects.green.on_timer,
on_construct = beacon.on_construct.green,
on_destruct = beacon.on_destruct,
-- on_rightclick = beacon.effects.green.on_rightclick,
on_destruct = beacon.effects.green.on_destruct,
after_place_node = beacon.effects.green.after_place_node,
on_timer = beacon.effects.green.on_timer,
})
--code for "Main purple source cube"

0
intllib.lua Normal file → Executable file
View File

0
original/beacon_master.zip Normal file → Executable file
View File

0
textures/BlueBeacon.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

0
textures/GreenBeacon.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

0
textures/RedBeacon.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

0
textures/Thumbs.db Normal file → Executable file
View File

0
textures/UnactivatedBeacon.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

0
textures/VioletBeacon.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

0
textures/bluebase.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 650 B

After

Width:  |  Height:  |  Size: 650 B

0
textures/bluebeacon.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 628 B

After

Width:  |  Height:  |  Size: 628 B

0
textures/bluebeam.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 233 B

After

Width:  |  Height:  |  Size: 233 B

0
textures/bluefield.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 157 B

After

Width:  |  Height:  |  Size: 157 B

0
textures/blueparticle.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 225 B

After

Width:  |  Height:  |  Size: 225 B

0
textures/emptybeacon.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 551 B

After

Width:  |  Height:  |  Size: 551 B

0
textures/greenbase.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 475 B

After

Width:  |  Height:  |  Size: 475 B

0
textures/greenbeacon.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 615 B

After

Width:  |  Height:  |  Size: 615 B

0
textures/greenbeam.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 208 B

After

Width:  |  Height:  |  Size: 208 B

0
textures/greenparticle.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 213 B

After

Width:  |  Height:  |  Size: 213 B

0
textures/purplebase.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 453 B

After

Width:  |  Height:  |  Size: 453 B

0
textures/purplebeacon.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 599 B

After

Width:  |  Height:  |  Size: 599 B

0
textures/purplebeam.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 208 B

After

Width:  |  Height:  |  Size: 208 B

0
textures/purpleparticle.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 218 B

After

Width:  |  Height:  |  Size: 218 B

0
textures/redbase.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 450 B

After

Width:  |  Height:  |  Size: 450 B

0
textures/redbeacon.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 590 B

After

Width:  |  Height:  |  Size: 590 B

0
textures/redbeam.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 205 B

After

Width:  |  Height:  |  Size: 205 B

0
textures/redparticle.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 217 B

After

Width:  |  Height:  |  Size: 217 B