landsandboat/scripts/commands/spawnmob.lua

82 lines
2.1 KiB
Lua
Raw Permalink Normal View History

-----------------------------------
-- func: spawnmob
2016-01-16 01:26:33 -05:00
-- desc: Spawns a mob.
-----------------------------------
---@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 = 'iii'
}
2016-01-16 01:26:33 -05:00
local function error(player, msg)
player:printToPlayer(msg)
player:printToPlayer('!spawnmob <mob ID> (despawntime) (respawntime)')
end
commandObj.onTrigger = function(player, mobId, despawntime, respawntime)
2021-10-18 13:29:59 -05:00
local zone = player:getZone()
if not zone then
return
end
if zone:getTypeMask() == xi.zoneType.INSTANCED then
2021-10-18 13:29:59 -05:00
local instance = player:getInstance()
2021-10-18 13:29:59 -05:00
-- validate mobId
if mobId == nil then
error(player, 'You must provide a mob ID.')
2021-10-19 13:35:33 -05:00
return
2021-10-18 13:29:59 -05:00
end
2021-10-18 13:29:59 -05:00
if GetMobByID(mobId, instance) == nil then
error(player, 'Invalid mobID')
2021-10-18 13:29:59 -05:00
return
end
2021-10-18 13:29:59 -05:00
if GetMobByID(mobId, instance):isSpawned() then
error(player, 'Mob is already spawned')
2021-10-18 13:29:59 -05:00
return
end
2021-10-18 13:29:59 -05:00
SpawnMob(mobId, instance)
player:printToPlayer(string.format('Spawned %s %s in %s.', GetMobByID(mobId, instance):getName(), mobId, instance))
2021-10-18 13:29:59 -05:00
else
-- validate mobId
if mobId == nil then
error(player, 'You must provide a mob ID.')
2021-10-18 13:29:59 -05:00
return
end
2021-10-18 13:29:59 -05:00
local targ = GetMobByID(mobId)
if targ == nil then
error(player, 'Invalid mob ID.')
2021-10-18 13:29:59 -05:00
return
end
2021-10-18 13:29:59 -05:00
if targ:isSpawned() then
error(player, 'Mob is already spawned')
2021-10-18 13:29:59 -05:00
return
end
2021-10-18 13:29:59 -05:00
-- validate despawntime
if despawntime ~= nil and despawntime < 0 then
error(player, 'Invalid despawn time.')
2021-10-18 13:29:59 -05:00
return
end
-- validate respawntime
if respawntime ~= nil and respawntime < 0 then
error(player, 'Invalid respawn time.')
2021-10-18 13:29:59 -05:00
return
end
2021-10-18 13:29:59 -05:00
SpawnMob(targ:getID(), despawntime, respawntime)
player:printToPlayer(string.format('Spawned %s %s.', targ:getName(), mobId))
2021-10-18 13:29:59 -05:00
end
end
return commandObj