• 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] Automatic/Manual Lua Raids (raids.xml replacement)

Homeslice

-anoyn/Rage the Mage
Joined
May 9, 2010
Messages
112
Solutions
2
Reaction score
65
Location
Canada
A Lua raid system designed to provide more features and customizability than raids.xml.

Features
Set individual raid's rarity
Delay before running said raid again
Delay before running after other raids
Require certain amount of online players
Delayed broadcast announcements
Delayed/Staged monster spawning
Spawn NPCs or Monsters
Individual/Multiple creature spawn(s) at a position or within an area
Automatically despawn creatures after X time passed
Talkaction to manually start raids

Enjoy.

Add to global.lua
Lua:
--Lua Raids by [email protected]
luaRaids = {
    ["intiri_swamp_raid"] = {
        --Automatic Raids - using the talkaction skips these checks.
        spawnInterval = 99000, --optional, 1000 = 1% chance per globalevent(GE) (10 min),
            --1440 min in a day / globalEvent interval (10 min) = 144 runs a day,
            --1% (chance) / 100 * 144 (GEs times run) = average of 1.44 of this raid, per day
        secondsBetweenRerunning = 86400,--optional, SECONDS, 86400 = 24 hours
        secondsBetweenOtherRaids = 1800,--optional, SECONDS, 3600 = 1 hour. Other raids includes this raid too.
        minPlayersOnline = 5, --optional, amount of players online for raid to occur
      
        --Raid Details
        --lastRunTime = TIME, Automatically created. Do not uncomment.
        announcements = { --optional, can set announcements to nil
            --{ delay = 0, message = "Test", broadcastType = MESSAGE_STATUS_CONSOLE_BLUE}, --broadcastType is optional
            { delay = 0, message = "Toxic smog is rising from the intiri swamp."},
            { delay = 70000, message = "Creatures from the intiri swamp are fleeing into town due to the toxic smog!"},
        },
        delayGroups = {--optional, give any creature a delayGroup of 1 to them spawning by 5000 MS or 5 seconds.
            20000,40000 --Milliseconds, first entry = delayGroup 1, second = 2...
        },
        msDespawnDelay = 20000, --Optional. In Milliseconds. 3600000 = 1 hour. Removes all creatures spawned by the raid.
        creatures = {
            --AVAILABLE PARAMETERS
            --spawnAmount, {from/to OR position}, delayGroup, force (forceSpawn/stack), and npc are optional
            --note: monsters with a from/to.x are not guranteed to be spawned by enabling force, but they will spawn/stack on other creatures.
            --    The force flag is guranteed to spawn monsters on a single position, providing the position is walkable.
          
            --{ name="Orc", position = {x = 1056, y = 1056, z = 7}, delayGroup = 1, force = true, npc=false },
            --{ name="Orc", from = {x = 1056, y = 1056, z = 7}, to = {x = 1058, y = 1058, z = 7}, delayGroup = 1, force = true },
            { name="Eryn", position = {x = 1056, y = 1056, z = 7}, force = false, npc=true },
            { name="Eryn", from = {x = 1056, y = 1056, z = 7}, to = {x = 1058, y = 1058, z = 7}, force = false, npc=true },
      
            { name="Orc Berserker", spawnAmount = 3, from = {x = 400, y = 125, z = 6}, to = {x = 405, y = 138, z = 6}, delayGroup = 1, force = true },
            { name="Orc Berserker", spawnAmount = 3, position = {x = 1056, y = 1056, z = 7}, delayGroup = 1, force = true },
        },
    },
}
--Dont edit anything below.
ranLuaRaids = {} -- [1]={ name = "intiri_swamp_raid", startTime = os.time(), creatures = { cid, cid, cid, cid }, despawnEvent = event }

luaRaidsChance = {
    lastRaidTime = 0,
    raidIntervalToCheckFirst = 1,--randomly generated, so always check different raid first
    raids = {},
}
luaRaidsAttemptsToFindValidTileToSpawnCreature = 10

