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