Add basic protection support

This commit is contained in:
stujones11 2014-10-01 20:43:33 +01:00
parent c8dd9aa002
commit 4b34151f1d
5 changed files with 66 additions and 30 deletions

View file

@ -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

View file

@ -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

View file

@ -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"

View file

@ -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,14 +347,24 @@ 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
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,
p1, p2, {x=-0, y=-0, z=-0}, {x=0, y=0, z=0},
@ -373,9 +392,7 @@ function shooter:blast(pos, radius, fleshy, distance)
end
end
end
if SHOOTER_ALLOW_NODES == false then
return
end
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)
@ -384,12 +401,19 @@ function shooter:blast(pos, radius, fleshy, distance)
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)
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
end
@ -399,4 +423,5 @@ function shooter:blast(pos, radius, fleshy, distance)
vm:write_to_map()
vm:update_map()
end
end

View file

@ -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,11 +172,15 @@ 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
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,
{x=pos.x - 1, y=pos.y - 1, z=pos.z - 1},