Add basic protection support
This commit is contained in:
parent
c8dd9aa002
commit
4b34151f1d
5 changed files with 66 additions and 30 deletions
|
@ -25,7 +25,7 @@ minetest.register_entity("shooter:grenade_entity", {
|
||||||
local below = {x=pos.x, y=pos.y - 1, z=pos.z}
|
local below = {x=pos.x, y=pos.y - 1, z=pos.z}
|
||||||
if minetest.get_node(below).name ~= "air" then
|
if minetest.get_node(below).name ~= "air" then
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
shooter:blast(pos, 1, 25, 5)
|
shooter:blast(pos, 1, 25, 5, self.player)
|
||||||
end
|
end
|
||||||
self.timer = 0
|
self.timer = 0
|
||||||
end
|
end
|
||||||
|
|
|
@ -30,7 +30,7 @@ minetest.register_entity("shooter:rocket_entity", {
|
||||||
local pos = self.object:getpos()
|
local pos = self.object:getpos()
|
||||||
if minetest.get_node(pos).name ~= "air" then
|
if minetest.get_node(pos).name ~= "air" then
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
shooter:blast(pos, 2, 50, 7)
|
shooter:blast(pos, 2, 50, 7, self.player)
|
||||||
end
|
end
|
||||||
self.timer = 0
|
self.timer = 0
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
-- Global Constants (defaults)
|
-- Global Constants (defaults)
|
||||||
|
|
||||||
|
-- Enable node destruction with explosives
|
||||||
|
SHOOTER_ENABLE_BLASTING = true
|
||||||
|
|
||||||
-- Enable basic guns (Pistol, Rifle, Shotgun, Machine Gun)
|
-- Enable basic guns (Pistol, Rifle, Shotgun, Machine Gun)
|
||||||
SHOOTER_ENABLE_GUNS = true
|
SHOOTER_ENABLE_GUNS = true
|
||||||
|
|
||||||
|
@ -26,6 +29,10 @@ SHOOTER_ENABLE_CRAFTING = true
|
||||||
-- Enable particle effects
|
-- Enable particle effects
|
||||||
SHOOTER_ENABLE_PARTICLE_FX = true
|
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
|
-- Particle texture used when a player or entity is hit
|
||||||
SHOOTER_EXPLOSION_TEXTURE = "shooter_hit.png"
|
SHOOTER_EXPLOSION_TEXTURE = "shooter_hit.png"
|
||||||
|
|
||||||
|
|
71
shooter.lua
71
shooter.lua
|
@ -7,6 +7,7 @@ shooter = {
|
||||||
reload_time = 0,
|
reload_time = 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SHOOTER_ENABLE_BLASTING = true
|
||||||
SHOOTER_ENABLE_GUNS = true
|
SHOOTER_ENABLE_GUNS = true
|
||||||
SHOOTER_ENABLE_FLARES = true
|
SHOOTER_ENABLE_FLARES = true
|
||||||
SHOOTER_ENABLE_HOOK = true
|
SHOOTER_ENABLE_HOOK = true
|
||||||
|
@ -15,6 +16,7 @@ SHOOTER_ENABLE_ROCKETS = true
|
||||||
SHOOTER_ENABLE_TURRETS = true
|
SHOOTER_ENABLE_TURRETS = true
|
||||||
SHOOTER_ENABLE_CRAFTING = true
|
SHOOTER_ENABLE_CRAFTING = true
|
||||||
SHOOTER_ENABLE_PARTICLE_FX = true
|
SHOOTER_ENABLE_PARTICLE_FX = true
|
||||||
|
SHOOTER_ENABLE_PROTECTION = false
|
||||||
SHOOTER_EXPLOSION_TEXTURE = "shooter_hit.png"
|
SHOOTER_EXPLOSION_TEXTURE = "shooter_hit.png"
|
||||||
SHOOTER_ALLOW_NODES = true
|
SHOOTER_ALLOW_NODES = true
|
||||||
SHOOTER_ALLOW_ENTITIES = false
|
SHOOTER_ALLOW_ENTITIES = false
|
||||||
|
@ -36,6 +38,7 @@ SHOOTER_ENTITIES = {
|
||||||
}
|
}
|
||||||
|
|
||||||
if minetest.is_singleplayer() == true then
|
if minetest.is_singleplayer() == true then
|
||||||
|
SHOOTER_ENABLE_BLASTING = true
|
||||||
SHOOTER_ALLOW_ENTITIES = true
|
SHOOTER_ALLOW_ENTITIES = true
|
||||||
SHOOTER_ALLOW_PLAYERS = false
|
SHOOTER_ALLOW_PLAYERS = false
|
||||||
end
|
end
|
||||||
|
@ -104,6 +107,12 @@ local function punch_node(pos, def)
|
||||||
if not item then
|
if not item then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
if SHOOTER_ENABLE_PROTECTION then
|
||||||
|
if minetest.is_protected(pos, def.name) then
|
||||||
|
print(dump(def))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
if item.groups then
|
if item.groups then
|
||||||
for k, v in pairs(def.groups) do
|
for k, v in pairs(def.groups) do
|
||||||
local level = item.groups[k] or 0
|
local level = item.groups[k] or 0
|
||||||
|
@ -338,13 +347,23 @@ function shooter:update_objects()
|
||||||
end
|
end
|
||||||
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 pos = vector.round(pos)
|
||||||
local p1 = vector.subtract(pos, radius)
|
local p1 = vector.subtract(pos, radius)
|
||||||
local p2 = vector.add(pos, radius)
|
local p2 = vector.add(pos, radius)
|
||||||
minetest.sound_play("tnt_explode", {pos=pos, gain=1})
|
minetest.sound_play("tnt_explode", {pos=pos, gain=1})
|
||||||
if SHOOTER_ALLOW_NODES == true then
|
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
|
end
|
||||||
if SHOOTER_ENABLE_PARTICLE_FX == true then
|
if SHOOTER_ENABLE_PARTICLE_FX == true then
|
||||||
minetest.add_particlespawner(50, 0.1,
|
minetest.add_particlespawner(50, 0.1,
|
||||||
|
@ -373,30 +392,36 @@ function shooter:blast(pos, radius, fleshy, distance)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if SHOOTER_ALLOW_NODES == false then
|
if SHOOTER_ALLOW_NODES and SHOOTER_ENABLE_BLASTING then
|
||||||
return
|
local pr = PseudoRandom(os.time())
|
||||||
end
|
local vm = VoxelManip()
|
||||||
local pr = PseudoRandom(os.time())
|
local min, max = vm:read_from_map(p1, p2)
|
||||||
local vm = VoxelManip()
|
local area = VoxelArea:new({MinEdge=min, MaxEdge=max})
|
||||||
local min, max = vm:read_from_map(p1, p2)
|
local data = vm:get_data()
|
||||||
local area = VoxelArea:new({MinEdge=min, MaxEdge=max})
|
local c_air = minetest.get_content_id("air")
|
||||||
local data = vm:get_data()
|
for z = -radius, radius do
|
||||||
local c_air = minetest.get_content_id("air")
|
for y = -radius, radius do
|
||||||
for z = -radius, radius do
|
local vp = {x=pos.x - radius, y=pos.y + y, z=pos.z + z}
|
||||||
for y = -radius, radius do
|
local vi = area:index(vp.x, vp.y, vp.z)
|
||||||
local vi = area:index(pos.x - radius, pos.y + y, pos.z + z)
|
for x = -radius, radius do
|
||||||
for x = -radius, radius do
|
if (x * x) + (y * y) + (z * z) <=
|
||||||
if (x * x) + (y * y) + (z * z) <=
|
(radius * radius) + pr:next(-radius, radius) then
|
||||||
(radius * radius) + pr:next(-radius, radius) then
|
if SHOOTER_ENABLE_PROTECTION then
|
||||||
data[vi] = c_air
|
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
|
||||||
vi = vi + 1
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
vm:set_data(data)
|
||||||
|
vm:update_liquids()
|
||||||
|
vm:write_to_map()
|
||||||
|
vm:update_map()
|
||||||
end
|
end
|
||||||
vm:set_data(data)
|
|
||||||
vm:update_liquids()
|
|
||||||
vm:write_to_map()
|
|
||||||
vm:update_map()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
14
turret.lua
14
turret.lua
|
@ -43,7 +43,7 @@ minetest.register_entity("shooter:tnt_entity", {
|
||||||
local pos = self.object:getpos()
|
local pos = self.object:getpos()
|
||||||
if minetest.get_node(pos).name ~= "air" then
|
if minetest.get_node(pos).name ~= "air" then
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
shooter:blast(pos, 4, 80, 10)
|
shooter:blast(pos, 4, 80, 10, self.player)
|
||||||
end
|
end
|
||||||
self.timer = 0
|
self.timer = 0
|
||||||
end
|
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})
|
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")
|
local obj = minetest.add_entity(pos, "shooter:tnt_entity")
|
||||||
if obj then
|
if obj then
|
||||||
minetest.sound_play("shooter_rocket_fire", {object=obj})
|
local ent = obj:get_luaentity()
|
||||||
obj:setyaw(self.yaw)
|
if ent then
|
||||||
obj:setvelocity({x=dir.x * 20, y=dir.y * 20, z=dir.z * 20})
|
minetest.sound_play("shooter_rocket_fire", {object=obj})
|
||||||
obj:setacceleration({x=dir.x * -3, y=-10, z=dir.z * -3})
|
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
|
end
|
||||||
if SHOOTER_ENABLE_PARTICLE_FX == true then
|
if SHOOTER_ENABLE_PARTICLE_FX == true then
|
||||||
minetest.add_particlespawner(10, 0.1,
|
minetest.add_particlespawner(10, 0.1,
|
||||||
|
|
Loading…
Reference in a new issue