-- name: \\#FF0000\\Breaking \\#0044FF\\News! -- description: I made a news -- this sets up network sync tables! gGlobalSyncTable.showNewsTicker = false gGlobalSyncTable.newsMessage = "NO BROADCAST RIGHT NOW." gGlobalSyncTable.newsTheme = "RED" gGlobalSyncTable.newsSpeed = 2 local textX = djui_hud_get_screen_width() -- these are the themes. local THEMES = { RED = { r = 255, g = 0, b = 0, hr = 140, hg = 0, hb = 0 }, YELLOW = { r = 230, g = 190, b = 0, hr = 150, hg = 120, hb = 0 }, GREEN = { r = 0, g = 200, b = 50, hr = 0, hg = 100, hb = 25 }, BLUE = { r = 0, g = 100, b = 255, hr = 0, hg = 50, hb = 150 } } function render_my_news_ticker() if not gGlobalSyncTable.showNewsTicker then return end local screenWidth = djui_hud_get_screen_width() local screenHeight = djui_hud_get_screen_height() local barHeight = 50 local barYPosition = screenHeight - barHeight -- if you dont have a theme, it falls back to red! local theme = THEMES[gGlobalSyncTable.newsTheme] or THEMES.RED -- this is the little header box thing. local headerWidth = 180 local headerHeight = 25 local headerYPosition = barYPosition - headerHeight djui_hud_set_color(theme.hr, theme.hg, theme.hb, 255) djui_hud_render_rect(0, headerYPosition, headerWidth, headerHeight) djui_hud_set_color(255, 255, 255, 255) djui_hud_set_font(FONT_NORMAL) djui_hud_print_text("Breaking news!", 10, headerYPosition + 3, 0.7) -- draw the ticker thing. djui_hud_set_color(theme.r, theme.g, theme.b, 255) djui_hud_render_rect(0, barYPosition, screenWidth, barHeight) -- this draws the message. local fullMessage = gGlobalSyncTable.newsMessage or "" if string.sub(fullMessage, -4) ~= " -- " then fullMessage = fullMessage .. " -- " end -- text font and scale stuff. djui_hud_set_font(FONT_NORMAL) local textScale = 1.0 local textWidth = djui_hud_measure_text(fullMessage) * textScale -- YOU CANT DIVIDE BY ZERO THATS IMPOSSIBLE SO THIS CHECKS IF THAT HAPPENS if textWidth <= 0 then textWidth = 10 end -- make it left textX = textX - (gGlobalSyncTable.newsSpeed or 2) -- reset position! if textX <= -textWidth then textX = textX + textWidth end -- Infinite wrap djui_hud_set_color(255, 255, 255, 255) local currentX = textX while currentX < screenWidth do djui_hud_print_text(fullMessage, currentX, barYPosition + 12, textScale) currentX = currentX + textWidth end end -- now for the broadcast command. function on_news_command(msg) if not network_is_server() then djui_chat_message_create("Error: Only the server host can update the news!") return true end if msg ~= "" then gGlobalSyncTable.newsMessage = "BREAKING NEWS: " .. msg:upper() textX = djui_hud_get_screen_width() -- Play notification chime for all players locally play_sound(SOUND_MENU_YOSHI_GAIN_LIVES, gMarioStates.marioObj.header.gfx.cameraToObject) djui_chat_message_create("Broadcast updated globally!") else djui_chat_message_create("please provide a string. Example: /news mario crashed the server") end return true end -- toggle the news function on_toggle_news_command() if not network_is_server() then djui_chat_message_create("Error: Only the server host can toggle the news banner!") return true end gGlobalSyncTable.showNewsTicker = not gGlobalSyncTable.showNewsTicker if gGlobalSyncTable.showNewsTicker then play_sound(SOUND_MENU_ENTER_GAME, gMarioStates.marioObj.header.gfx.cameraToObject) djui_chat_message_create("News ticker is now VISIBLE.") else djui_chat_message_create("News ticker is now HIDDEN.") end return true end -- this is for configuring stuff like colors and speed function on_news_config_command(msg) if not network_is_server() then djui_chat_message_create("Error: Only the host can configure banner settings!") return true end local args = {} for word in string.gmatch(msg, "%S+") do table.insert(args, word:upper()) end if args[1] == "SPEED" and args[2] then local num = tonumber(args[2]) if num and num >= 1 and num <= 10 then gGlobalSyncTable.newsSpeed = num djui_chat_message_create("Ticker scrolling speed set to: " .. num) else djui_chat_message_create("Error: Speed must be a number between 1 and 10.") end elseif args[1] == "COLOR" and args[2] then if THEMES[args[2]] then gGlobalSyncTable.newsTheme = args[2] djui_chat_message_create("Banner color theme changed to: " .. args[2]) else djui_chat_message_create("Error: Available colors are RED, YELLOW, GREEN, BLUE.") end else djui_chat_message_create("Usage: /newsconfig speed [1-10] OR /newsconfig color [RED/YELLOW/GREEN/BLUE]") end return true end -- SYNC function on_sync_table_change(key, value) if key == "newsMessage" then textX = djui_hud_get_screen_width() play_sound(SOUND_MENU_YOSHI_GAIN_LIVES, gMarioStates.marioObj.header.gfx.cameraToObject) elseif key == "showNewsTicker" and value == true then play_sound(SOUND_MENU_ENTER_GAME, gMarioStates.marioObj.header.gfx.cameraToObject) end end -- these are the hooks. hook_event(HOOK_ON_HUD_RENDER, render_my_news_ticker) hook_event(HOOK_ON_SYNC_TABLE_CHANGE, on_sync_table_change) hook_chat_command("news", "[anything] - Broadcast a custom news alert globally", on_news_command) hook_chat_command("togglenews", "- Show or hide the news ticker for all players", on_toggle_news_command) hook_chat_command("newsconfig", "[speed/color] [value] - Adjust look and feel", on_news_config_command)