• 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 Create monster two times

icekis

Member
Joined
Jan 18, 2018
Messages
91
Reaction score
5
I am trying to make a raid from globalevents using date but this script summons two bosses at same time

Could someone help me?


Lua:
local raids = {   
    ['Saturday'] = {
        ['22:28'] = {raidName = 'The Horned Fox', position = Position(2163, 2362, 6)}
    }
}   

function onThink(interval, lastExecution, thinkInterval)
    local day, date = os.date('%A'), getRealDate()

    local raidDays = {}
    if raids[day] then
        raidDays[#raidDays + 1] = raids[day]
    end
    if raids[date] then
        raidDays[#raidDays + 1] = raids[date]
    end

    if #raidDays == 0 then
        return true
    end

    for i = 1, #raidDays do
        local settings = raidDays[i][getRealTime()]
        if settings and not settings.alreadyExecuted then
            Game.createMonster(settings.raidName, settings.position, true, true)
            settings.alreadyExecuted = true
            print(">>>> Automatic Raid " .. settings.raidName .. "")
        end
    end

    return true
end
 
Solution
I am trying to make a raid from globalevents using date but this script summons two bosses at same time

Could someone help me?


Lua:
local raids = { 
    ['Saturday'] = {
        ['22:28'] = {raidName = 'The Horned Fox', position = Position(2163, 2362, 6)}
    }
} 

function onThink(interval, lastExecution, thinkInterval)
    local day, date = os.date('%A'), getRealDate()

    local raidDays = {}
    if raids[day] then
        raidDays[#raidDays + 1] = raids[day]
    end
    if raids[date] then
        raidDays[#raidDays + 1] = raids[date]
    end

    if #raidDays == 0 then
        return true
    end

    for i = 1, #raidDays do
        local settings = raidDays[i][getRealTime()]
        if settings and not settings.alreadyExecuted then...
I am trying to make a raid from globalevents using date but this script summons two bosses at same time

Could someone help me?


Lua:
local raids = { 
    ['Saturday'] = {
        ['22:28'] = {raidName = 'The Horned Fox', position = Position(2163, 2362, 6)}
    }
} 

function onThink(interval, lastExecution, thinkInterval)
    local day, date = os.date('%A'), getRealDate()

    local raidDays = {}
    if raids[day] then
        raidDays[#raidDays + 1] = raids[day]
    end
    if raids[date] then
        raidDays[#raidDays + 1] = raids[date]
    end

    if #raidDays == 0 then
        return true
    end

    for i = 1, #raidDays do
        local settings = raidDays[i][getRealTime()]
        if settings and not settings.alreadyExecuted then
            Game.createMonster(settings.raidName, settings.position, true, true)
            settings.alreadyExecuted = true
            print(">>>> Automatic Raid " .. settings.raidName .. "")
        end
    end

    return true
end
You can try this one:
Lua:
local raids = {  
    ['Saturday'] = {
        ['22:28'] = {raidName = 'The Horned Fox', position = Position(2163, 2362, 6)}
    }
}

function onThink(interval, lastExecution, thinkInterval)
    local day = os.date('%A')
    if raids[day] then
        local time = os.date('%H:%M')
        for raid_time, raid in pairs(raids[day]) do
            if time == raid_time then
                Game.createMonster(raid.name, raid.position, true, true)
                print(">>>> Automatic Raid " .. raid.name .. "")
            end
        end
    end
    return true
end

It looks like you caused two because you added a table to raidDays twice with those two if statements. If you want to learn how to use os.date to achieve what you want check the reference below.
 
Last edited by a moderator:
Solution
You can try this one:
Lua:
local raids = {  
    ['Saturday'] = {
        ['22:28'] = {raidName = 'The Horned Fox', position = Position(2163, 2362, 6)}
    }
}

function onThink(interval, lastExecution, thinkInterval)
    local day = os.date('%A')
    if raids[day] then
        local time = os.date('%H:%M')
        for raid_time, raid in pairs(raids[day]) do
            if time == raid_time then
                Game.createMonster(raid.name, raid.position, true, true)
                print(">>>> Automatic Raid " .. raid.name .. "")
            end
        end
    end
end

It looks like you caused two because you added a table to raidDays twice with those two if statements. If you want to learn how to use os.date to achieve what you want check the reference below.

Thank you for reply!

I got this error on my console:


Code:
[Error - GlobalEvents::think] Failed to execute event: Raid System
[Error - GlobalEvents::think] Failed to execute event: raids
 
Thank you for reply!

I got this error on my console:


Code:
[Error - GlobalEvents::think] Failed to execute event: Raid System
[Error - GlobalEvents::think] Failed to execute event: raids
Do you have the script registered twice in globalevents.xml? If so you should only have it registered once, that may be one of your problems.

Regarding the error, I forgot to add a return true to the end of the function. Before the very last end in the script put in a return true.
 
Back
Top