OTcreator
Active Member
- Joined
- Feb 14, 2022
- Messages
- 439
- Solutions
- 1
- Reaction score
- 48
Hi,
I use this script in TFS 1.4.2 buy monsters are duplicated.
No errors in consola.
What to change to make it check properly if the boss has already been respawned and to not respawn duplicates.
I use this script in TFS 1.4.2 buy monsters are duplicated.
No errors in consola.
What to change to make it check properly if the boss has already been respawned and to not respawn duplicates.
Lua:
local raids = {
-- Bosses
[1] = {type = 'BOSS', position = Position(32960, 32075, 6), monster = 'demodras', message = 'Demodras has spawned', chance = 30},
[2] = {type = 'BOSS', position = Position(998, 1006, 7), monster = 'orshabaal', chance = 40},
[3] = {type = 'BOSS', position = Position(998, 1006, 7), monster = 'ferumbras', chance = 30},
-- Raids fromPos, toPos
[4] = {type = 'NORMAL', fromPos = Position(997, 1005, 7), toPos = Position(1009, 1014, 7), monsters = {'orc', 'orc Spearman', 'orc warrior'}, count = 10, message = 'orcs raid', chance = 20},
[5] = {type = 'NORMAL', fromPos = Position(997, 1005, 7), toPos = Position(1009, 1014, 7), monsters = 'demon', count = 10, message = 'demons raid', chance = 50},
}
local spawnedBosses = {}
local function isSpawned(name)
for i = 1, #spawnedBosses do
local monster = Monster(spawnedBosses[i])
if monster and monster:getName():lower() == name then
return true
else
spawnedBosses[i] = nil
end
end
return false
end
function onThink(interval, lastExecution, thinkInterval)
local table = raids[math.random(#raids)]
if math.random(100) > table.chance then
return true
end
if table.type == 'BOSS' then
if not isSpawned(table.monster:lower()) then
local boss = Game.createMonster(table.monster, table.position, true, false)
if boss then
spawnedBosses[#spawnedBosses + 1] = boss:getId()
end
if table.message ~= nil then
broadcastMessage(table.message, MESSAGE_EVENT_ADVANCE)
end
end
elseif table.type == 'NORMAL' then
for i = 1, table.count do
local randomPosition = Position(math.random(table.fromPos.x, table.toPos.x), math.random(table.fromPos.y, table.toPos.y), table.fromPos.z)
if type(table.monsters) == 'string' then
Game.createMonster(table.monsters, randomPosition, true, false)
else
Game.createMonster(table.monsters[math.random(#table.monsters)], randomPosition, true, false)
end
end
if table.message ~= nil then
broadcastMessage(table.message, MESSAGE_EVENT_ADVANCE)
end
end
return true
end