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

[OTV8] colored broadcasts

Fifth

Active Member
Joined
Jul 8, 2023
Messages
64
Reaction score
26
Lua:
function displayMessage(mode, text)
  if not g_game.isOnline() then return end

  local msgtype = MessageTypes[mode]
  if not msgtype then
    return
  end

  if msgtype == MessageSettings.none then return end
 
  if msgtype.screenTarget then
    local label = messagesPanel:recursiveGetChildById(msgtype.screenTarget)
    local messageColor = msgtype.color  -- Store the original color

    if msgtype == MessageSettings.centerRed then
      -- Search for color codes within the message and replace them with the appropriate color
      text = text:gsub("{(#%x+)}", function(color)
        messageColor = color  -- Update the color for this message
        return ""
      end)
    end 

    label:setText(text)
    label:setColor(messageColor)  -- Use the stored color for this message
    label:setVisible(true)
    removeEvent(label.hideEvent)
    label.hideEvent = scheduleEvent(function() label:setVisible(false) end, calculateVisibleTime(text))
  end

  if msgtype.consoleTab ~= nil and (msgtype.consoleOption == nil or modules.client_options.getOption(msgtype.consoleOption)) then
    -- Remove color codes from the text before adding it to the console
    text = text:gsub("{(#%x+)}", "")
    modules.game_console.addText(text, msgtype, tr(msgtype.consoleTab))
    --TODO move to game_console
  end
end

\modules\game_textmessage\textmessage.lua

so that you can recolor broadcast messages using hex color code, example/b test123 {#03fcfc}

Lua:
-- Function to broadcast a message with random hex colors for a specified number of times
function broadcastMessageWithRandomColors(message, messageType, numTimes)
    for i = 1, numTimes do
        local randomHexColor = getRandomHexColor()
        addEvent(function()
            broadcastMessage(message .. " {" .. randomHexColor .. "}", messageType)
        end, i * 2500) -- Delay each broadcast by i seconds (1000 milliseconds = 1 second)
    end
end

-- Function to generate a random hex color code
function getRandomHexColor()
    local hexChars = "0123456789ABCDEF"
    local color = "#"
    for i = 1, 6 do
        local randomIndex = math.random(1, #hexChars)
        color = color .. string.sub(hexChars, randomIndex, randomIndex)
    end
    return color
end

Example of application

Lua:
        local message = string.format("~~%s~~ has extended the global [10%% Loot] rate boost for another two hours!", playerName)
        broadcastMessageWithRandomColors(message, MESSAGE_STATUS_WARNING, 5)
 
Back
Top