Update player inventories when item is replaced with chat command
This commit is contained in:
parent
f8fd1506eb
commit
9592b1df73
6
TODO.txt
6
TODO.txt
@ -1,5 +1,9 @@
|
||||
|
||||
TODO:
|
||||
- update world file when chat commands are used
|
||||
- update player inventories when items are replaced
|
||||
- update player inventories when items are replaced:
|
||||
- bags
|
||||
- 3d_armor
|
||||
- update storage inventories when items are replaced
|
||||
- update player inventories on login
|
||||
- fix top nodes disappearing with /replace_node command
|
||||
|
17
chat.lua
17
chat.lua
@ -190,13 +190,26 @@ local function replace_item(src, tgt)
|
||||
end
|
||||
|
||||
core.register_alias(src, tgt)
|
||||
|
||||
-- update player inventories
|
||||
for _, player in ipairs(core.get_connected_players()) do
|
||||
local pinv = player:get_inventory()
|
||||
|
||||
for idx, stack in pairs(pinv:get_list("main")) do
|
||||
if stack:get_name() == src then
|
||||
local new_stack = ItemStack(tgt)
|
||||
new_stack:set_count(stack:get_count())
|
||||
|
||||
pinv:set_stack("main", idx, new_stack)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
--- Replaces an item.
|
||||
--
|
||||
-- FIXME: inventory icons not updated
|
||||
--
|
||||
-- @chatcmd replace_item
|
||||
-- @param old_item Technical name of item to replace.
|
||||
-- @param new_item Technical name of item to be used in place.
|
||||
|
Loading…
x
Reference in New Issue
Block a user