• 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 Raid Call Off in TFS 1.3

Berciq

Veteran OT User
Joined
Aug 7, 2018
Messages
292
Reaction score
354
Location
Poland
Hey, I have simple raid on rookgaard that rats appear in waves on specified area.
I wanted to call off this raid when after 30 minutes rats has not been slayed.
I also wanted to reward participants if they killed all the rats and then to call it off.

I recieve error in server console:

Error: [ScriptEvent::configureRaidEvent] No script file found for raid
[Error - Raid::loadFromXml] In file (data/raids/rookrats.xml), eventNode: script

This is how my raid xml looks (without 3 last lines it worked):
XML:
<?xml version="1.0" encoding="UTF-8"?>

<raid>
    <announce delay="0" type="event" message="Few rats in Rookgaard village. PLX HALP!" />
    <areaspawn delay="1000" fromx="650" fromy="530" fromz="7" tox="574" toy="486" toz="7">
        <monster name="rat" amount="5" />
    </areaspawn>

    <announce delay="60000" type="event" message="Rats are attacking Rookgaard!" />
    <areaspawn delay="61000" fromx="650" fromy="530" fromz="7" tox="574" toy="486" toz="7">
        <monster name="rat" amount="5" />
    </areaspawn>

    <announce delay="180000" type="event" message="Rat plague Rookgaard needs help!" />
    <areaspawn delay="181000" fromx="650" fromy="530" fromz="7" tox="574" toy="486" toz="7">
        <monster name="rat" amount="10" />
    </areaspawn>

    <announce delay="360000" type="event" message="Final Wave! Rats came out of caves in Rook! Situation is terrible!" />
    <areaspawn delay="361000" fromx="650" fromy="530" fromz="7" tox="574" toy="486" toz="7">
        <monster name="cave rat" amount="10" />
        <monster name="rat" amount="10" />
    </areaspawn>

    <!-- Zapowiedź końca raidu 10 minut przed jego zakończeniem -->
    <announce delay="1680000" type="event" message="Rats on Rookgaard started retreating!" />

    <!-- Informacja o zakończeniu/odwołaniu rajdu -->
    <announce delay="1800000" type="event" message="The rat threat on Rookgaard has been eliminated!" />

    <!-- Wywołanie skryptu LUA do obsługi rajdu -->
    <script event="script" file="actions/scripts/rookgaard/rat_plague.lua" delay="1800000" />
</raid>

And this is my lua script, put in actions/scripts/rookgaard (but not registerd in actions.xml)
LUA:
local killCounts = {}  -- Tablica do przechowywania liczby zabitych szczurów przez graczy
                      -- Array to store the number of rats killed by players

-- Nagrody
-- Rewards
local rewardLastKiller = {  -- Nagroda za zabicie ostatniego szczura
                            -- Reward for killing the last rat
    {2148, 40},  -- 40 złotych monet
                 -- 40 gold coins
    {2696, 6}    -- 6 Cheese
                 -- 6 Cheese
}

local rewardMostKills = {  -- Nagroda za zabicie najwięcej szczurów
                            -- Reward for killing the most rats
    {2148, 100},  -- 100 złotych monet
                  -- 100 gold coins
    {12344, 5}    -- 5 Rat Cheese
                  -- 5 Rat Cheese
}

local rewardParticipants = {  -- Nagroda dla wszystkich, którzy brali udział
                               -- Reward for all participants
    {2148, 20},  -- 20 złotych monet
                 -- 20 gold coins
    {2696, 3}    -- 3 Cheese
                 -- 3 Cheese
}

-- Funkcja wywoływana przy zabiciu szczura
-- Function called when a rat is killed
function onKill(creature, target)
    if not target:isMonster() then
        return true
    end

    local monsterName = target:getName():lower()
    if monsterName == "rat" or monsterName == "cave rat" then
        -- Zliczanie zabitych szczurów
        -- Counting the number of rats killed
        if not killCounts[creature:getId()] then
            killCounts[creature:getId()] = 0
        end
        killCounts[creature:getId()] = killCounts[creature:getId()] + 1

        -- Sprawdzenie, czy wszystkie szczury zostały zabite
        -- Checking if all rats have been killed
        local remainingMonsters = Game.getSpectators(Position(650, 530, 7), false, true, Position(574, 486, 7))
        local ratsLeft = false

        for _, monster in ipairs(remainingMonsters) do
            if monster:getName():lower() == "rat" or monster:getName():lower() == "cave rat" then
                ratsLeft = true
                break
            end
        end

        if not ratsLeft then
            -- Ostatni szczur zabity, nagradzamy gracza
            -- Last rat killed, rewarding the player
            -- Nagroda za zabicie ostatniego szczura
            -- Reward for killing the last rat
            for _, reward in ipairs(rewardLastKiller) do
                creature:addItem(reward[1], reward[2])
            end
            -- Komunikat dla gracza, który zabił ostatniego szczura
            -- Message to the player who killed the last rat
            creature:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Congratulations! You killed the last rat and saved Rookgaard!")
            Game.broadcastMessage("The last rat on Rookgaard has been slain by " .. creature:getName() .. "!", MESSAGE_EVENT_ADVANCE)
            Game.broadcastMessage("The rat threat on Rookgaard has been eliminated!", MESSAGE_EVENT_ADVANCE)

            -- Nagradzanie graczy, którzy zabili najwięcej szczurów
            -- Rewarding players who killed the most rats
            local mostKillsPlayers = {}  -- Tablica do przechowywania graczy z największą liczbą zabitych szczurów
                                        -- Array to store players with the most rat kills
            local mostKills = 0
            for playerId, killCount in pairs(killCounts) do
                local player = Player(playerId)
                if player and killCount > mostKills then
                    mostKills = killCount
                    mostKillsPlayers = {player}  -- Zresetowanie tablicy, bo znalazł się gracz z większą liczbą zabitych
                                               -- Resetting the array because a player with more kills was found
                elseif player and killCount == mostKills then
                    table.insert(mostKillsPlayers, player)  -- Dodanie gracza do tablicy, jeśli ma tyle samo zabitych co inni
                                                          -- Adding player to the array if they have the same number of kills as others
                end
            end

            -- Komunikaty dla graczy, którzy zabili najwięcej szczurów
            -- Messages to the players who killed the most rats
            for _, player in ipairs(mostKillsPlayers) do
                for _, reward in ipairs(rewardMostKills) do
                    player:addItem(reward[1], reward[2])
                end
                Game.broadcastMessage(player:getName() .. " is the hero of Rookgaard! They killed the most rats (" .. mostKills .. " rats)!", MESSAGE_EVENT_ADVANCE)
            end

            -- Nagradzanie wszystkich graczy, którzy zabili przynajmniej jednego szczura
            -- Rewarding all players who killed at least one rat
            for playerId, killCount in pairs(killCounts) do
                local player = Player(playerId)
                if player and killCount > 0 then
                    -- Nagroda dla uczestników
                    -- Reward for participants
                    for _, reward in ipairs(rewardParticipants) do
                        player:addItem(reward[1], reward[2])
                    end
                    Game.broadcastMessage(player:getName() .. " helped in deratisation by killing " .. killCount .. " rats. Rookgaard thanks you!", MESSAGE_EVENT_ADVANCE)
                end
            end
        else
            -- Komunikat o zabiciu szczura
            -- Message about killing a rat
            Game.broadcastMessage("One less rat to worry about!", MESSAGE_EVENT_ADVANCE)
        end
    end

    return true
end

Any good soul may take a look and point out what i'm doing wrong? chat is helpless it loops in errors
 
Back
Top