Your browser does not support JavaScript or its disabled!
Please turn it on, or be aware that some features on this website will not work correctly.
1.4K
Broadcast Chat #113
This allows you to view/chat and the last 10 message in a panel.
This is just a few already released scripts joined together.
File: broadcast_chat.lua | 3.35kb | 133 lines.
--[[
  Script made by Lee (Discord: l33_) - www.trainorcreations.com
  If you want to support my work, feel free to donate at https://trainorcreations.com/donate
  PS. Stop ripping off my work and selling it as your own.
]]--
local panelName = "broadcastPanel"
if not storage[panelName] then
  storage[panelName] = {
    msgView = true,
    width = 500,
  }
end

local config = storage[panelName]
local msgWidget = setupUI([[
Panel
  id: msgPanel
  anchors.top: parent.top
  anchors.left: parent.left
  height: 140
  width: 500
  background-color: #00000055
  color: white
  border-width: 1
  border-color: #666666
  phantom: false
  UIScrollArea
    id: msgArea
    layout: verticalBox
    margin-left: 3
    margin-top: 1
    margin-right: 3
    anchors.fill: parent
    height: 100
  ResizeBorder
    id: bottomResizeBorder
    anchors.fill: next
    height: 3
    minimum: 180
    maximum: 800
    margin-left: 3
    margin-right: 3
    background: #ffffff88

  VerticalSeparator
    id: sep
    anchors.right: parent.right
    anchors.top: parent.top
    anchors.bottom: parent.bottom
    margin-right: 0
    margin-top: 8
    margin-bottom: 8

]], modules.game_interface.getMapPanel())

g_ui.loadUIFromString([[
BroadcastLabel < Label
  color: #5ff7f7
  opacity: 0.87
]])
msgWidget:setVisible(config.msgView)
msgWidget:setWidth(config.width or 400)
local function broadcastChat(name, message)
  if msgWidget.msgArea:getChildCount() >= 10 then
    local fWidget = msgWidget.msgArea:getFirstChild()
    if fWidget then
      fWidget:destroy()
    end
  end
  local level = message["level"] or '?'
  local text = message["text"] or ''
  local msgLabel = UI.createWidget('BroadcastLabel', msgWidget.msgArea)
  msgLabel:setText(os.date('%H:%M', os.time()).. ' ' .. name .. " [" .. level .. "]: " .. text)
  if name == player:getName() then
    msgLabel:setColor('white')
  end
  return modules.game_textmessage.displayBroadcastMessage(name.. ': ' ..text)
end

local broadcastWindow
UI.Separator()
UI.Label("Broadcast:")
broadcastAllow = macro(1000000, "Allow Broadcast", function() end)
local messageBtn = UI.Button("Toggle Message", function(widget)
  if msgWidget:isVisible() then
    msgWidget:hide()
    config.msgView = false
  else
    msgWidget:show()
    config.msgView = true
  end
  widget:setColor(config.msgView and '#03AC13' or '#E3242B')
end)
messageBtn:setColor(config.msgView and '#03AC13' or '#E3242B')

local broadcastBtn = UI.Button("Broadcast", function(widget)
  if broadcastWindow:isVisible() then
    broadcastWindow:hide()
  else
    broadcastWindow:show()
    broadcastWindow:raise()
    broadcastWindow:focus()
  end
end)

broadcastWindow = UI.createWindow('BroadcastWindow')
broadcastWindow:hide()

broadcastWindow.broadcastText.onKeyPress = function(self, keyCode, keyboardModifiers)
  if not (keyCode == 5) then return false end
  broadcastWindow.Broadcast.onClick()
end

broadcastWindow.Broadcast.onClick = function(widget)
  if BotServer._websocket then
    BotServer.send("broadcast_chat", {
      text=broadcastWindow.broadcastText:getText(), level=player:getLevel()}
    )
  end
  broadcastWindow.broadcastText:setText('')
end

BotServer.listen("broadcast_chat", function(name, message)
  if broadcastAllow.isOn() then
    broadcastChat(name, message)
  end
end)

msgWidget.onGeometryChange = function(widget, old, new)
  if old.width == 0 then return end
  config.width = new.width
end

broadcastWindow.closeButton.onClick = function(widget)
  broadcastWindow:hide()
end

UI.Separator()
File: broadcast_chat.otui | 854b | 40 lines.
BroadcastWindow < MainWindow
  !text: tr('Broadcast')
  size: 400 100
  @onEscape: self:hide()

  TextEdit
    id: broadcastText
    anchors.top: parent.top
    anchors.left: parent.left
    anchors.right: parent.right
    margin-left: 3
    margin-bottom: 3
    margin-right: 80

  Button
    id: Broadcast
    anchors.top: parent.top
    anchors.right: parent.right
    margin-right: 0
    margin-left: 0
    height: 22
    width: 70
    text: Broadcast

  HorizontalSeparator
    id: separator
    anchors.right: parent.right
    anchors.left: parent.left
    anchors.bottom: closeButton.top
    margin-bottom: 8    

  Button
    id: closeButton
    !text: tr('Close')
    font: cipsoftFont
    anchors.right: parent.right
    anchors.bottom: parent.bottom
    size: 45 21
    margin-top: 15
    margin-right: 5

01 Aug 2023
Ads