landsandboat/scripts/commands/getmobflags.lua

44 lines
1.1 KiB
Lua
Raw Permalink Normal View History

-----------------------------------
2018-12-16 23:20:37 -07:00
-- func: getmobflags <optional MobID>
-- desc: Used to get a mob's entity flags for testing.
-- MUST either target a mob first or else specify a Mob ID.
-----------------------------------
---@type TCommand
local commandObj = {}
2018-12-16 23:20:37 -07:00
commandObj.cmdprops =
2018-12-16 23:20:37 -07:00
{
permission = 1,
parameters = 'i'
2018-12-16 23:20:37 -07:00
}
local function error(player, msg)
player:printToPlayer(msg)
player:printToPlayer('!getmobflags (mob ID)')
2018-12-16 23:20:37 -07:00
end
commandObj.onTrigger = function(player, target)
2018-12-16 23:20:37 -07:00
-- validate target
local targ
if not target then
targ = player:getCursorTarget()
2018-12-16 23:44:35 -07:00
if not targ or not targ:isMob() then
error(player, 'You must either supply a mob ID or target a mob.')
2018-12-16 23:20:37 -07:00
return
end
else
targ = GetMobByID(target)
if not targ then
error(player, 'Invalid mob ID.')
2018-12-16 23:20:37 -07:00
return
end
end
-- set flags
local flags = targ:getMobFlags()
local hex = '0x' .. string.format('%08x', flags)
player:printToPlayer(string.format('%s\'s flags: %s (%u)', targ:getName(), hex, flags))
end
return commandObj