diff --git a/grenade.lua b/grenade.lua index 9b2b669..5dac7f8 100644 --- a/grenade.lua +++ b/grenade.lua @@ -25,7 +25,7 @@ minetest.register_entity("shooter:grenade_entity", { local below = {x=pos.x, y=pos.y - 1, z=pos.z} if minetest.get_node(below).name ~= "air" then self.object:remove() - shooter:blast(pos, 1, 25, 5) + shooter:blast(pos, 1, 25, 5, self.player) end self.timer = 0 end diff --git a/rocket.lua b/rocket.lua index cf1c867..165282d 100644 --- a/rocket.lua +++ b/rocket.lua @@ -30,7 +30,7 @@ minetest.register_entity("shooter:rocket_entity", { local pos = self.object:getpos() if minetest.get_node(pos).name ~= "air" then self.object:remove() - shooter:blast(pos, 2, 50, 7) + shooter:blast(pos, 2, 50, 7, self.player) end self.timer = 0 end diff --git a/shooter.conf.example b/shooter.conf.example index 954ccca..3c2ce1b 100644 --- a/shooter.conf.example +++ b/shooter.conf.example @@ -2,6 +2,9 @@ -- Global Constants (defaults) +-- Enable node destruction with explosives +SHOOTER_ENABLE_BLASTING = true + -- Enable basic guns (Pistol, Rifle, Shotgun, Machine Gun) SHOOTER_ENABLE_GUNS = true @@ -26,6 +29,10 @@ SHOOTER_ENABLE_CRAFTING = true -- Enable particle effects SHOOTER_ENABLE_PARTICLE_FX = true +-- Enable protection mod support, requires a protection mod that utilizes +-- minetest.is_protected(), tested with TenPlus1's version of [protector] +SHOOTER_ENABLE_PROTECTION = false + -- Particle texture used when a player or entity is hit SHOOTER_EXPLOSION_TEXTURE = "shooter_hit.png" diff --git a/shooter.lua b/shooter.lua index 1b437f9..05eef3c 100644 --- a/shooter.lua +++ b/shooter.lua @@ -7,6 +7,7 @@ shooter = { reload_time = 0, } +SHOOTER_ENABLE_BLASTING = true SHOOTER_ENABLE_GUNS = true SHOOTER_ENABLE_FLARES = true SHOOTER_ENABLE_HOOK = true @@ -15,6 +16,7 @@ SHOOTER_ENABLE_ROCKETS = true SHOOTER_ENABLE_TURRETS = true SHOOTER_ENABLE_CRAFTING = true SHOOTER_ENABLE_PARTICLE_FX = true +SHOOTER_ENABLE_PROTECTION = false SHOOTER_EXPLOSION_TEXTURE = "shooter_hit.png" SHOOTER_ALLOW_NODES = true SHOOTER_ALLOW_ENTITIES = false @@ -36,6 +38,7 @@ SHOOTER_ENTITIES = { } if minetest.is_singleplayer() == true then + SHOOTER_ENABLE_BLASTING = true SHOOTER_ALLOW_ENTITIES = true SHOOTER_ALLOW_PLAYERS = false end @@ -104,6 +107,12 @@ local function punch_node(pos, def) if not item then return end + if SHOOTER_ENABLE_PROTECTION then + if minetest.is_protected(pos, def.name) then + print(dump(def)) + return + end + end if item.groups then for k, v in pairs(def.groups) do local level = item.groups[k] or 0 @@ -338,13 +347,23 @@ function shooter:update_objects() end end -function shooter:blast(pos, radius, fleshy, distance) +function shooter:blast(pos, radius, fleshy, distance, user) + if not user then + return + end + local name = user:get_player_name() local pos = vector.round(pos) local p1 = vector.subtract(pos, radius) local p2 = vector.add(pos, radius) minetest.sound_play("tnt_explode", {pos=pos, gain=1}) if SHOOTER_ALLOW_NODES == true then - minetest.set_node(pos, {name="tnt:boom"}) + if SHOOTER_ENABLE_PROTECTION then + if not minetest.is_protected(pos, name) then + minetest.set_node(pos, {name="tnt:boom"}) + end + else + minetest.set_node(pos, {name="tnt:boom"}) + end end if SHOOTER_ENABLE_PARTICLE_FX == true then minetest.add_particlespawner(50, 0.1, @@ -373,30 +392,36 @@ function shooter:blast(pos, radius, fleshy, distance) end end end - if SHOOTER_ALLOW_NODES == false then - return - end - local pr = PseudoRandom(os.time()) - local vm = VoxelManip() - local min, max = vm:read_from_map(p1, p2) - local area = VoxelArea:new({MinEdge=min, MaxEdge=max}) - local data = vm:get_data() - local c_air = minetest.get_content_id("air") - for z = -radius, radius do - for y = -radius, radius do - local vi = area:index(pos.x - radius, pos.y + y, pos.z + z) - for x = -radius, radius do - if (x * x) + (y * y) + (z * z) <= - (radius * radius) + pr:next(-radius, radius) then - data[vi] = c_air + if SHOOTER_ALLOW_NODES and SHOOTER_ENABLE_BLASTING then + local pr = PseudoRandom(os.time()) + local vm = VoxelManip() + local min, max = vm:read_from_map(p1, p2) + local area = VoxelArea:new({MinEdge=min, MaxEdge=max}) + local data = vm:get_data() + local c_air = minetest.get_content_id("air") + for z = -radius, radius do + for y = -radius, radius do + local vp = {x=pos.x - radius, y=pos.y + y, z=pos.z + z} + local vi = area:index(vp.x, vp.y, vp.z) + for x = -radius, radius do + if (x * x) + (y * y) + (z * z) <= + (radius * radius) + pr:next(-radius, radius) then + if SHOOTER_ENABLE_PROTECTION then + if not minetest.is_protected(vp, name) then + data[vi] = c_air + end + else + data[vi] = c_air + end + end + vi = vi + 1 end - vi = vi + 1 end end + vm:set_data(data) + vm:update_liquids() + vm:write_to_map() + vm:update_map() end - vm:set_data(data) - vm:update_liquids() - vm:write_to_map() - vm:update_map() end diff --git a/turret.lua b/turret.lua index d8ce291..f56769d 100644 --- a/turret.lua +++ b/turret.lua @@ -43,7 +43,7 @@ minetest.register_entity("shooter:tnt_entity", { local pos = self.object:getpos() if minetest.get_node(pos).name ~= "air" then self.object:remove() - shooter:blast(pos, 4, 80, 10) + shooter:blast(pos, 4, 80, 10, self.player) end self.timer = 0 end @@ -172,10 +172,14 @@ minetest.register_entity("shooter:turret_entity", { pos = vector.add(pos, {x=dir.x * 1.5, y=dir.y * 1.5, z=dir.z * 1.5}) local obj = minetest.add_entity(pos, "shooter:tnt_entity") if obj then - minetest.sound_play("shooter_rocket_fire", {object=obj}) - obj:setyaw(self.yaw) - obj:setvelocity({x=dir.x * 20, y=dir.y * 20, z=dir.z * 20}) - obj:setacceleration({x=dir.x * -3, y=-10, z=dir.z * -3}) + local ent = obj:get_luaentity() + if ent then + minetest.sound_play("shooter_rocket_fire", {object=obj}) + ent.player = self.player + obj:setyaw(self.yaw) + obj:setvelocity({x=dir.x * 20, y=dir.y * 20, z=dir.z * 20}) + obj:setacceleration({x=dir.x * -3, y=-10, z=dir.z * -3}) + end end if SHOOTER_ENABLE_PARTICLE_FX == true then minetest.add_particlespawner(10, 0.1,