Skip to content

Commit

Permalink
Update manage_monster.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
kaleohanopahala authored Oct 2, 2024
1 parent e938b75 commit db754d2
Showing 1 changed file with 119 additions and 111 deletions.
230 changes: 119 additions & 111 deletions data/scripts/talkactions/god/manage_monster.lua
Original file line number Diff line number Diff line change
@@ -1,157 +1,165 @@
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)
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

Check warning on line 16 in data/scripts/talkactions/god/manage_monster.lua

View workflow job for this annotation

GitHub Actions / luacheck

[luacheck] reported by reviewdog 🐶 line contains only whitespace Raw Output: data/scripts/talkactions/god/manage_monster.lua:16:1: line contains only whitespace
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
else
sendMessage = true
end
end
end
end
end
end
end

if sendMessage 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"
-- Format: "/m monstername, monstercount, [fiendish/influenced level], [forceCreate]"
-- Example: "/m rat, 10, fiendish"
-- @param: the last param is by default "false", if add "," or any value it's set to true
-- @return true if the command is executed successfully, false otherwise.
function createMonster.onSay(player, words, param)
-- create log
-- create Log of the command usage.
logCommand(player, words, param)

-- Check if parameters were passed.
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 monsterCount = 0
if split[2] then
split[2] = split[2]:trimSpace()
monsterCount = tonumber(split[2])
local monsterName = split[1]:trimSpace()

Check warning on line 79 in data/scripts/talkactions/god/manage_monster.lua

View workflow job for this annotation

GitHub Actions / luacheck

[luacheck] reported by reviewdog 🐶 line contains only whitespace Raw Output: data/scripts/talkactions/god/manage_monster.lua:79:1: line contains only whitespace
local monsterType = MonsterType(monsterName)
if not monsterType then
player:sendCancelMessage("Invalid monster name!")
return true
end

local monsterCount = tonumber(split[2]) or 1
if monsterCount < 1 or monsterCount > 100 then
if monsterCount > 100 then

Check warning on line 88 in data/scripts/talkactions/god/manage_monster.lua

View workflow job for this annotation

GitHub Actions / luacheck

[luacheck] reported by reviewdog 🐶 inconsistent indentation (SPACE followed by TAB) Raw Output: data/scripts/talkactions/god/manage_monster.lua:88:1: inconsistent indentation (SPACE followed by TAB)
monsterCount = 100

Check warning on line 89 in data/scripts/talkactions/god/manage_monster.lua

View workflow job for this annotation

GitHub Actions / luacheck

[luacheck] reported by reviewdog 🐶 inconsistent indentation (SPACE followed by TAB) Raw Output: data/scripts/talkactions/god/manage_monster.lua:89:1: inconsistent indentation (SPACE followed by TAB)

Check warning on line 89 in data/scripts/talkactions/god/manage_monster.lua

View workflow job for this annotation

GitHub Actions / luacheck

[luacheck] reported by reviewdog 🐶 value assigned to variable 'monsterCount' is unused Raw Output: data/scripts/talkactions/god/manage_monster.lua:89:10: value assigned to variable 'monsterCount' is unused
player:sendCancelMessage("You can only create up to 100 monsters at a time due to server stability concerns!")

Check warning on line 90 in data/scripts/talkactions/god/manage_monster.lua

View workflow job for this annotation

GitHub Actions / luacheck

[luacheck] reported by reviewdog 🐶 inconsistent indentation (SPACE followed by TAB) Raw Output: data/scripts/talkactions/god/manage_monster.lua:90:1: inconsistent indentation (SPACE followed by TAB)
return false

Check warning on line 91 in data/scripts/talkactions/god/manage_monster.lua

View workflow job for this annotation

GitHub Actions / luacheck

[luacheck] reported by reviewdog 🐶 inconsistent indentation (SPACE followed by TAB) Raw Output: data/scripts/talkactions/god/manage_monster.lua:91:1: inconsistent indentation (SPACE followed by TAB)
end

Check warning on line 92 in data/scripts/talkactions/god/manage_monster.lua

View workflow job for this annotation

GitHub Actions / luacheck

