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

Lua [TFS 1.3] Addevent in raid script

E

Evil Puncker

Guest
Hi everyone, I really tried doing it myself before asking here, but I got no success, I was trying to achieve two things in this raid script:

  1. making the NORMAL raid spawn in 3 waves with 10 minutes between each one (for example 3 waves of 50 feverish citizen with 10 minutes and a message between each one)
  2. making a simple talkaction to force a raid execution based on the raid index if specified or random (I didn't even knew where to start)

Lua:
local raids = {
    -- Bosses
    [1]  = {type = "BOSS", position = Position(49, 172, 10), monster = "Demodras", message = "Demodras has spawned", chance = 3},
    [2]  = {type = "BOSS", position = Position(115, 88, 7), monster = "Grorlam", message = "Grorlam has spawned", chance = 2},
    [3]  = {type = "BOSS", position = Position(102, 41, 8), monster = "Rotworm Queen", message = "Rotworm Queen has spawned", chance = 2},

    -- Raids fromPos, toPos
    [4] = {type = "NORMAL", fromPos = Position(127, 35, 7), toPos = Position(184, 65, 7), monsters = {"minotaur", "minotaur guard", "minotaur mage", "minotaur archer"}, count = 50, message = "Minotaur assault incoming!", chance = 20},
    [5] = {type = "NORMAL", fromPos = Position(127, 35, 7), toPos = Position(184, 65, 7), monsters = "Feverish Citizen", count = 50, message = "Feverish Citizens have invaded the streets!", chance = 100},
}

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

local globalevent = GlobalEvent("SpawnRaid")

function globalevent.onThink(...)
    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

globalevent:interval(18000) -- will be executed every 1000ms
globalevent:register()


local talk = TalkAction("/raid")

function talk.onSay(player, words, param)
    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end
    --???
    return false
end

talk:separator(" ")
talk:register()
 
Back
Top