Skip to content

Commit

Permalink
Swap superior item pickups with inferior held ones
Browse files Browse the repository at this point in the history
  • Loading branch information
LoneWolfHT committed Oct 25, 2023
1 parent 2a2737f commit 8dc999e
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion mods/ctf/ctf_modebase/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,28 @@ function ctf_modebase.player.give_initial_stuff(player)
inv:set_list("main", new)
end

end
minetest.register_on_item_pickup(function(itemstack, picker)
if ctf_modebase.current_mode and ctf_teams.get(picker) then
for name, func in pairs(ctf_modebase:get_current_mode().initial_stuff_item_levels) do
local priority = func(itemstack)

if priority then
local inv = picker:get_inventory()
for i=1, 8 do -- loop through the top row of the player's inv
local compare = inv:get_stack("main", i)
local cprio = func(compare)

if cprio and cprio < priority then
inv:set_stack("main", i, itemstack)
return compare
end
end

break -- We already found a place for it, don't check for one held by a different item type
end
end
end
end)

function ctf_modebase.player.empty_inv(player)
player:get_inventory():set_list("main", {})
Expand Down

0 comments on commit 8dc999e

Please sign in to comment.