• 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!

GlobalEvent TFS 1.3 Monster Wave Event

!!THE MAIN POST HAS BEEN UPDATED WITH FIXES!!



Search for

Lua:
addEvent(proccessWave, 60 * 1000)

change to

Lua:
addEvent(MW_proccessWave, 60 * 1000)
Post automatically merged:

Try with these fixes

lib
Lua:
---- DONT TOUCH ---
MW_STATUS = 0
MW_PLAYERS = {}
MW_MONSTERS = {}
local MW_WAVE = 1
-------------------

--- CONFIG ----
MW_minLevel = 50 -- Player must be this level to enter event --
MW_positionEnter = Position(1000, 1000, 7) -- Wait area for event to start position --
MW_positionLeave = Position(1000, 1000, 7) -- Exit waiting area position --
local MW_minPlayersToStart = 5 -- How many people are required for event to start --
local MW_firstWaveStart = 30 -- 30 seconds for the first wave to start --
local MW_reTryEvent = 60 -- Time in minutes to retry the event if there are not enough players --
local MW_startEventAgain = 60 -- Start the event again after 60 minutes --
---------------

local MW_PLAYER_TELEPORT_TO = { -- Teleport players to this area for event --
    min = Position(1000, 1000, 7), -- Top left square of area --
    max = Position(1000, 1000, 7) -- bottom right square of area --
}

local MONSTER_WAVES = {
    [1] = {exp = 20000, waitTimeBoss = 60,
        monsters = {
            {"Cyclops", Position(1000, 1000, 7)},
            {"Cyclops", Position(1000, 1000, 7)},
            {"Cyclops", Position(1000, 1000, 7)},
            {"Cyclops Drone", Position(1000, 1000, 7)},
            {"Cyclops Drone", Position(1000, 1000, 7)}
        },
        boss = { -- Boss is spawned after waitTimeBoss seconds after the wave is stated --
            {"Cyclops Smith", Position(1000, 1000, 7)}
        },
        itemRewards = { -- Items rewarded for completing the wave. --
            {2152, 50},
            {2160, 1}
        },
        outfitReward = {male = 260, female = 261, addons = 0, name = "Citizen"}, -- outfit rewards for completing the wave --
        mountReward = {126, "Horse"}
    } -- You can delete any of the values to remove it from the wave. exp, itemreward, boss, outfitreward, mountreward (DO NOT DELETE THE monsters TABLE) --

    -- [2]

}

function MW_sendMessage(msgType, msg)
    for i = 1, #MW_PLAYERS do
        local player = Player(MW_PLAYERS[i])
        if player then
            player:sendTextMessage(msgType, "")
        end
    end
end

function MW_teleportPlayers()
    for i = 1, #MW_PLAYERS do
        local player = Player(MW_PLAYERS[i])
        if player then
            local position = Position(math.random(MW_PLAYER_TELEPORT_TO.min.x, MW_PLAYER_TELEPORT_TO.max.x),math.random(MW_PLAYER_TELEPORT_TO.min.y, MW_PLAYER_TELEPORT_TO.max.y), MW_PLAYER_TELEPORT_TO.min.z)
            player:teleportTo(position)
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "Welcome to monster wave event. It will begin in "..MW_firstWaveStart.." seconds.")
        end
    end
end

function MW_tryEvent()
    if #MW_PLAYERS < MW_minPlayersToStart then
        MW_sendMessage(MESSAGE_STATUS_CONSOLE_RED, "There are not enough players for the event to start. The event will try again after "..MW_reTryEvent.." minutes.")
        addEvent(MW_tryEvent, MW_reTryEvent * 60 * 1000)
        return true
    end

    MW_teleportPlayers()
    MW_STATUS = 2
    addEvent(MW_startWave, MW_firstWaveStart  * 1000)
end

function MW_checkMonsters()
    for i = 1, #MW_MONSTERS do
        local monster = Monster(MW_MONSTERS[i])
        if monster then
            return true
        end
    end
    return false
end

function MW_removeMonsters()
    for i = 1, #MW_MONSTERS do
        local monster = Monster(MW_MONSTERS[i])
        if monster then
            monster:remove()
        end
        MW_MONSTERS[i] = nil
    end
end

