landsandboat/scripts/commands/mobhere.lua

89 lines
2.6 KiB
Lua
Raw Permalink Normal View History

-----------------------------------
-- func: mobhere <mobId>
2016-01-16 01:26:33 -05:00
-- desc: Spawns a MOB and then moves it to the current position, if in same zone.
-- Errors will despawn the MOB unless 'noDepop' was specified (any value works).
-----------------------------------
---@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 = 'is'
}
2016-01-16 01:26:33 -05:00
local function error(player, msg)
player:printToPlayer(msg)
player:printToPlayer('!mobhere (mobID) (noDepop)')
end
commandObj.onTrigger = function(player, mobId, noDepop)
2021-10-18 10:41:48 -05:00
local zone = player:getZone()
if not zone then
return
end
if zone:getTypeMask() == xi.zoneType.INSTANCED then
2021-10-18 10:41:48 -05:00
local instance = player:getInstance()
local targ
-- validate mobId
if mobId == nil then
targ = player:getCursorTarget()
if targ == nil or not targ:isMob() then
error(player, 'You must either provide a mobID or target a mob.')
2021-10-18 10:41:48 -05:00
return
end
else
targ = GetMobByID(mobId, instance)
if targ == nil then
error(player, 'Invalid mobID.')
2021-10-18 10:41:48 -05:00
return
end
end
2021-10-18 10:41:48 -05:00
if not targ:isSpawned() then
2021-10-19 21:53:27 -05:00
SpawnMob(mobId, instance)
player:printToPlayer('Mob state changed to: Spawned.')
2021-10-18 10:41:48 -05:00
end
2021-10-18 10:41:48 -05:00
targ:setPos(player:getXPos(), player:getYPos(), player:getZPos(), player:getRotPos())
else
2021-10-18 10:41:48 -05:00
-- validate mobId
local targ
if mobId == nil then
targ = player:getCursorTarget()
if targ == nil or not targ:isMob() then
error(player, 'You must either provide a mobID or target a mob.')
2021-10-18 10:41:48 -05:00
return
end
else
targ = GetMobByID(mobId)
if targ == nil then
error(player, 'Invalid mobID.')
2021-10-18 10:41:48 -05:00
return
end
end
2021-10-18 10:41:48 -05:00
mobId = targ:getID()
2021-10-18 10:41:48 -05:00
if not targ:isSpawned() then
SpawnMob(mobId)
player:printToPlayer('Mob state changed to: Spawned.')
2021-10-18 10:41:48 -05:00
end
if player:getZoneID() == targ:getZoneID() then
targ:setPos(player:getXPos(), player:getYPos(), player:getZPos(), player:getRotPos(), player:getZoneID())
2021-10-18 10:41:48 -05:00
else
if noDepop == nil or noDepop == 0 then
DespawnMob(mobId)
player:printToPlayer('Despawned the mob because of an error.')
2021-10-18 10:41:48 -05:00
end
player:printToPlayer('Mob could not be moved to current pos - you are probably in the wrong zone.')
2016-01-16 01:26:33 -05:00
end
end
end
return commandObj