• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

Action [TFS 1.2] Boss Raid Starter with Global CD

strutZ

Australian OT Member {AKA Beastn}
Joined
Nov 16, 2014
Messages
1,391
Solutions
7
Reaction score
550
Hello,

Today I would like to release my modal window raid selector.

Features
- Configurable price to start a raid
- Configurable CD between raid starting
ccca3482f82369e624e9e858e7ca1c3c.jpg

data/actions/actions.xml
Code:
 <action actionid="5000" script="custom/modalRAID_Bosses.lua"/>

data/actions/scripts/raidstarter.lua
Code:
local raids = {
        [1] = {raid = 'Arachir the Ancient One'},
        [2] = {raid = 'Diblis The Fair'},
        [3] = {raid = 'Ferumbras'},
        [4] = {raid = 'Ghazbaran'},
        [5] = {raid = 'Horned Fox'},
        [6] = {raid = 'Morgaroth'}, 
        [7] = {raid = 'Necropharus'},
        [8] = {raid = 'Orshabaal'},
        [9] = {raid = 'Sir Valorcrest'},
        [10] = {raid = 'The Old Widow'},
        [11] = {raid = 'Zevelon Duskbringer'},
        [12] = {raid = 'Zulazza the Corruptor'},
        [13] = {raid = 'Apocalypse'},
     
}

function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
    player:registerEvent("modalRAID_Bosses")

    local title = "Pick a Raid!"
    local message = "Pick the raid you wish to start. Each raid will cost you 50cc"

    local window = ModalWindow(1003, title, message)

    window:addButton(100, "Confirm")
    window:addButton(101, "Cancel")

    for i = 1, #raids do
        local o = raids[i].raid
        window:addChoice(i, o)
    end
    window:setDefaultEnterButton(100)
    window:setDefaultEscapeButton(101)

    window:sendToPlayer(player)
    return true
end

data/creaturescripts/scripts/raidstarter.lua

Code:
local cost = 50 --Amount of Crystal Coins per raid
local wait = 30 * 60 -- Wait time between raids (Works in minitues right now its set to 30 mins. Change the 30 to w/e you want)
local raids = {
        [1] = {name = 'Arachir the Ancient One'},
        [2] = {name = 'Diblis The Fair'},
        [3] = {name = 'Ferumbras'},
        [4] = {name = 'Ghazbaran'},
        [5] = {name = 'Horned Fox'},
        [6] = {name = 'Morgaroth'},
        [7] = {name = 'Necropharus'},
        [8] = {name = 'Orshabaal'},
        [9] = {name = 'Sir Valorcrest'},
        [10] = {name = 'The Old Widow'},
        [11] = {name = 'Zevelon Duskbringer'},
        [12] = {name = 'Zulazza the Corruptor'},
        [13] = {name = 'Apocalypse'},
    
}

function onModalWindow(player, modalWindowId, buttonId, choiceId)
    player:unregisterEvent("modalRAID_Bosses")
    if modalWindowId ~= 1003 or buttonId ~= 100 then
        return false
    end

    local raid = raids[choiceId]
    if not raid then
         return false
    end

    local raidStorage = Game.getStorageValue(12345)
    raidStorage = not raidStorage and 0 or raidStorage
    if raidStorage > os.time() then
       player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You must wait ".. showTimeLeft(raidStorage - os.time(), true) ..", before you can start another boss raid.")
       return false
    end
 
    if player:getItemCount(2160) < 20 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You dont have enough money.")
    return false
    end
 
    player:removeItem(2160, cost)
    player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_YELLOW)
    Game.startRaid(raid.name)
    Game.setStorageValue(12345, os.time() + wait)
    return true
end


data/creaturescripts/creaturescripts.xml
Code:
    <event type="modalwindow" name="raidstarter" script="raidstarter.lua"/>

Then dont forget to register it in your login.lua
Code:
raidstarter

Enjoy.
 
Last edited:
Tested on 1.2 works good, except for cool down part i get errors.
Thanks for this i will use it.
 
Tested on 1.2 works good, except for cool down part i get errors.
Thanks for this i will use it.
Use the new version i posted =) also add this to the bottom of your global.lua it will fix your errors. =)

Code:
function showTimeLeft(number, usewords)
   local number = tonumber(number)
   if not number then
     return "error"
   end

   if number < 0 then
     return "expired"
   end

   local clocknum = os.date("!%X",number):split(":") -- h:m:s
   local day = math.modf(number / 86400)
   local hour = clocknum[1]
   local minute = clocknum[2]
   local second = clocknum[3]

   if not usewords then
     return table.concat({day, hour, minute, second}, ":")
   end

   local text = {}
   if day > 0 then
     table.insert(text, tonumber(day) .. " day" .. (day > 1 and "s" or ""))
   end

   if hour ~= "00" then
     table.insert(text, tonumber(hour) .. " hour" .. (tonumber(hour) > 1 and "s" or ""))
   end

   if minute ~= "00" then
     table.insert(text, tonumber(minute) .. " minute" .. (tonumber(minute) > 1 and "s" or ""))
   end

   if second ~= "00" then
     table.insert(text, tonumber(second) .. " second" .. (tonumber(second) > 1 and "s" or ""))
   end

   countdown_text = ""
   if #text > 0 then
     countdown_text = text[1]
     for i = 2, #text - 1 do
       countdown_text = countdown_text .. ", " .. text[i]
     end
     if #text > 1 then
       countdown_text = countdown_text .. " and " .. text[#text]
     end
     countdown_text = countdown_text .. ""
   else
     countdown_text = "expired"
   end
return countdown_text
end

function timeString(timeDiff)
    local dateFormat = {
        {"day", timeDiff / 60 / 60 / 24},
        {"hour", timeDiff / 60 / 60 % 24},
        {"minute", timeDiff / 60 % 60},
        {"second", timeDiff % 60}
    }

    local out = {}
    for k, t in ipairs(dateFormat) do
        local v = math.floor(t[2])
        if(v > 0) then
            table.insert(out, (k < #dateFormat and (#out > 0 and ', ' or '') or ' and ') .. v .. ' ' .. t[1] .. (v ~= 1 and 's' or ''))
        end
    end
   
    return table.concat(out)
end
 
Back
Top