2021-01-18 13:34:00 -05:00
|
|
|
-----------------------------------
|
2016-07-29 08:35:15 -06:00
|
|
|
-- func: spawnmob
|
2016-01-16 01:26:33 -05:00
|
|
|
-- desc: Spawns a mob.
|
2021-01-18 13:34:00 -05:00
|
|
|
-----------------------------------
|
2024-08-25 10:54:45 -04:00
|
|
|
---@type TCommand
|
2023-09-02 07:01:35 -04:00
|
|
|
local commandObj = {}
|
2016-01-16 01:26:33 -05:00
|
|
|
|
2023-09-02 07:01:35 -04:00
|
|
|
commandObj.cmdprops =
|
2016-01-16 01:26:33 -05:00
|
|
|
{
|
|
|
|
|
permission = 1,
|
2023-08-28 21:02:28 -04:00
|
|
|
parameters = 'iii'
|
2020-02-19 21:40:57 -08:00
|
|
|
}
|
2016-01-16 01:26:33 -05:00
|
|
|
|
2023-09-02 07:01:35 -04:00
|
|
|
local function error(player, msg)
|
2023-12-09 23:54:00 +00:00
|
|
|
player:printToPlayer(msg)
|
|
|
|
|
player:printToPlayer('!spawnmob <mob ID> (despawntime) (respawntime)')
|
2020-02-19 21:40:57 -08:00
|
|
|
end
|
2017-08-08 17:23:52 -04:00
|
|
|
|
2023-09-02 07:01:35 -04:00
|
|
|
commandObj.onTrigger = function(player, mobId, despawntime, respawntime)
|
2021-10-18 13:29:59 -05:00
|
|
|
local zone = player:getZone()
|
2024-08-25 12:01:53 -04:00
|
|
|
if not zone then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
2023-08-12 19:03:48 -04:00
|
|
|
if zone:getTypeMask() == xi.zoneType.INSTANCED then
|
2021-10-18 13:29:59 -05:00
|
|
|
local instance = player:getInstance()
|
2017-08-08 17:23:52 -04:00
|
|
|
|
2021-10-18 13:29:59 -05:00
|
|
|
-- validate mobId
|
|
|
|
|
if mobId == nil then
|
2023-08-28 21:02:28 -04:00
|
|
|
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
|
2022-11-22 14:39:00 -05:00
|
|
|
|
2021-10-18 13:29:59 -05:00
|
|
|
if GetMobByID(mobId, instance) == nil then
|
2023-08-28 21:02:28 -04:00
|
|
|
error(player, 'Invalid mobID')
|
2021-10-18 13:29:59 -05:00
|
|
|
return
|
|
|
|
|
end
|
2022-11-22 14:39:00 -05:00
|
|
|
|
2021-10-18 13:29:59 -05:00
|
|
|
if GetMobByID(mobId, instance):isSpawned() then
|
2023-08-28 21:02:28 -04:00
|
|
|
error(player, 'Mob is already spawned')
|
2021-10-18 13:29:59 -05:00
|
|
|
return
|
|
|
|
|
end
|
2022-11-22 14:39:00 -05:00
|
|
|
|
2021-10-18 13:29:59 -05:00
|
|
|
SpawnMob(mobId, instance)
|
2023-12-09 23:54:00 +00:00
|
|
|
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
|
2023-08-28 21:02:28 -04:00
|
|
|
error(player, 'You must provide a mob ID.')
|
2021-10-18 13:29:59 -05:00
|
|
|
return
|
|
|
|
|
end
|
2022-11-22 14:39:00 -05:00
|
|
|
|
2021-10-18 13:29:59 -05:00
|
|
|
local targ = GetMobByID(mobId)
|
|
|
|
|
if targ == nil then
|
2023-08-28 21:02:28 -04:00
|
|
|
error(player, 'Invalid mob ID.')
|
2021-10-18 13:29:59 -05:00
|
|
|
return
|
|
|
|
|
end
|
2020-03-19 18:41:42 -07:00
|
|
|
|
2021-10-18 13:29:59 -05:00
|
|
|
if targ:isSpawned() then
|
2023-08-28 21:02:28 -04:00
|
|
|
error(player, 'Mob is already spawned')
|
2021-10-18 13:29:59 -05:00
|
|
|
return
|
|
|
|
|
end
|
2017-08-08 17:23:52 -04:00
|
|
|
|
2021-10-18 13:29:59 -05:00
|
|
|
-- validate despawntime
|
|
|
|
|
if despawntime ~= nil and despawntime < 0 then
|
2023-08-28 21:02:28 -04:00
|
|
|
error(player, 'Invalid despawn time.')
|
2021-10-18 13:29:59 -05:00
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- validate respawntime
|
|
|
|
|
if respawntime ~= nil and respawntime < 0 then
|
2023-08-28 21:02:28 -04:00
|
|
|
error(player, 'Invalid respawn time.')
|
2021-10-18 13:29:59 -05:00
|
|
|
return
|
|
|
|
|
end
|
2017-08-08 17:23:52 -04:00
|
|
|
|
2021-10-18 13:29:59 -05:00
|
|
|
SpawnMob(targ:getID(), despawntime, respawntime)
|
2023-12-09 23:54:00 +00:00
|
|
|
player:printToPlayer(string.format('Spawned %s %s.', targ:getName(), mobId))
|
2021-10-18 13:29:59 -05:00
|
|
|
end
|
2020-03-19 18:41:42 -07:00
|
|
|
end
|
2023-09-02 07:01:35 -04:00
|
|
|
|
|
|
|
|
return commandObj
|