[luacheck] reported by reviewdog 🐶 inconsistent indentation (SPACE followed by TAB) Raw Output: data/scripts/talkactions/god/manage_monster.lua:92:1: inconsistent indentation (SPACE followed by TAB)
end

local monsterForge = nil
if split[3] then
split[3] = split[3]:trimSpace()
monsterForge = split[3]
local monsterForge = split[3] and split[3]:trimSpace() or nil
local influencedLevel = tonumber(split[3]) or 0

if influencedLevel < 0 or influencedLevel > 5 then
player:sendCancelMessage("Influenced level must be between 0 and 5.")

Check warning on line 99 in data/scripts/talkactions/god/manage_monster.lua

View workflow job for this annotation

GitHub Actions / luacheck

[luacheck] reported by reviewdog 🐶 inconsistent indentation (SPACE followed by TAB) Raw Output: data/scripts/talkactions/god/manage_monster.lua:99:1: inconsistent indentation (SPACE followed by TAB)
return true

Check warning on line 100 in data/scripts/talkactions/god/manage_monster.lua

View workflow job for this annotation

GitHub Actions / luacheck

[luacheck] reported by reviewdog 🐶 inconsistent indentation (SPACE followed by TAB) Raw Output: data/scripts/talkactions/god/manage_monster.lua:100:1: inconsistent indentation (SPACE followed by TAB)
end

local spawnRadius = tonumber(split[4]) or 5
local forceCreate = split[5] and split[5]:lower() == "true"

if monsterCount > 1 then
local spawnRadius = 5
if split[4] then
split[4] = split[4]:trimSpace()
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

local monster = Game.createMonster(monsterName, position)
if monster 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
else
local monster = Game.createMonster(monsterName, position)
if monster then
local canSetFiendish, canSetInfluenced, influencedLevel = CheckDustLevel(monsterForge, player)
monster:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
position:sendMagicEffect(CONST_ME_MAGIC_RED)
if monsterForge and not monster:isForgeable() then
player:sendCancelMessage("Only allowed monsters can be fiendish or influenced!")
return true
end

local monsterType = monster:getType()
if canSetFiendish then
SetFiendish(monsterType, position, player, monster)
end
if canSetInfluenced then
SetInfluenced(monsterType, monster, player, influencedLevel)
local monsterType = monster:getType()
if canSetFiendish then
SetFiendish(monsterType, position, player, monster)
end
if canSetInfluenced then
SetInfluenced(monsterType, monster, player, influencedLevel)
end
else
player:sendCancelMessage("There is not enough room.")
position:sendMagicEffect(CONST_ME_POFF)
end
else
player:sendCancelMessage("There is not enough room.")
position:sendMagicEffect(CONST_ME_POFF)
end

return true
end

createMonster:separator(" ")
createMonster:groupType("god")
createMonster:register()

----------------- Rename monster name -----------------
local setMonsterName = TalkAction("/setmonstername")

-- Command to rename monsters within a radius
-- @function setMonsterName.onSay
-- @desc TalkAction to rename nearby monsters within a radius of 4 sqm.
-- @desc TalkAction to rename nearby monsters within a radius of 4 sqms.
-- Format: "/setmonstername newName"
local setMonsterName = TalkAction("/setmonstername")

function setMonsterName.onSay(player, words, param)
if param == "" then
player:sendCancelMessage("Command param required.")
return true
end
if param == "" then
player:sendCancelMessage("Command param required.")
return true
end

local split = param:split(",")
local monsterNewName = split[1]
local newName = param:trimSpace()
local position = player:getPosition()

local spectators, spectator = Game.getSpectators(player:getPosition(), false, false, 4, 4, 4, 4)
for i = 1, #spectators do
spectator = spectators[i]
if spectator:isMonster() then
spectator:setName(monsterNewName)
end
end
local spectators = Game.getSpectators(position, false, false, 4, 4, 4, 4)

return true
for _, spectator in ipairs(spectators) do
if spectator:isMonster() then
spectator:setName(newName)
end
end

return true
end

setMonsterName:separator(" ")
Expand Down

0 comments on commit db754d2

Please sign in to comment.