landsandboat/scripts/commands/setmobflags.lua

53 lines
1.4 KiB
Lua
Raw Permalink Normal View History

-----------------------------------
-- func: setmobflags <flags> <optional MobID>
-- desc: Used to manipulate a mob's nameflags for testing.
2016-01-16 01:26:33 -05:00
-- MUST either target a mob first or else specify a Mob ID.
-----------------------------------
---@type TCommand
local commandObj = {}
2016-01-16 01:26:33 -05:00
commandObj.cmdprops =
2016-01-16 01:26:33 -05:00
{
permission = 1,
parameters = 'si'
}
2016-01-16 01:26:33 -05:00
local function error(player, msg)
player:printToPlayer(msg)
player:printToPlayer('!setmobflags <flags> (mob ID)')
end
commandObj.onTrigger = function(player, flags, target)
-- validate flags
2021-05-02 14:33:02 -04:00
if flags ~= nil and tonumber(flags) ~= nil then
flags = tonumber(flags)
else
error(player, 'You must supply a flags value.')
return
2016-01-16 01:26:33 -05:00
end
-- validate target
local targ
2021-05-02 14:33:02 -04:00
if target == nil then
targ = player:getCursorTarget()
if targ == nil or not targ:isMob() then
error(player, 'You must either supply a mob ID or target a mob.')
return
end
2016-01-16 01:26:33 -05:00
else
targ = GetMobByID(target)
2021-05-02 14:33:02 -04:00
if targ == nil then
error(player, 'Invalid mob ID.')
return
end
2016-01-16 01:26:33 -05:00
end
-- set flags
---@diagnostic disable-next-line param-type-mismatch
player:setMobFlags(flags, targ:getID())
local hex = '0x' .. string.format('%08x', flags)
player:printToPlayer(string.format('Set %s %i flags to %s (%i).', targ:getName(), targ:getID(), hex, flags))
end
return commandObj