Drop a minetest.after

This commit is contained in:
Wuzzy 2019-08-24 18:58:20 +02:00
parent e3a6dac028
commit 76bd636df2
2 changed files with 28 additions and 31 deletions

View File

@ -40,40 +40,37 @@ else
end end
function tsm_pyramids.fill_chest(pos, stype, flood_sand) function tsm_pyramids.fill_chest(pos, stype, flood_sand)
minetest.after(2, function() local sand = "default:sand"
local sand = "default:sand" if stype == "desert_sandstone" or stype == "desert_stone" then
if stype == "desert_sandstone" or stype == "desert_stone" then sand = "default:desert_sand"
sand = "default:desert_sand" end
local n = minetest.get_node(pos)
if n and n.name and n.name == "default:chest" then
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
inv:set_size("main", 8*4)
local stacks = {}
-- Fill with sand in sand-flooded pyramids
if flood_sand then
table.insert(stacks, {name=sand, count = math.random(1,32)})
end end
local n = minetest.get_node(pos) -- Add treasures
if n and n.name and n.name == "default:chest" then if math.random(1,10) >= 7 then
local meta = minetest.get_meta(pos) if minetest.get_modpath("treasurer") ~= nil then
local inv = meta:get_inventory() stacks = treasurer.select_random_treasures(3,7,9,{"minetool", "food", "crafting_component"})
inv:set_size("main", 8*4) else
local stacks = {} for i=0,2,1 do
-- Fill with sand in sand-flooded pyramids local stuff = chest_stuff[math.random(1,#chest_stuff)]
if flood_sand then table.insert(stacks, {name=stuff.name, count = math.random(1,stuff.max)})
table.insert(stacks, {name=sand, count = math.random(1,32)})
end
-- Add treasures
if math.random(1,10) >= 7 then
if minetest.get_modpath("treasurer") ~= nil then
stacks = treasurer.select_random_treasures(3,7,9,{"minetool", "food", "crafting_component"})
else
for i=0,2,1 do
local stuff = chest_stuff[math.random(1,#chest_stuff)]
table.insert(stacks, {name=stuff.name, count = math.random(1,stuff.max)})
end
end end
end end
for s=1,#stacks do
if not inv:contains_item("main", stacks[s]) then
inv:set_stack("main", math.random(1,32), stacks[s])
end
end
end end
end) for s=1,#stacks do
if not inv:contains_item("main", stacks[s]) then
inv:set_stack("main", math.random(1,32), stacks[s])
end
end
end
end end
local function add_spawner(pos, mummy_offset) local function add_spawner(pos, mummy_offset)

View File

@ -54,7 +54,7 @@ local function hit(self)
self.object:set_properties(prop) self.object:set_properties(prop)
minetest.after(0.4, function(self) minetest.after(0.4, function(self)
local prop = {textures = mummy_texture,} local prop = {textures = mummy_texture,}
if self.object ~= nil then if self ~= nil and self.object ~= nil then
self.object:set_properties(prop) self.object:set_properties(prop)
end end
end, self) end, self)