mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2025-01-11 18:40:25 +01:00
Changed random selecting to simple 'all dropped' behavior
- '?' nodes now drop eveything they have
This commit is contained in:
parent
c668e9f1d8
commit
e0febced46
@ -18,31 +18,55 @@ minetest.register_node("eventobjects:surprise_node", {
|
|||||||
tiles = {"eventobjects_surprise_node.png"},
|
tiles = {"eventobjects_surprise_node.png"},
|
||||||
inventory_image = "eventobjects_surprise_node.png",
|
inventory_image = "eventobjects_surprise_node.png",
|
||||||
wield_image = "eventobjects_surprise_node.png",
|
wield_image = "eventobjects_surprise_node.png",
|
||||||
})
|
groups = {oddly_breakable_by_hand = 2},
|
||||||
|
on_construct = function(pos)
|
||||||
minetest.after(1,function()
|
local meta = minetest.get_meta(pos)
|
||||||
minetest.override_item("eventobjects:surprise_node", {
|
local inv = meta:get_inventory()
|
||||||
on_punch = function(pos, node, puncher, pointed_things)
|
meta:set_string("infotext","?")
|
||||||
-- Spawn betweek 5 and 20 random nodes
|
meta:set_string("formspec",
|
||||||
for cnt = 1,math.random(5,20) do
|
"size[11,12]" ..
|
||||||
local item = ""
|
"list[current_name;main;0.45,0.45;10,7;]" ..
|
||||||
local random_num = math.random(1,#minetest.registered_items)+math.random(-cnt,cnt)
|
"list[current_player;main;1.45,8;8,4;]"
|
||||||
if random_num <= 0 then random_num = 1 end
|
)
|
||||||
local random_count = 1
|
inv:set_size("main",70)
|
||||||
for key, value in pairs(minetest.registered_items) do
|
end,
|
||||||
if random_count == random_num then
|
allow_metadata_inventory_put = function(pos, to_list, to_index, stack, player)
|
||||||
item = key
|
if player and minetest.check_player_privs(player:get_player_name(),{server=true}) then
|
||||||
break
|
return stack:get_count()
|
||||||
end
|
else
|
||||||
random_count = random_count + 1
|
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
|
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
|
end
|
||||||
minetest.remove_node(pos)
|
end
|
||||||
end,
|
minetest.remove_node(pos)
|
||||||
})
|
end,
|
||||||
end)
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user