Hi !
I have TFS 1.4.2
I created several bosses in several rooms. One of their spells is to summon monsters. The problem is that after killing the boss (if possible), his summons would disappear after e.g. 30 seconds. If this is not possible, the summon disappears when you kill the boss. I tried to do it in various ways, but unfortunately I failed. Does anyone know how to solve it?
Here is the spell:
It was created with GPT chat, so after a few attempts it could probably be written in a simpler way
Second:

I created several bosses in several rooms. One of their spells is to summon monsters. The problem is that after killing the boss (if possible), his summons would disappear after e.g. 30 seconds. If this is not possible, the summon disappears when you kill the boss. I tried to do it in various ways, but unfortunately I failed. Does anyone know how to solve it?
Here is the spell:
It was created with GPT chat, so after a few attempts it could probably be written in a simpler way

LUA:
local maxSummons = 6 -- Maksymalna liczba summonów
local summonStorage = {} -- Przechowuje summonowane potwory
local summonChance = 50 -- Szansa na summonowanie (w %)
local summonInterval = 3000 -- Czas między summonami (3 sekundy)
local activeSummonProcess = {} -- Przechowuje aktywne procesy summonowania dla bossów
-- Funkcja sprawdzająca liczbę aktualnych summonów
local function getSummonsCount()
local count = 0
for summonId, _ in pairs(summonStorage) do
local summon = Creature(summonId)
if summon then
count = count + 1
else
summonStorage[summonId] = nil -- Usuwa martwe summony
end
end
return count
end
-- Funkcja próbująca summonować potwora według szansy
local function trySummonMonster(creature)
if not creature or not creature:isMonster() then
return
end
-- Jeśli osiągnięto limit, nie summonujemy więcej
if getSummonsCount() >= maxSummons then
return
end
-- Sprawdzenie szansy na summon
if math.random(100) > summonChance then
return -- Jeśli nie wylosowano summonowania, kończymy funkcję
end
-- Wybór losowego potwora do summonowania
local roll = math.random(100)
local summonName = nil
if roll <= 35 then
summonName = "[Tower]Orc Leader" -- 35% szansy
elseif roll <= 55 then
summonName = "[Tower]Orc Warlord" -- 20% szansy (bo 35 + 20 = 55)
end
if summonName then
local position = creature:getPosition()
local offsetX = math.random(-3, 3)
local offsetY = math.random(-3, 3)
local summonPosition = Position(position.x + offsetX, position.y + offsetY, position.z)
-- Sprawdzenie, czy pozycja jest odpowiednia
local tile = Tile(summonPosition)
if tile and not tile:getTopCreature() then
local summon = Game.createMonster(summonName, summonPosition, true, false)
if summon then
summonStorage[summon:getId()] = true -- Dodaj summon do listy
summonPosition:sendMagicEffect(CONST_ME_TELEPORT)
end
end
end
end
-- Funkcja przywołująca potwory co 3 sekundy
local function summonOrcs(creatureId)
local creature = Creature(creatureId) -- Pobieramy obiekt Creature na podstawie ID
if not creature or not creature:isMonster() then
activeSummonProcess[creatureId] = nil -- Usuwamy proces summonowania, jeśli boss zginął
return
end
-- Jeśli osiągnięto maksymalną liczbę summonów, nie summonujemy więcej
if getSummonsCount() < maxSummons then
trySummonMonster(creature)
end
-- Ponowne wywołanie summonowania tylko, jeśli boss nadal istnieje
if creature then
activeSummonProcess[creatureId] = addEvent(summonOrcs, summonInterval, creatureId)
end
end
-- Główna funkcja rzucająca spell
function onCastSpell(creature, variant)
if not creature or not creature:isMonster() then
return false
end
local creatureId = creature:getId()
-- Zapobieganie wielokrotnemu uruchamianiu procesu summonowania
if not activeSummonProcess[creatureId] then
activeSummonProcess[creatureId] = addEvent(summonOrcs, summonInterval, creatureId)
end
return true
end
-- Rejestracja spella
local spell = Spell("instant")
spell:name("Summon Orcs")
spell:words("###summonOrcs")
spell:isAggressive(false)
spell:blockWalls(false)
spell:needLearn(false)
spell:needDirection(false)
spell:register()
Second:
Code:
-- Tablica globalna zapamiętująca, czy dany creatureId już przyzwał Queen
local summonedQueenFor = {} -- [creatureId] = true/false
-- Przy jakim % HP boss ma przyzwać Queen (możesz zmienić)
local SUMMON_HP_THRESHOLD = 75
function onCastSpell(creature, variant)
if not creature or not creature:isMonster() then
return false
end
local cid = creature:getId()
-- Jeśli nie mieliśmy jeszcze wpisu o tym potworze, inicjalizujemy go na false
if summonedQueenFor[cid] == nil then
summonedQueenFor[cid] = false
end
local hpPercent = (creature:getHealth() / creature:getMaxHealth()) * 100
-- Sprawdzamy, czy boss ma ≤ 75% HP
if hpPercent <= SUMMON_HP_THRESHOLD then
-- Jeżeli jeszcze nie przyzwał:
if not summonedQueenFor[cid] then
-- Oznaczamy, że od teraz "Queen" została przyzwana
summonedQueenFor[cid] = true
-- Tworzymy potwora "Queen" na pozycji bossa (albo obok)
Game.createMonster("Queen", creature:getPosition())
-- Opcjonalnie boss krzyczy
creature:say("The Queen has been summoned!", TALKTYPE_MONSTER_SAY)
end
end
return true
end