Dont pick up items when dead

This commit is contained in:
PilzAdam 2013-03-10 17:58:04 +01:00
parent a41ddb6705
commit e0c61c2f77

View File

@ -1,56 +1,58 @@
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
for _,player in ipairs(minetest.get_connected_players()) do for _,player in ipairs(minetest.get_connected_players()) do
local pos = player:getpos() if player:get_hp() > 0 or not minetest.setting_getbool("enable_damage") then
pos.y = pos.y+0.5 local pos = player:getpos()
local inv = player:get_inventory() pos.y = pos.y+0.5
local inv = player:get_inventory()
for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 1)) do
if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 1)) do
if inv and inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then
inv:add_item("main", ItemStack(object:get_luaentity().itemstring)) if inv and inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then
if object:get_luaentity().itemstring ~= "" then inv:add_item("main", ItemStack(object:get_luaentity().itemstring))
minetest.sound_play("item_drop_pickup", { if object:get_luaentity().itemstring ~= "" then
to_player = player:get_player_name(), minetest.sound_play("item_drop_pickup", {
}) to_player = player:get_player_name(),
})
end
object:get_luaentity().itemstring = ""
object:remove()
end end
object:get_luaentity().itemstring = ""
object:remove()
end end
end end
end
for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 2)) do
for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 2)) do if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then
if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then if object:get_luaentity().collect then
if object:get_luaentity().collect then if inv and inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then
if inv and inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then local pos1 = pos
local pos1 = pos pos1.y = pos1.y+0.2
pos1.y = pos1.y+0.2 local pos2 = object:getpos()
local pos2 = object:getpos() local vec = {x=pos1.x-pos2.x, y=pos1.y-pos2.y, z=pos1.z-pos2.z}
local vec = {x=pos1.x-pos2.x, y=pos1.y-pos2.y, z=pos1.z-pos2.z} vec.x = vec.x*3
vec.x = vec.x*3 vec.y = vec.y*3
vec.y = vec.y*3 vec.z = vec.z*3
vec.z = vec.z*3 object:setvelocity(vec)
object:setvelocity(vec)
minetest.after(1, function(args)
minetest.after(1, function(args) local lua = object:get_luaentity()
local lua = object:get_luaentity() if object == nil or lua == nil or lua.itemstring == nil then
if object == nil or lua == nil or lua.itemstring == nil then return
return
end
if inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then
inv:add_item("main", ItemStack(object:get_luaentity().itemstring))
if object:get_luaentity().itemstring ~= "" then
minetest.sound_play("item_drop_pickup", {
to_player = player:get_player_name(),
})
end end
object:get_luaentity().itemstring = "" if inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then
object:remove() inv:add_item("main", ItemStack(object:get_luaentity().itemstring))
else if object:get_luaentity().itemstring ~= "" then
object:setvelocity({x=0,y=0,z=0}) minetest.sound_play("item_drop_pickup", {
end to_player = player:get_player_name(),
end, {player, object}) })
end
object:get_luaentity().itemstring = ""
object:remove()
else
object:setvelocity({x=0,y=0,z=0})
end
end, {player, object})
end
end end
end end
end end