local monsterName = "Wolf"
local spawnInterval = 15 -- in seconds
local duration = 2 * 60 * 60 -- in seconds (2 hours)
local itemId = ITEM_ID -- Replace for the item ID
local checkRadius = 1 -- Radius check to see if can create the monster
local function canSpawnMonster(position)
local creatures = getCreaturesInRange(position, checkRadius, checkRadius, false)
return #creatures == 0
end
local function spawnMonster(position)
if canSpawnMonster(position) then
local monster = Game.createMonster(monsterName, position)
if not monster then
print("Failed to spawn monster at position: ", position)
end
else
print("Cannot spawn monster at position: ", position, " - space occupied.")
end
end
local function startSpawning(position)
local endTime = os.time() + duration
addEvent(function()
if os.time() < endTime then
spawnMonster(position)
addEvent(startSpawning, spawnInterval * 1000, position)
end
end, spawnInterval * 1000)
end
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if target and not Tile(target:getPosition()):hasFlag(TILESTATE_PROTECTIONZONE) and not Tile(target:getPosition()):hasFlag(TILESTATE_BLOCKSOLID) then
startSpawning(target:getPosition())
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Spawning started!")
else
player:sendTextMessage(MESSAGE_STATUS_WARNING, "You cannot use this item here.")
end
return true
end