diff --git a/data/scripts/talkactions/god/create_monster.lua b/data/scripts/talkactions/god/create_monster.lua index 6e5c4a4ffbf..924a0d0906d 100644 --- a/data/scripts/talkactions/god/create_monster.lua +++ b/data/scripts/talkactions/god/create_monster.lua @@ -1,36 +1,114 @@ +local function createCreaturesAround(player, maxRadius, creatureName, creatureCount, creatureForge, boolForceCreate) + local position = player:getPosition() + local createdCount = 0 + local sendMessage = false + local canSetFiendish, canSetInfluenced, influencedLevel = CheckDustLevel(creatureForge, player) + for radius = 1, maxRadius do + if createdCount >= creatureCount then + break + end + + local minX = position.x - radius + local maxX = position.x + radius + local minY = position.y - radius + local maxY = position.y + radius + for dx = minX, maxX do + for dy = minY, maxY do + if (dx == minX or dx == maxX or dy == minY or dy == maxY) and createdCount < creatureCount then + local checkPosition = Position(dx, dy, position.z) + local tile = Tile(checkPosition) + if tile and not tile:hasProperty(CONST_PROP_IMMOVABLEBLOCKSOLID) then + local monster = Game.createMonster(creatureName, checkPosition, false, boolForceCreate) + if monster then + createdCount = createdCount + 1 + monster:getPosition():sendMagicEffect(CONST_ME_TELEPORT) + position:sendMagicEffect(CONST_ME_MAGIC_RED) + if creatureForge ~= nil and monster:isForgeable() then + local monsterType = monster:getType() + if canSetFiendish then + SetFiendish(monsterType, position, player, monster) + end + if canSetInfluenced then + SetInfluenced(monsterType, monster, player, influencedLevel) + end + elseif notSendMessage then + sendMessage = true + end + end + end + end + end + end + end + if sendMessage == true then + player:sendCancelMessage("Only allowed monsters can be fiendish or influenced.") + end + + logger.info("Player {} created '{}' monsters", player:getName(), createdCount) +end + local createMonster = TalkAction("/m") +-- @function createMonster.onSay +-- @desc TalkAction to create monsters with multiple options. +-- @param player: The player executing the command. +-- @param words: Command words. +-- @param param: String containing the command parameters. +-- Format: "/m monstername, monstercount, [fiendish/influenced level], spawnRadius, [forceCreate]" +-- Example: "/m rat, 10, fiendish, 5, true" +-- @param: the last param is by default "false", if add "," or any value i'ts set to true +-- @return true if the command is executed successfully, false otherwise. function createMonster.onSay(player, words, param) -- create log logCommand(player, words, param) - - -- Usage: "/m monstername, fiendish" for create a fiendish monster (/m rat, fiendish) - -- Usage: "/m monstername, [1-5]" for create a influenced monster with specific level (/m rat, 2) if param == "" then player:sendCancelMessage("Monster name param required.") logger.error("[createMonster.onSay] - Monster name param not found.") return true end + local position = player:getPosition() + local split = param:split(",") local monsterName = split[1] - local monsterForge = nil + local monsterCount = 0 if split[2] then split[2] = split[2]:gsub("^%s*(.-)$", "%1") --Trim left - monsterForge = split[2] + monsterCount = tonumber(split[2]) + end + + local monsterForge = nil + if split[3] then + split[3] = split[3]:gsub("^%s*(.-)$", "%1") --Trim left + monsterForge = split[3] + end + + if monsterCount > 1 then + local spawnRadius = 5 + if split[4] then + split[4] = split[4]:gsub("^%s*(.-)$", "%1") --Trim left + spawnRadius = split[4] + print(spawnRadius) + end + + local forceCreate = false + if split[5] then + forceCreate = true + end + + createCreaturesAround(player, spawnRadius, monsterName, monsterCount, monsterForge, forceCreate) + return true end - -- Check dust level - local canSetFiendish, canSetInfluenced, influencedLevel = CheckDustLevel(monsterForge, player) - local position = player:getPosition() local monster = Game.createMonster(monsterName, position) if monster then - if not monster:isForgeable() then + local canSetFiendish, canSetInfluenced, influencedLevel = CheckDustLevel(monsterForge, player) + monster:getPosition():sendMagicEffect(CONST_ME_TELEPORT) + position:sendMagicEffect(CONST_ME_MAGIC_RED) + if monsterForge ~= nil and not monster:isForgeable() then player:sendCancelMessage("Only allowed monsters can be fiendish or influenced.") return true end - monster:getPosition():sendMagicEffect(CONST_ME_TELEPORT) - position:sendMagicEffect(CONST_ME_MAGIC_RED) local monsterType = monster:getType() if canSetFiendish then