commit | author | age
|
e139ff
|
1 |
dofile(minetest.get_modpath("item_drop").."/item_entity.lua") |
R |
2 |
time_pick = 3 |
|
3 |
minetest.register_globalstep(function(dtime) |
|
4 |
for _,player in ipairs(minetest.get_connected_players()) do |
|
5 |
local pos = player:getpos() |
|
6 |
pos.y = pos.y+0.5 |
|
7 |
local inv = player:get_inventory() |
1cbe99
|
8 |
for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 2)) do |
R |
9 |
if not object:is_player() and object:get_luaentity() then |
|
10 |
local obj=object:get_luaentity() |
|
11 |
if obj.name == "__builtin:item" then |
|
12 |
if inv:room_for_item("main", ItemStack(obj.itemstring)) then |
|
13 |
if obj.timer > time_pick then |
|
14 |
inv:add_item("main", ItemStack(obj.itemstring)) |
|
15 |
if obj.itemstring ~= "" then |
|
16 |
minetest.sound_play("item_drop_pickup") |
e139ff
|
17 |
end |
1cbe99
|
18 |
if object:get_luaentity() then |
R |
19 |
object:get_luaentity().itemstring = "" |
|
20 |
object:remove() |
|
21 |
end |
e139ff
|
22 |
end |
R |
23 |
end |
|
24 |
end |
|
25 |
end |
|
26 |
end |
|
27 |
end |
|
28 |
end) |
|
29 |
|
|
30 |
function minetest.handle_node_drops(pos, drops, digger) |
|
31 |
for _,item in ipairs(drops) do |
|
32 |
local count, name |
|
33 |
if type(item) == "string" then |
|
34 |
count = 1 |
|
35 |
name = item |
|
36 |
else |
|
37 |
count = item:get_count() |
|
38 |
name = item:get_name() |
|
39 |
end |
|
40 |
for i=1,count do |
|
41 |
local obj = minetest.env:add_item(pos, name) |
|
42 |
if obj ~= nil then |
|
43 |
obj:get_luaentity().collect = true |
|
44 |
local x = math.random(1, 5) |
|
45 |
if math.random(1,2) == 1 then |
|
46 |
x = -x |
|
47 |
end |
|
48 |
local z = math.random(1, 5) |
|
49 |
if math.random(1,2) == 1 then |
|
50 |
z = -z |
|
51 |
end |
|
52 |
obj:setvelocity({x=1/x, y=obj:getvelocity().y, z=1/z}) |
|
53 |
obj:get_luaentity().timer = time_pick |
|
54 |
-- FIXME this doesnt work for deactiveted objects |
|
55 |
if minetest.setting_get("remove_items") and tonumber(minetest.setting_get("remove_items")) then |
|
56 |
minetest.after(tonumber(minetest.setting_get("remove_items")), function(obj) |
|
57 |
obj:remove() |
|
58 |
end, obj) |
|
59 |
end |
|
60 |
end |
|
61 |
end |
|
62 |
end |
|
63 |
end |
|
64 |
--[[ |
|
65 |
minetest.register_on_dieplayer(function(name, pos) |
|
66 |
local inv = name:get_inventory() |
|
67 |
local pos = name:getpos() |
|
68 |
for i = 1, inv:get_size("main"), 1 do |
|
69 |
srcstack = inv:get_stack("main", i) |
|
70 |
if srcstack:to_string() ~= "" then |
|
71 |
pos.y = pos.y + 3 |
|
72 |
local obj = minetest.env:add_item(pos, srcstack:to_string()) |
|
73 |
local x = math.random(-5, 5) |
|
74 |
if x >= -2 and x <=0 then |
|
75 |
local x = x - 3 |
|
76 |
end |
|
77 |
if x > 0 and x <= 2 then |
|
78 |
local x = x + 3 |
|
79 |
end |
|
80 |
local y = math.random(3, 5) |
|
81 |
local z = math.random(-5, 5) |
|
82 |
if z >= -2 and z <= 0 then |
|
83 |
local z = z - 3 |
|
84 |
end |
|
85 |
if z > 0 and z <= 2 then |
|
86 |
local z = z + 3 |
|
87 |
end |
|
88 |
inv:set_stack("main", i, "") |
|
89 |
obj:setvelocity({x=x, y=y, z=z}) |
|
90 |
end |
|
91 |
if i == 32 then |
|
92 |
break |
|
93 |
end |
|
94 |
end |
|
95 |
end) |
|
96 |
]]-- |
595ed5
|
97 |
print("DROPS LOADED!") |