• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TFS 1.X+ raid globalevent tfs 1.3 summon wrong amount

Thorn

Spriting since 2013
Joined
Sep 24, 2012
Messages
2,203
Solutions
1
Reaction score
921
Location
Chile
Hello guys, im frustrated with a script i have, wich is a globalevent for massive raids, the thing about this, is that sometimes it summons all the amount of monsters i input, but sometimes it summons very few monsters, for instance i have a spider raid, and it should summon 2000 monsters in a full city, however now it just summoned no more than a hundred...when this happens, to run this again, i change the hour (works on exact hours every day) and do a reload and after that it summons the amount it should, this is the script, i really hope some of you have a clue of why this happens D:
i would appreaciate the help :(


Lua:
local cfg = {
    monsters = {'Tarantula', 'Spider','Poison Spider','Giant Spider','Crystal Spider','The Old Widowevent','Hide'},
    centerPos = Position(690, 1228, 7)
}
function onTime(interval)
    broadcastMessage("Los horribles aracnidos atacan Azurthis!!!Derrota a las old widow para sacar tokens!", MESSAGE_STATUS_WARNING)
    local pos = cfg.centerPos
    local monsterCount = math.random(2000) -- How many monsters will spawn?
    local spawned = 0
     for i = 1, monsterCount do
        local randX, randY = math.random(-120, 120), math.random(-50, 50)
        local spawnPosition = Position(pos.x + randX, pos.y + randY, pos.z)
        local tile = Tile(spawnPosition)
        if tile and (not tile:getHouse()) and (not (tile:getCreatureCount() > 0)) and (not tile:hasFlag(TILESTATE_PROTECTIONZONE)) then
            Game.createMonster(cfg.monsters[math.random(#cfg.monsters)], spawnPosition, true)
            spawned = spawned + 1
        end
    end
    return true
end

Code:
<globalevent name="arachnids" time="17:30:00" script="raids/arachnids.lua"/>
 
Solution
math.random(1900, 2000)
also you should iterate the amount of monsters spawned like
Lua:
local cfg = {
    monsters = {'Tarantula', 'Spider','Poison Spider','Giant Spider','Crystal Spider','The Old Widowevent','Hide'},
    centerPos = Position(690, 1228, 7)
}
function onTime(interval)
    broadcastMessage("Los horribles aracnidos atacan Azurthis!!!Derrota a las old widow para sacar tokens!", MESSAGE_STATUS_WARNING)
    local pos = cfg.centerPos
    local monsterCount = math.random(2000, 2100) -- How many monsters will spawn? between 2000 - 2100
    local spawned = 0
    while (spawned < monsterCount) do -- if the amount of monster created is lower than the amount of monster that we want
        local randX, randY = math.random(-120...
math.random(1900, 2000)
also you should iterate the amount of monsters spawned like
Lua:
local cfg = {
    monsters = {'Tarantula', 'Spider','Poison Spider','Giant Spider','Crystal Spider','The Old Widowevent','Hide'},
    centerPos = Position(690, 1228, 7)
}
function onTime(interval)
    broadcastMessage("Los horribles aracnidos atacan Azurthis!!!Derrota a las old widow para sacar tokens!", MESSAGE_STATUS_WARNING)
    local pos = cfg.centerPos
    local monsterCount = math.random(2000, 2100) -- How many monsters will spawn? between 2000 - 2100
    local spawned = 0
    while (spawned < monsterCount) do -- if the amount of monster created is lower than the amount of monster that we want
        local randX, randY = math.random(-120, 120), math.random(-50, 50)
        local spawnPosition = Position(pos.x + randX, pos.y + randY, pos.z)
        local tile = Tile(spawnPosition)
        if tile and (not tile:getHouse()) and (not (tile:getCreatureCount() > 0)) and (not tile:hasFlag(TILESTATE_PROTECTIONZONE)) then
            local create = Game.createMonster(cfg.monsters[math.random(#cfg.monsters)], spawnPosition, true)
            if create then
                spawned = spawned + 1
            end
        end
    end
    return true
end
 
Last edited:
Solution
math.random(1900, 2000)
also you should iterate the amount of monsters spawned like
Lua:
local cfg = {
    monsters = {'Tarantula', 'Spider','Poison Spider','Giant Spider','Crystal Spider','The Old Widowevent','Hide'},
    centerPos = Position(690, 1228, 7)
}
function onTime(interval)
    broadcastMessage("Los horribles aracnidos atacan Azurthis!!!Derrota a las old widow para sacar tokens!", MESSAGE_STATUS_WARNING)
    local pos = cfg.centerPos
    local monsterCount = math.random(2000, 2100) -- How many monsters will spawn? between 2000 - 2100
    local spawned = 0
    while (spawned < monsterCount) do -- if the amount of monster created is lower than the amount of monster that we want
        local randX, randY = math.random(-120, 120), math.random(-50, 50)
        local spawnPosition = Position(pos.x + randX, pos.y + randY, pos.z)
        local tile = Tile(spawnPosition)
        if tile and (not tile:getHouse()) and (not (tile:getCreatureCount() > 0)) and (not tile:hasFlag(TILESTATE_PROTECTIONZONE)) then
            local create = Game.createMonster(cfg.monsters[math.random(#cfg.monsters)], spawnPosition, true)
            if create then
                spawned = spawned + 1
            end
        end
    end
    return true
end
oohh i see, and is that while safe from infinite loop? :O i have had big headaches with crashes because of that D:
 
Ye, it will loop only until the random amount of monsters. Anyways you can add any kind of break there to check also some prints. Try to test it with lower amounts (19-20) to check if its working.
 
It is only "safe" given that the area in which you try to spawn the monsters is big enough.
If you try to spawn 2000 monsters in a 5x5 area, all tiles will be filled up shortly and since the scripts check for the amount of creatures on the tiles it will fail to spawn more.
Also, even if the area is big enough players could block all spots and cause the same issue.

To prevent that simply break the loop after X failed attempts to spawn a monster.
 
Back
Top