Skip to content

Commit

Permalink
ctf_markers: Fix occasional crash due to invalid ObjectRef
Browse files Browse the repository at this point in the history
  • Loading branch information
ClobberXD committed Apr 30, 2020
1 parent e6bc656 commit 03de61f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions mods/ctf/ctf_marker/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,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
Expand Down

0 comments on commit 03de61f

Please sign in to comment.