function MW_startWave()
    local WAVE = MONSTER_WAVES[MW_WAVE]

    for i = 1, #WAVE.monsters do
        local MONS = Game.createMonster(WAVE.monsters[i][1], WAVE.monsters[i][2])
        if not MW_MONSTERS[1] then
            MW_MONSTERS[1] = MONS:getId()
        else
            MW_MONSTERS[#MW_MONSTERS + 1] = MONS:getId()
        end
    end

    MW_sendMessage(MESSAGE_STATUS_CONSOLE_BLUE, "The wave has spawned. Kill all monsters for the next wave to begin.")

    if WAVE.boss then
        addEvent(MW_spawnBosses, WAVE.waitTimeBoss * 1000)
        MW_sendMessage(MESSAGE_STATUS_CONSOLE_BLUE, "This waves bosses will spawn in "..WAVE.waitTimeBoss.." seconds.")
    end

    addEvent(MW_proccessWave, 60 * 1000)
end

function MW_addOutfitReward(WAVE, player)
    if player:getSex() == 0 then
        player:addOutfit(WAVE.outfitReward.female)
        if addons > 0 then
            for x = 1, addons do
                player:addOutfitAddons(WAVE.outfitReward.female, x)
            end
        end
    else
        player:addOutfit(WAVE.outfitReward.male)
        if addons > 0 then
            for x = 1, addons do
                player:addOutfitAddons(WAVE.outfitReward.male, x)
            end
        end
    end
end

function MW_spawnBosses(waveTable)
    for i = 1, #waveTable.boss do
        local MONS = Game.createMonster(waveTable.boss[1], waveTable.boss[2])
        if MONS then
             MW_MONSTERS[#MW_MONSTERS + 1] = MONS:getId()
        end
    end
end

function MW_proccessWave()
    if MW_checkMonsters() then
        MW_sendMessage(MESSAGE_STATUS_CONSOLE_RED, "There are still monsters left to kill. Kill them to start the next wave.")
        addEvent(MW_proccessWave, 60 * 1000)
        return true
    end

    local WAVE = MONSTER_WAVES[MW_WAVE]

    local text = "[WAVE REWARD]:"

    if WAVE.exp then
        for i = 1, #MW_PLAYERS do
            local player = Player(MW_PLAYERS[i])
            if player then
                if i == 1 then
                    text = text.." "..WAVE.exp.." experience."
                end
                player:addExperience(WAVE.exp)
            end
        end
    end

    if WAVE.outfitReward then
        for i = 1, #MW_PLAYERS do
            local player = Player(MW_PLAYERS[i])
            if player then
                if i == 1 then
                    text = text.." "..WAVE.outfitReward.name.." outfit."
                end
                MW_addOutfitReward(WAVE, player)
            end
        end
    end

    if WAVE.mountReward then
        for i = 1, #MW_PLAYERS do
            local player = Player(MW_PLAYERS[i])
            if player then
                if i == 1 then
                    text = text.." "..WAVE.mountReward[2].." mount."
                end
                player:addMount(WAVE.mountReward[1])
            end
        end
    end

    MW_sendMessage(MESSAGE_STATUS_CONSOLE_RED, text)
    MW_WAVE = MW_WAVE + 1
    MW_removeMonsters()

    if not MONSTER_WAVES[MW_WAVE] then
        MW_sendMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Well done. You completed all waves. The event will end in 30 seconds!")
        MW_STATUS = 3
        addEvent(MW_endEvent, 30 * 1000)
        return true
    end

    MW_sendMessage(MESSAGE_STATUS_CONSOLE_BLUE, "The next wave will spawn in 1 minute.")
    addEvent(MW_startWave, 60 * 1000)
end

function MW_endEvent()
    for i = 1, #MW_PLAYERS do
        local player = Player(MW_PLAYERS[i])
        if player then
            player:teleportTo(MW_positionLeave)
        end
        MW_PLAYERS[i] = nil
    end

    MW_removeMonsters()
    addEvent(MW_restartEvent, MW_startEventAgain * 60 * 1000)
end

function MW_restartEvent()
    MW_STATUS = 0
end

movement
Lua:
local aidEnter = 1510 -- ActionID of teleport/tile to enter the event waiting area
local aidLeave = 1511 -- ActionId of teleport/tile to leave the event waiting area

function onStepIn(creature, item, position, fromPosition)
    local player = Player(creature)

    if not player then creature:teleportTo(fromPosition) return true end

    if item.actionid == aidEnter then
        if MW_STATUS ~= 1 then
            player:teleportTo(fromPosition)
            player:sendCancelMessage("Monster wave event is not open.")
            return true
        end
  
        if player:getLevel() < MW_minLevel then
            player:teleportTo(fromPosition)
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "You must be level "..MW_minLevel.." to enter this event.")
        else
            player:teleportTo(MW_positionEnter)
            if not MW_PLAYERS[1] then
                MW_PLAYERS[1] = player:getName()
            else
                MW_PLAYERS[#MW_PLAYERS + 1] = player:getName()
            end
        end
    else
        for i = 1, #MW_PLAYERS do
            if MW_PLAYERS[i] == player:getName() then
                MW_PLAYERS[i] = nil
            end
        end
  
        player:teleportTo(MW_positionLeave)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "You will no longer paticipate in the event.")
    end
    return true
end


If you dont have it add

Lua:
function MW_spawnBosses(waveTable)
    for i = 1, #waveTable.boss do
        local MONS = Game.createMonster(waveTable.boss[1], waveTable.boss[2])
        MW_MONSTERS[#MW_MONSTERS + 1] = MONS:getId()
    end
end

after the MW_spawnWave function

also change

Lua:
addEvent(spawnBosses, WAVE.waitTimeBoss * 1000)

to

Lua:
addEvent(MW_spawnBosses, WAVE.waitTimeBoss * 1000, WAVE)
 
Last edited:
Lib
Line 34 (there was a , missing)
Lua:
        },
Line 76
Lua:
    addEvent(MW_startWave, MW_firstWaveStart * 60 * 1000)
Doesn't this mean the wave wil start after 30 mins instead of 30 seconds?

I'm getting this error now (with your latest fixes)
1609586675702.png(
 
replace (main post edited)

Lua:
function MW_spawnBosses(waveTable)
    for i = 1, #waveTable.boss do
        local MONS = Game.createMonster(waveTable.boss[1], waveTable.boss[2])
        MW_MONSTERS[#MW_MONSTERS + 1] = MONS:getId()
    end
end

with

Lua:
function MW_spawnBosses(waveTable)
    for i = 1, #waveTable.boss do
        local MONS = Game.createMonster(waveTable.boss[1], waveTable.boss[2])
        if MONS then
              MW_MONSTERS[#MW_MONSTERS + 1] = MONS:getId()
        end
    end
end
 
Programmers always have so fragile ego, I don't get it. Code whatever you want, code however you want, just please if you code it for someone (or for yourself too), make sure it's readable for other programmers.
 
Programmers always have so fragile ego, I don't get it. Code whatever you want, code however you want, just please if you code it for someone (or for yourself too), make sure it's readable for other programmers.
Kinda late for this msg lol
 
waveeventerrors.PNG

Once first wave is killed I get this error

Edit: Fixed these error messages but I am not receiving any wave messages and the boss isn't spawning, any ideas?
Also no rewards are given out once player is done with the waves.
 
Last edited:
Try changing the message type to something else everywhere there is MW_sendMessage

What TFS are you using?
 
Try changing the message type to something else everywhere there is MW_sendMessage

What TFS are you using?

Downgraded 8.6 TFS 1.3

Seems like the MW_sendMessage function doesn't work at all for some reason, i receive the "Welcome to monster wave event. It will begin in "..MW_firstWaveStart.." seconds." message but that is all as it doesn't call on the MW_sendMessage..
 
Change
Lua:
function MW_sendMessage(msgType, msg)
    for i = 1, #MW_PLAYERS do
        local player = Player(MW_PLAYERS[i])
        if player then
            player:sendTextMessage(msgType, "")
        end
    end
end

to

Lua:
function MW_sendMessage(msgType, msg)
    for i = 1, #MW_PLAYERS do
        local player = Player(MW_PLAYERS[i])
        if player then
            player:sendTextMessage(msgType, msg)
        end
    end
end
 
Change
Lua:
function MW_sendMessage(msgType, msg)
    for i = 1, #MW_PLAYERS do
        local player = Player(MW_PLAYERS[i])
        if player then
            player:sendTextMessage(msgType, "")
        end
    end
end

to

Lua:
function MW_sendMessage(msgType, msg)
    for i = 1, #MW_PLAYERS do
        local player = Player(MW_PLAYERS[i])
        if player then
            player:sendTextMessage(msgType, msg)
        end
    end
end

Thank you! Messages working fine now, just no bosses or item rewards, i couldn't see anything that refers to itemRewards in the config though(sorry for being a noob haha)
 
replace

Lua:
function MW_spawnBosses(waveTable)
    for i = 1, #waveTable.boss do
        local MONS = Game.createMonster(waveTable.boss[1], waveTable.boss[2])
        MW_MONSTERS[#MW_MONSTERS + 1] = MONS:getId()
    end
end
[code]

[code=lua]
function MW_spawnBosses(waveTable)
    for i = 1, #waveTable.boss do
        local MONS = Game.createMonster(waveTable[i].boss[1], waveTable[i].boss[2])
        MW_MONSTERS[#MW_MONSTERS + 1] = MONS:getId()
    end
end
 
replace

Lua:
function MW_spawnBosses(waveTable)
    for i = 1, #waveTable.boss do
        local MONS = Game.createMonster(waveTable.boss[1], waveTable.boss[2])
        MW_MONSTERS[#MW_MONSTERS + 1] = MONS:getId()
    end
end
[code]

[code=lua]
function MW_spawnBosses(waveTable)
    for i = 1, #waveTable.boss do
        local MONS = Game.createMonster(waveTable[i].boss[1], waveTable[i].boss[2])

[/QUOTE]


errror.PNG

Getting this error now..
Also if there is any fields in the way of the next spawn it will bug the next wave and the event won't continue, i added this basic function to correct it:
Credit to Infernum
Lua:
function MW_CleanFields()
local area = {
      fromPos = {x = 32470, y = 32315, z = 9},
      toPos = {x = 32479, y = 32322, z = 9}
  }

local tileCache = {}

local itemIds = {1487, 1486,1485,1490,1491,1497}
    -- initialize tiles we need to clean, store all tiles in a cache to avoid reconstructing them in the future
    if #tileCache == 0 then
        for x = area.fromPos.x, area.toPos.x do
            for y = area.fromPos.y, area.toPos.y do
                for z = area.fromPos.z, area.toPos.z do
                    tileCache[#tileCache+1] = Tile(x, y, z)
                end
            end
        end
    end
    -- clean based off of cache
    for i = 1, #tileCache do
        local items = tileCache[i]:getItems()
        if items and next(items) then
            for index = 1, #items do
                local item = items[index]
                if table.contains(itemIds, item:getId()) then
                    item:remove()
                end
            end
        end
    end
    return true
end

then added the event below:
Lua:
    MW_sendMessage(MESSAGE_STATUS_CONSOLE_BLUE, "The next wave will spawn in 15 seconds.")
    addEvent(MW_startWave, 15 * 1000)
    addEvent(MW_CleanFields, 5 * 1000)
 
Last edited:
replace

Lua:
function MW_spawnBosses(waveTable)
    for i = 1, #waveTable.boss do
        local MONS = Game.createMonster(waveTable.boss[1], waveTable.boss[2])
        MW_MONSTERS[#MW_MONSTERS + 1] = MONS:getId()
    end
end
[code]

[code=lua]
function MW_spawnBosses(waveTable)
    for i = 1, #waveTable.boss do
        local MONS = Game.createMonster(waveTable[i].boss[1], waveTable[i].boss[2])
        MW_MONSTERS[#MW_MONSTERS + 1] = MONS:getId()
    end
end
Sem título.png
solucion?

funcion erro:
function MW_spawnBosses(waveTable)
for i = 1, #waveTable.boss do
local MONS = Game.createMonster(waveTable.boss[1], waveTable.boss[2])
MW_MONSTERS[#MW_MONSTERS + 1] = MONS:getId()
end
end
 
View attachment 53843
solucion?

funcion erro:


I was receiving the same error, try this:

Lua:
function MW_spawnBosses()
    local WAVE = MONSTER_WAVES[MW_WAVE]
  
    for i = 1, #WAVE.boss do
        local MONS = Game.createMonster(WAVE.boss[i][1], WAVE.boss[i][2])
        if not MW_MONSTERS[1] then
            MW_MONSTERS[1] = MONS:getId()
        else
            MW_MONSTERS[#MW_MONSTERS + 1] = MONS:getId()
        end
    end
  
    MW_sendMessage(MESSAGE_STATUS_CONSOLE_BLUE, "The boss has spawned!")
    end
 
I was receiving the same error, try this:

Lua:
function MW_spawnBosses()
    local WAVE = MONSTER_WAVES[MW_WAVE]
 
    for i = 1, #WAVE.boss do
        local MONS = Game.createMonster(WAVE.boss[i][1], WAVE.boss[i][2])
        if not MW_MONSTERS[1] then
            MW_MONSTERS[1] = MONS:getId()
        else
            MW_MONSTERS[#MW_MONSTERS + 1] = MONS:getId()
        end
    end
 
    MW_sendMessage(MESSAGE_STATUS_CONSOLE_BLUE, "The boss has spawned!")
    end
View attachment 53803

Once first wave is killed I get this error

Edit: Fixed these error messages but I am not receiving any wave messages and the boss isn't spawning, any ideas?
Also no rewards are given out once player is done with the waves.
solucion?
 
Back
Top