Add shorter countdown for explosives ignited by other explosives
This commit is contained in:
parent
ee351c385c
commit
25b7992ae0
2
api.lua
2
api.lua
@ -58,7 +58,7 @@ function nuke:register_nuke(name, description, radius, tiles)
|
||||
visual = "cube",
|
||||
groups = entity_groups,
|
||||
health = 10,
|
||||
timer = 1,
|
||||
timer = 10,
|
||||
blinktimer = 0,
|
||||
blinkstatus = true,
|
||||
on_activate = e.on_activate,
|
||||
|
32
entity.lua
32
entity.lua
@ -1,5 +1,13 @@
|
||||
nuke.entity = {}
|
||||
|
||||
local function remove_smoke(e)
|
||||
if e.smoke_spawner then
|
||||
minetest.delete_particlespawner(e.smoke_spawner)
|
||||
end
|
||||
-- For add_particlespawner hack to detect if we've been removed
|
||||
e.smoke_spawner = nil
|
||||
end
|
||||
|
||||
function nuke.entity:on_activate(staticdata)
|
||||
if static_data and static_data ~= "" then
|
||||
for k, v in pairs(minetest.deserialize(static_data)) do
|
||||
@ -24,9 +32,10 @@ function nuke.entity:on_activate(staticdata)
|
||||
-- use minetest.after to call it later.
|
||||
minetest.after(0, function()
|
||||
if self.smoke_spawner == false then
|
||||
local time = self.timer
|
||||
self.smoke_spawner = minetest.add_particlespawner({
|
||||
amount = 512,
|
||||
time = 10,
|
||||
amount = 50 * time,
|
||||
time = time,
|
||||
minpos = min_pos,
|
||||
maxpos = max_pos,
|
||||
minvel = {x=-1, y=1, z=-1},
|
||||
@ -47,35 +56,28 @@ end
|
||||
|
||||
function nuke.entity:on_step(dtime)
|
||||
local o = self.object
|
||||
self.timer = self.timer + dtime
|
||||
self.blinktimer = self.blinktimer + (dtime * self.timer)
|
||||
self.timer = self.timer - dtime
|
||||
self.blinktimer = self.blinktimer + ((5 * dtime) / self.timer)
|
||||
if self.blinktimer > 1 then
|
||||
self.blinktimer = self.blinktimer - 1
|
||||
o:settexturemod(self.blinkstatus and "" or "^[brighten")
|
||||
self.blinkstatus = not self.blinkstatus
|
||||
end
|
||||
|
||||
if self.timer > 10 then
|
||||
if self.timer <= 0 then
|
||||
nuke:detonate(self, self.radius)
|
||||
remove_smoke(self)
|
||||
end
|
||||
end
|
||||
|
||||
function nuke.entity:on_punch(hitter)
|
||||
self.object:remove()
|
||||
remove_smoke(self)
|
||||
hitter:get_inventory():add_item("main", self.name)
|
||||
if self.smoke_spawner then
|
||||
minetest.delete_particlespawner(self.smoke_spawner)
|
||||
end
|
||||
-- For add_particlespawner hack to detect if we've been removed
|
||||
self.smoke_spawner = nil
|
||||
end
|
||||
|
||||
function nuke.entity:get_staticdata()
|
||||
if self.smoke_spawner then
|
||||
minetest.delete_particlespawner(self.smoke_spawner)
|
||||
end
|
||||
-- For add_particlespawner hack to detect if we've been removed
|
||||
self.smoke_spawner = nil
|
||||
remove_smoke(self)
|
||||
return minetest.serialize({
|
||||
player_name = self.player_name,
|
||||
})
|
||||
|
@ -10,13 +10,16 @@ function nuke:can_detonate(player_name)
|
||||
end
|
||||
|
||||
|
||||
function nuke:ignite(pos, node_name, player_name)
|
||||
function nuke:ignite(pos, node_name, player_name, time)
|
||||
minetest.dig_node(pos)
|
||||
minetest.sound_play("nuke_ignite",
|
||||
{pos = pos, gain = 1.0, max_hear_distance = 10})
|
||||
local o = minetest.add_entity(pos, node_name)
|
||||
local e = o:get_luaentity()
|
||||
e.player_name = player_name
|
||||
if time then
|
||||
e.timer = time
|
||||
end
|
||||
return o
|
||||
end
|
||||
|
||||
@ -149,7 +152,7 @@ function nuke:explode(pos, radius, player_name)
|
||||
p.x = pos.x + x
|
||||
p.y = pos.y + y
|
||||
p.z = pos.z + z
|
||||
self:ignite(p, name, player_name)
|
||||
self:ignite(p, name, player_name, 1)
|
||||
end
|
||||
data[vi] = c_air
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user