ctf_markers: Fix occasional crash due to invalid ObjectRef

This commit is contained in:
ANAND 2020-04-25 00:46:35 +05:30
parent dc72f1d10e
commit e415b1be79
No known key found for this signature in database
GPG key ID: 3AD8A3C4A51AAB97

View file

@ -99,15 +99,18 @@ minetest.register_chatcommand("m", {
if pointed.type == "object" then
local concat
local obj = pointed.ref
local entity = obj:get_luaentity()
-- If object is a player, append player name to display text
-- Else if obj is item entity, append item description and count to str.
if obj:is_player() then
concat = obj:get_player_name()
else
local entity = obj:get_luaentity()
-- If obj is item entity, append item description and count to str.
-- Fallback to itemstring if description doesn't exist
elseif entity then
if entity.name == "__builtin:item" then
local stack = ItemStack(entity.itemstring)
local itemdef = minetest.registered_items[stack:get_name()]
-- Fallback to itemstring if description doesn't exist
concat = itemdef.description or entity.itemstring
concat = concat .. " " .. stack:get_count()
else