for raidName,_ in pairs(luaRaids) do
    if luaRaids[raidName].spawnInterval ~= nil then
        luaRaidsChance.raids[#luaRaidsChance.raids+1] = {name = raidName, spawnInterval = luaRaids[raidName].spawnInterval}
    end
end

function delayedBroadcast(message, broadcastType)
    if broadcastType == nil then
        broadcastMessage(message, MESSAGE_STATUS_WARNING)
    else
        broadcastMessage(message, broadcastType)
    end
end

function delayedRaidDespawn(raidIndex)
    if ranLuaRaids[raidIndex] == nil then
        print("delayedRaidDespawn() Error: raidIndex of " .. raidIndex .. " in ranLuaRaids is nil. If you reloaded global ignore this.")
        return false
    end
    for creaturesIndex=1,#ranLuaRaids[raidIndex].creatures do
        local creature = Creature(ranLuaRaids[raidIndex].creatures[creaturesIndex])
        if creature ~= nil then
            creature:getPosition():sendMagicEffect(CONST_ME_POFF)
            creature:remove()
        end
    end
end

function startRaid(raidName)
    if luaRaids[raidName] ~= nil then
        luaRaids[raidName].lastRunTime = os.time()
        luaRaidsChance.lastRaidTime = os.time()
        local newRaidIndex = #ranLuaRaids+1
        ranLuaRaids[newRaidIndex] = { name = raidName, startTime = os.time(), creatures = {} }
        --despawn
        if luaRaids[raidName].msDespawnDelay ~= nil then
            ranLuaRaids[newRaidIndex].despawnEvent = addEvent(delayedRaidDespawn, luaRaids[raidName].msDespawnDelay, newRaidIndex)
        end
        --announcements
        if luaRaids[raidName].announcements ~= nil then
            for announcementIndex=1,#luaRaids[raidName].announcements do
                addEvent(delayedBroadcast,  luaRaids[raidName].announcements[announcementIndex].delay,
                    luaRaids[raidName].announcements[announcementIndex].message,  luaRaids[raidName].announcements[announcementIndex].broadcastType)
            end
        end
        --delayGroups
        if luaRaids[raidName].delayGroups ~= nil then
            for delayGroupIndex=1,#luaRaids[raidName].delayGroups do
                addEvent(spawnRaidGroup, luaRaids[raidName].delayGroups[delayGroupIndex], raidName, newRaidIndex, delayGroupIndex)
            end
        end
        spawnRaidGroup(raidName, newRaidIndex, nil)
        return newRaidIndex
    else
        return false
    end
end

function spawnCreatureInArea(creatureArr)
    local foundTile = nil
    local forcingSpawnEnabled = false
    local resultCreature = nil
    for findTileTries=1,luaRaidsAttemptsToFindValidTileToSpawnCreature*2 do
        foundTile = Tile(math.random(creatureArr.from.x, creatureArr.to.x),
            math.random(creatureArr.from.y, creatureArr.to.y),
            math.random(creatureArr.from.z, creatureArr.to.z))

        if foundTile ~= nil and foundTile:getGround() ~= nil and not foundTile:hasProperty(TILESTATE_NONE) and
            not foundTile:hasProperty(TILESTATE_PROTECTIONZONE) and (foundTile:getCreatureCount() == 0 or forcingSpawnEnabled) then

            if creatureArr.npc == nil or creatureArr.npc == false then
                resultCreature = Game.createMonster(creatureArr.name, foundTile:getPosition(), false, forcingSpawnEnabled)
            else
                resultCreature = Game.createNpc(creatureArr.name, foundTile:getPosition(), false, forcingSpawnEnabled)
            end
            if resultCreature ~= nil then
                return resultCreature
            end
        end
        if findTileTries > luaRaidsAttemptsToFindValidTileToSpawnCreature then
            if creatureArr.force then
                forcingSpawnEnabled = true
            else
                break
            end
        end
    end
end

function spawnRaidGroup(raidName, raidIndex, delayGroup)
    if ranLuaRaids[raidIndex] == nil then
        print("spawnRaidGroup() Error: raidIndex of " .. raidIndex .. " in ranLuaRaids is nil. If you reloaded global ignore this.")
        return false
    end
    for creaturesIndex=1,#luaRaids[raidName].creatures do
        if luaRaids[raidName].creatures[creaturesIndex].delayGroup == delayGroup then
            --Monster
            if luaRaids[raidName].creatures[creaturesIndex].npc == nil or luaRaids[raidName].creatures[creaturesIndex].npc == false then
              
                if luaRaids[raidName].creatures[creaturesIndex].spawnAmount == nil then
                    luaRaids[raidName].creatures[creaturesIndex].spawnAmount = 1
                end

                for monsterSpawnLoopIndex = 1, luaRaids[raidName].creatures[creaturesIndex].spawnAmount do
                    local monster = nil
                    if luaRaids[raidName].creatures[creaturesIndex].from ~= nil then
                        monster = spawnCreatureInArea(luaRaids[raidName].creatures[creaturesIndex])
                    else
                        local position = Position(luaRaids[raidName].creatures[creaturesIndex].position.x,
                            luaRaids[raidName].creatures[creaturesIndex].position.y, luaRaids[raidName].creatures[creaturesIndex].position.z)
                        if position then
                            monster = Game.createMonster(luaRaids[raidName].creatures[creaturesIndex].name, position, false,
                                luaRaids[raidName].creatures[creaturesIndex].force)
                        end
                    end
                  
                    if monster ~= nil then
                        monster:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
                        ranLuaRaids[raidIndex].creatures[#ranLuaRaids[raidIndex].creatures+1] = monster:getId()
                    else
                        print("spawnRaidGroup() Error: Could not spawn Monster " .. luaRaids[raidName].creatures[creaturesIndex].name ..
                            " for raid " .. raidName .. " at creatureIndex " .. creaturesIndex)
                    end
                end
            else --NPC
                local npc = nil
                if luaRaids[raidName].creatures[creaturesIndex].from ~= nil then
                    npc = spawnCreatureInArea(luaRaids[raidName].creatures[creaturesIndex])
                else
                    local position = Position(luaRaids[raidName].creatures[creaturesIndex].position.x,
                        luaRaids[raidName].creatures[creaturesIndex].position.y, luaRaids[raidName].creatures[creaturesIndex].position.z)
                    if position then
                        npc = Game.createNpc(luaRaids[raidName].creatures[creaturesIndex].name, position, false, forceSpawn)
                    end
                end

                if npc ~= nil then
                    npc:setMasterPos(npc:getPosition())
                    npc:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
                    ranLuaRaids[raidIndex].creatures[#ranLuaRaids[raidIndex].creatures+1] = npc:getId()
                else
                    print("spawnRaidGroup() Error: Could not spawn NPC " .. luaRaids[raidName].creatures[creaturesIndex].name ..
                        " for raid " .. raidName .. " at creatureIndex " .. creaturesIndex)
                end
            end     
        end
    end
end

function luaRaids_onThink(interval, lastExecution, thinkInterval)
    local loops = 0
    local raidIndex = math.random(1,#luaRaidsChance.raids)
    local raidToStart = nil
    while loops < #luaRaidsChance.raids and raidToStart == nil do
        if math.random(1, 100000) <= luaRaidsChance.raids[raidIndex].spawnInterval then
            --Check timeBetweenOtherRaids
            local currentTime = os.time()
            local raid = luaRaids[luaRaidsChance.raids[raidIndex].name]
            if (raid.secondsBetweenOtherRaids == nil or currentTime - luaRaidsChance.lastRaidTime > raid.secondsBetweenOtherRaids) and
                ((raid.secondsBetweenRerunning == nil or raid.lastRunTime == nil) or currentTime - raid.lastRunTime > raid.secondsBetweenRerunning) and
                (raid.minPlayersOnline == nil or raid.minPlayersOnline <= #Game.getPlayers() ) then
                raidToStart = luaRaidsChance.raids[raidIndex].name
            end         
        end
        loops = loops + 1 
        raidIndex = raidIndex + 1
        if raidIndex > #luaRaidsChance.raids then
            raidIndex = 1
        end
    end
    if raidToStart ~= nil then
        print("Randomly Starting Raid: " .. raidToStart)
        startRaid(raidToStart)
    end
    return true
end

create globalevents/scripts/lua_raids.lua
Lua:
function onThink(interval, lastExecution, thinkInterval)
    return luaRaids_onThink(interval, lastExecution, thinkInterval)
end

Globalevents.xml add the line:
Code:
<globalevent name="LuaRaids" interval="600000" script="lua_raids.lua"/> <!-- 600000=10 minutes -->

create talkactions/scripts/lua_raid.lua
Lua:
function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end

    local result = startRaid(param)
    if result == false then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Could not find a raid with that name.")
    else
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Raid Started.")
    end
    return false
end

talkactions.xml add the line:
Lua:
<talkaction words="/luaraid" separator=" " script="lua_raid.lua" />

How do I use it?
Edit the config
When you copy a position from RME, it gives you {x=0,y=0,z=0}. Perfect for pasting new monster positions into the config.

To use the talkaction
/luaraids intiri_swamp_raid

Tested with TFS 1.2.
 
Last edited by a moderator:
v1.1
Changes:
Added area spawning (from.xyz, to.xyz)
Fixed reloaded global error messages
 
Last edited by a moderator:
You can discuss that in github repo, would be nice to replace the default tfs one (i guess they intended that for 2.0 version).
 
v1.2
Changes:
Added spawnAmount parameter.
 
Last edited by a moderator:
A Lua raid system designed to provide more features and customizability than raids.xml.

Features
Set individual raid's rarity
Delay before running said raid again
Delay before running after other raids
Require certain amount of online players
Delayed broadcast announcements
Delayed/Staged monster spawning
Spawn NPCs or Monsters
Individual/Multiple creature spawn(s) at a position or within an area
Automatically despawn creatures after X time passed
Talkaction to manually start raids

Enjoy.

Add to global.lua
Lua:
--Lua Raids by [email protected]
luaRaids = {
    ["intiri_swamp_raid"] = {
        --Automatic Raids - using the talkaction skips these checks.
        spawnInterval = 99000, --optional, 1000 = 1% chance per globalevent(GE) (10 min),
            --1440 min in a day / globalEvent interval (10 min) = 144 runs a day,
            --1% (chance) / 100 * 144 (GEs times run) = average of 1.44 of this raid, per day
        secondsBetweenRerunning = 86400,--optional, SECONDS, 86400 = 24 hours
        secondsBetweenOtherRaids = 1800,--optional, SECONDS, 3600 = 1 hour. Other raids includes this raid too.
        minPlayersOnline = 5, --optional, amount of players online for raid to occur
     
        --Raid Details
        --lastRunTime = TIME, Automatically created. Do not uncomment.
        announcements = { --optional, can set announcements to nil
            --{ delay = 0, message = "Test", broadcastType = MESSAGE_STATUS_CONSOLE_BLUE}, --broadcastType is optional
            { delay = 0, message = "Toxic smog is rising from the intiri swamp."},
            { delay = 70000, message = "Creatures from the intiri swamp are fleeing into town due to the toxic smog!"},
        },
        delayGroups = {--optional, give any creature a delayGroup of 1 to them spawning by 5000 MS or 5 seconds.
            20000,40000 --Milliseconds, first entry = delayGroup 1, second = 2...
        },
        msDespawnDelay = 20000, --Optional. In Milliseconds. 3600000 = 1 hour. Removes all creatures spawned by the raid.
        creatures = {
            --AVAILABLE PARAMETERS
            --spawnAmount, {from/to OR position}, delayGroup, force (forceSpawn/stack), and npc are optional
            --note: monsters with a from/to.x are not guranteed to be spawned by enabling force, but they will spawn/stack on other creatures.
            --    The force flag is guranteed to spawn monsters on a single position, providing the position is walkable.
         
            --{ name="Orc", position = {x = 1056, y = 1056, z = 7}, delayGroup = 1, force = true, npc=false },
            --{ name="Orc", from = {x = 1056, y = 1056, z = 7}, to = {x = 1058, y = 1058, z = 7}, delayGroup = 1, force = true },
            { name="Eryn", position = {x = 1056, y = 1056, z = 7}, force = false, npc=true },
            { name="Eryn", from = {x = 1056, y = 1056, z = 7}, to = {x = 1058, y = 1058, z = 7}, force = false, npc=true },
     
            { name="Orc Berserker", spawnAmount = 3, from = {x = 400, y = 125, z = 6}, to = {x = 405, y = 138, z = 6}, delayGroup = 1, force = true },
            { name="Orc Berserker", spawnAmount = 3, position = {x = 1056, y = 1056, z = 7}, delayGroup = 1, force = true },
        },
    },
}
--Dont edit anything below.
ranLuaRaids = {} -- [1]={ name = "intiri_swamp_raid", startTime = os.time(), creatures = { cid, cid, cid, cid }, despawnEvent = event }

luaRaidsChance = {
    lastRaidTime = 0,
    raidIntervalToCheckFirst = 1,--randomly generated, so always check different raid first
    raids = {},
}
luaRaidsAttemptsToFindValidTileToSpawnCreature = 10

for raidName,_ in pairs(luaRaids) do
    if luaRaids[raidName].spawnInterval ~= nil then
        luaRaidsChance.raids[#luaRaidsChance.raids+1] = {name = raidName, spawnInterval = luaRaids[raidName].spawnInterval}
    end
end

function delayedBroadcast(message, broadcastType)
    if broadcastType == nil then
        broadcastMessage(message, MESSAGE_STATUS_WARNING)
    else
        broadcastMessage(message, broadcastType)
    end
end

function delayedRaidDespawn(raidIndex)
    if ranLuaRaids[raidIndex] == nil then
        print("delayedRaidDespawn() Error: raidIndex of " .. raidIndex .. " in ranLuaRaids is nil. If you reloaded global ignore this.")
        return false
    end
    for creaturesIndex=1,#ranLuaRaids[raidIndex].creatures do
        local creature = Creature(ranLuaRaids[raidIndex].creatures[creaturesIndex])
        if creature ~= nil then
            creature:getPosition():sendMagicEffect(CONST_ME_POFF)
            creature:remove()
        end
    end
end

function startRaid(raidName)
    if luaRaids[raidName] ~= nil then
        luaRaids[raidName].lastRunTime = os.time()
        luaRaidsChance.lastRaidTime = os.time()
        local newRaidIndex = #ranLuaRaids+1
        ranLuaRaids[newRaidIndex] = { name = raidName, startTime = os.time(), creatures = {} }
        --despawn
        if luaRaids[raidName].msDespawnDelay ~= nil then
            ranLuaRaids[newRaidIndex].despawnEvent = addEvent(delayedRaidDespawn, luaRaids[raidName].msDespawnDelay, newRaidIndex)
        end
        --announcements
        if luaRaids[raidName].announcements ~= nil then
            for announcementIndex=1,#luaRaids[raidName].announcements do
                addEvent(delayedBroadcast,  luaRaids[raidName].announcements[announcementIndex].delay,
                    luaRaids[raidName].announcements[announcementIndex].message,  luaRaids[raidName].announcements[announcementIndex].broadcastType)
            end
        end
        --delayGroups
        if luaRaids[raidName].delayGroups ~= nil then
            for delayGroupIndex=1,#luaRaids[raidName].delayGroups do
                addEvent(spawnRaidGroup, luaRaids[raidName].delayGroups[delayGroupIndex], raidName, newRaidIndex, delayGroupIndex)
            end
        end
        spawnRaidGroup(raidName, newRaidIndex, nil)
        return newRaidIndex
    else
        return false
    end
end

function spawnCreatureInArea(creatureArr)
    local foundTile = nil
    local forcingSpawnEnabled = false
    local resultCreature = nil
    for findTileTries=1,luaRaidsAttemptsToFindValidTileToSpawnCreature*2 do
        foundTile = Tile(math.random(creatureArr.from.x, creatureArr.to.x),
            math.random(creatureArr.from.y, creatureArr.to.y),
            math.random(creatureArr.from.z, creatureArr.to.z))

        if foundTile ~= nil and foundTile:getGround() ~= nil and not foundTile:hasProperty(TILESTATE_NONE) and
            not foundTile:hasProperty(TILESTATE_PROTECTIONZONE) and (foundTile:getCreatureCount() == 0 or forcingSpawnEnabled) then

            if creatureArr.npc == nil or creatureArr.npc == false then
                resultCreature = Game.createMonster(creatureArr.name, foundTile:getPosition(), false, forcingSpawnEnabled)
            else
                resultCreature = Game.createNpc(creatureArr.name, foundTile:getPosition(), false, forcingSpawnEnabled)
            end
            if resultCreature ~= nil then
                return resultCreature
            end
        end
        if findTileTries > luaRaidsAttemptsToFindValidTileToSpawnCreature then
            if creatureArr.force then
                forcingSpawnEnabled = true
            else
                break
            end
        end
    end
end

function spawnRaidGroup(raidName, raidIndex, delayGroup)
    if ranLuaRaids[raidIndex] == nil then
        print("spawnRaidGroup() Error: raidIndex of " .. raidIndex .. " in ranLuaRaids is nil. If you reloaded global ignore this.")
        return false
    end
    for creaturesIndex=1,#luaRaids[raidName].creatures do
        if luaRaids[raidName].creatures[creaturesIndex].delayGroup == delayGroup then
            --Monster
            if luaRaids[raidName].creatures[creaturesIndex].npc == nil or luaRaids[raidName].creatures[creaturesIndex].npc == false then
             
                if luaRaids[raidName].creatures[creaturesIndex].spawnAmount == nil then
                    luaRaids[raidName].creatures[creaturesIndex].spawnAmount = 1
                end

                for monsterSpawnLoopIndex = 1, luaRaids[raidName].creatures[creaturesIndex].spawnAmount do
                    local monster = nil
                    if luaRaids[raidName].creatures[creaturesIndex].from ~= nil then
                        monster = spawnCreatureInArea(luaRaids[raidName].creatures[creaturesIndex])
                    else
                        local position = Position(luaRaids[raidName].creatures[creaturesIndex].position.x,
                            luaRaids[raidName].creatures[creaturesIndex].position.y, luaRaids[raidName].creatures[creaturesIndex].position.z)
                        if position then
                            monster = Game.createMonster(luaRaids[raidName].creatures[creaturesIndex].name, position, false,
                                luaRaids[raidName].creatures[creaturesIndex].force)
                        end
                    end
                 
                    if monster ~= nil then
                        monster:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
                        ranLuaRaids[raidIndex].creatures[#ranLuaRaids[raidIndex].creatures+1] = monster:getId()
                    else
                        print("spawnRaidGroup() Error: Could not spawn Monster " .. luaRaids[raidName].creatures[creaturesIndex].name ..
                            " for raid " .. raidName .. " at creatureIndex " .. creaturesIndex)
                    end
                end
            else --NPC
                local npc = nil
                if luaRaids[raidName].creatures[creaturesIndex].from ~= nil then
                    npc = spawnCreatureInArea(luaRaids[raidName].creatures[creaturesIndex])
                else
                    local position = Position(luaRaids[raidName].creatures[creaturesIndex].position.x,
                        luaRaids[raidName].creatures[creaturesIndex].position.y, luaRaids[raidName].creatures[creaturesIndex].position.z)
                    if position then
                        npc = Game.createNpc(luaRaids[raidName].creatures[creaturesIndex].name, position, false, forceSpawn)
                    end
                end

                if npc ~= nil then
                    npc:setMasterPos(npc:getPosition())
                    npc:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
                    ranLuaRaids[raidIndex].creatures[#ranLuaRaids[raidIndex].creatures+1] = npc:getId()
                else
                    print("spawnRaidGroup() Error: Could not spawn NPC " .. luaRaids[raidName].creatures[creaturesIndex].name ..
                        " for raid " .. raidName .. " at creatureIndex " .. creaturesIndex)
                end
            end    
        end
    end
end

function luaRaids_onThink(interval, lastExecution, thinkInterval)
    local loops = 0
    local raidIndex = math.random(1,#luaRaidsChance.raids)
    local raidToStart = nil
    while loops < #luaRaidsChance.raids and raidToStart == nil do
        if math.random(1, 100000) <= luaRaidsChance.raids[raidIndex].spawnInterval then
            --Check timeBetweenOtherRaids
            local currentTime = os.time()
            local raid = luaRaids[luaRaidsChance.raids[raidIndex].name]
            if (raid.secondsBetweenOtherRaids == nil or currentTime - luaRaidsChance.lastRaidTime > raid.secondsBetweenOtherRaids) and
                ((raid.secondsBetweenRerunning == nil or raid.lastRunTime == nil) or currentTime - raid.lastRunTime > raid.secondsBetweenRerunning) and
                (raid.minPlayersOnline == nil or raid.minPlayersOnline <= #Game.getPlayers() ) then
                raidToStart = luaRaidsChance.raids[raidIndex].name
            end        
        end
        loops = loops + 1
        raidIndex = raidIndex + 1
        if raidIndex > #luaRaidsChance.raids then
            raidIndex = 1
        end
    end
    if raidToStart ~= nil then
        print("Randomly Starting Raid: " .. raidToStart)
        startRaid(raidToStart)
    end
    return true
end

create globalevents/scripts/lua_raids.lua
Lua:
function onThink(interval, lastExecution, thinkInterval)
    return luaRaids_onThink(interval, lastExecution, thinkInterval)
end

Globalevents.xml add the line:
Code:
<globalevent name="LuaRaids" interval="600000" script="lua_raids.lua"/> <!-- 600000=10 minutes -->

create talkactions/scripts/lua_raid.lua
Lua:
function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end

    local result = startRaid(param)
    if result == false then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Could not find a raid with that name.")
    else
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Raid Started.")
    end
    return false
end

talkactions.xml add the line:
Lua:
<talkaction words="/luaraid" separator=" " script="lua_raid.lua" />

How do I use it?
Edit the config
When you copy a position from RME, it gives you {x=0,y=0,z=0}. Perfect for pasting new monster positions into the config.

To use the talkaction
/luaraids intiri_swamp_raid

Tested with TFS 1.2.
Would this system have TFS 0.4? I liked the option of announcements
 
Hello,

is there a way to print a Text when the Despawn is going to happen, like 3 min before DeSpawning "The raid is going to end soon"?

Thx!

Also, why does it not start another (same raid) again after the first one is spawn and deSpawn after the set time in Globalevents.xml ?
 
Last edited:
Back
Top