Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve: added monster count to create monster talkaction #1861

Merged
merged 6 commits into from
Nov 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 89 additions & 11 deletions data/scripts/talkactions/god/create_monster.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down