Changed random selecting to simple 'all dropped' behavior

- '?' nodes now drop eveything they have
This commit is contained in:
LeMagnesium 2015-04-22 14:14:35 +02:00
parent c668e9f1d8
commit e0febced46
1 changed files with 50 additions and 26 deletions

View File

@ -18,31 +18,55 @@ minetest.register_node("eventobjects:surprise_node", {
tiles = {"eventobjects_surprise_node.png"},
inventory_image = "eventobjects_surprise_node.png",
wield_image = "eventobjects_surprise_node.png",
})
minetest.after(1,function()
minetest.override_item("eventobjects:surprise_node", {
on_punch = function(pos, node, puncher, pointed_things)
-- Spawn betweek 5 and 20 random nodes
for cnt = 1,math.random(5,20) do
local item = ""
local random_num = math.random(1,#minetest.registered_items)+math.random(-cnt,cnt)
if random_num <= 0 then random_num = 1 end
local random_count = 1
for key, value in pairs(minetest.registered_items) do
if random_count == random_num then
item = key
break
end
random_count = random_count + 1
groups = {oddly_breakable_by_hand = 2},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
meta:set_string("infotext","?")
meta:set_string("formspec",
"size[11,12]" ..
"list[current_name;main;0.45,0.45;10,7;]" ..
"list[current_player;main;1.45,8;8,4;]"
)
inv:set_size("main",70)
end,
allow_metadata_inventory_put = function(pos, to_list, to_index, stack, player)
if player and minetest.check_player_privs(player:get_player_name(),{server=true}) then
return stack:get_count()
else
return 0
end
end,
allow_metadata_inventory_take = function(pos, from_list, from_index, stack, player)
print(from_list)
print(from_index)
if player and minetest.check_player_privs(player:get_player_name(),{server=true}) then
return stack:get_count()
else
return 0
end
end,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
end,
on_punch = function(pos, node, puncher, pointed_things)
-- Spawn betweek 5 and 20 random nodes
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if inv:is_empty("main") then
minetest.chat_send_player(puncher:get_player_name(),"Cannot spread items, inventory empty")
return
end
for cnt = 1,70 do
local stack = inv:get_stack("main",cnt)
if stack:get_name() ~= "" then
local obj = minetest.spawn_item({x=pos.x, y = pos.y + 1,z=pos.z},stack)
inv:remove_item("main",stack)
if obj then
obj:setvelocity({x = math.random(-0.4,0.4), y = math.random(2,9), z = math.random(-0.4,0.4)})
end
print(table.getn(minetest.registered_items))
local s_count = math.random(1,minetest.registered_items[item].max_count or 99)
local obj = minetest.spawn_item({x=pos.x, y = pos.y + 1,z=pos.z},{name = item, count = s_count})
if not obj then return end
obj:setvelocity({x = 0, y = math.random(2,9), z = 0})
end
minetest.remove_node(pos)
end,
})
end)
end
minetest.remove_node(pos)
end,
})