mirror of
https://github.com/minetest-mods/item_drop.git
synced 2024-12-22 22:02:26 +01:00
Fix multiplayer support
This commit is contained in:
parent
b56c1792de
commit
69a68cb247
121
init.lua
121
init.lua
@ -55,74 +55,70 @@ if minetest.settings:get_bool("item_drop.enable_item_pickup") ~= false then
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function pickupfunc()
|
local function pickupfunc(player)
|
||||||
for _,player in ipairs(minetest.get_connected_players()) do
|
local keys_pressed = not key_triggered
|
||||||
local keys_pressed = not key_triggered
|
|
||||||
|
|
||||||
local control = player:get_player_control()
|
local control = player:get_player_control()
|
||||||
|
|
||||||
if keytype == "Use" then
|
if keytype == "Use" then
|
||||||
keys_pressed = control.aux1
|
keys_pressed = control.aux1
|
||||||
elseif keytype == "Sneak" then
|
elseif keytype == "Sneak" then
|
||||||
keys_pressed = control.sneak
|
keys_pressed = control.sneak
|
||||||
elseif keytype == "LeftAndRight" then -- LeftAndRight combination
|
elseif keytype == "LeftAndRight" then -- LeftAndRight combination
|
||||||
keys_pressed = control.left and control.right
|
keys_pressed = control.left and control.right
|
||||||
elseif keytype == "RMB" then
|
elseif keytype == "RMB" then
|
||||||
keys_pressed = control.RMB
|
keys_pressed = control.RMB
|
||||||
elseif keytype == "SneakAndRMB" then -- SneakAndRMB combination
|
elseif keytype == "SneakAndRMB" then -- SneakAndRMB combination
|
||||||
keys_pressed = control.sneak and control.RMB
|
keys_pressed = control.sneak and control.RMB
|
||||||
end
|
end
|
||||||
|
|
||||||
if not keys_pressed
|
if not keys_pressed
|
||||||
or (damage_enabled and player:get_hp() <= 0) then
|
or (damage_enabled and player:get_hp() <= 0) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local pos = player:getpos()
|
local pos = player:getpos()
|
||||||
pos.y = pos.y+0.5
|
pos.y = pos.y+0.5
|
||||||
local inv
|
local inv
|
||||||
|
|
||||||
local objectlist = minetest.get_objects_inside_radius(pos,
|
local objectlist = minetest.get_objects_inside_radius(pos,
|
||||||
pickup_radius)
|
pickup_radius)
|
||||||
for i = 1,#objectlist do
|
for i = 1,#objectlist do
|
||||||
local object = objectlist[i]
|
local object = objectlist[i]
|
||||||
local ent = opt_get_ent(object)
|
local ent = opt_get_ent(object)
|
||||||
if ent then
|
if ent then
|
||||||
|
if not inv then
|
||||||
|
inv = player:get_inventory()
|
||||||
if not inv then
|
if not inv then
|
||||||
inv = player:get_inventory()
|
minetest.log("error", "[item_drop] Couldn't " ..
|
||||||
if not inv then
|
"get inventory")
|
||||||
minetest.log("error", "[item_drop] Couldn't " ..
|
return
|
||||||
"get inventory")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
if inv:room_for_item("main",
|
end
|
||||||
ItemStack(ent.itemstring)
|
if inv:room_for_item("main", ItemStack(ent.itemstring)) then
|
||||||
) then
|
local pos2 = object:getpos()
|
||||||
local pos2 = object:getpos()
|
local distance = vector.distance(pos, pos2)
|
||||||
local distance = vector.distance(pos, pos2)
|
if distance <= 1 then
|
||||||
if distance <= 1 then
|
inv:add_item("main", ItemStack(
|
||||||
inv:add_item("main", ItemStack(
|
ent.itemstring))
|
||||||
ent.itemstring))
|
minetest.sound_play("item_drop_pickup", {
|
||||||
minetest.sound_play("item_drop_pickup", {
|
to_player = player:get_player_name(),
|
||||||
to_player = player:get_player_name(),
|
gain = pickup_gain,
|
||||||
gain = pickup_gain,
|
})
|
||||||
})
|
ent.itemstring = ""
|
||||||
ent.itemstring = ""
|
object:remove()
|
||||||
object:remove()
|
else
|
||||||
else
|
local vel = vector.multiply(
|
||||||
local vel = vector.multiply(
|
vector.subtract(pos, pos2), 3)
|
||||||
vector.subtract(pos, pos2), 3)
|
vel.y = vel.y + 0.6
|
||||||
vel.y = vel.y + 0.6
|
object:setvelocity(vel)
|
||||||
object:setvelocity(vel)
|
ent.physical_state = false
|
||||||
ent.physical_state = false
|
ent.object:set_properties({
|
||||||
ent.object:set_properties({
|
physical = false
|
||||||
physical = false
|
})
|
||||||
})
|
|
||||||
|
|
||||||
minetest.after(1.0, afterflight,
|
minetest.after(1.0, afterflight,
|
||||||
object, inv, player)
|
object, inv, player)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -130,7 +126,10 @@ if minetest.settings:get_bool("item_drop.enable_item_pickup") ~= false then
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function pickup_step()
|
local function pickup_step()
|
||||||
pickupfunc()
|
local players = minetest.get_connected_players()
|
||||||
|
for i = 1,#players do
|
||||||
|
pickupfunc(players[i])
|
||||||
|
end
|
||||||
minetest.after(0.01, pickup_step)
|
minetest.after(0.01, pickup_step)
|
||||||
end
|
end
|
||||||
minetest.after(3.0, pickup_step)
|
minetest.after(3.0, pickup_step)
|
||||||
|
Loading…
Reference in New Issue
Block a user