Weather Widget

Allows server owners to dynamically control the weather temperature and icon displayed on phone widgets.

Features

  • Live Weather Updates: Temperature and weather icons can be updated in real-time

  • Server Owner Control: Complete control over weather data through exports

  • Automatic Sync: Weather data automatically syncs to all connected phones

  • Fallback System: Graceful fallback to default values if weather system is disabled

  • Force Update Option: Optional immediate sync to all clients

  • NOTE: The weather widget is available only for Humanoid(android) phones as of now.

Configuration

Enable/Disable Weather System

In config/config.misc.lua:

Config.Weather = {}
Config.Weather.Enabled = true                           -- Enable/disable live weather system
Config.Weather.DefaultTemperature = 21                  -- Default temperature in Celsius
Config.Weather.DefaultIcon = 'humanoid/utils/cloudy.png' -- Default weather icon path
Config.Weather.UpdateInterval = 60000                   -- Update interval in milliseconds (1 minute)

Server Exports

Basic Usage

All export functions accept an optional forceUpdate parameter. When set to true, the weather data will be immediately synchronized to all connected clients instead of waiting for the next update cycle.

Parameters:

  • forceUpdate (boolean, optional): If true, immediately syncs data to all clients

Set Temperature

-- Set temperature to 25°C
local success, errorMsg = exports.yseries:SetTemperature(25)
if not success then
    print("Error setting temperature: " .. errorMsg)
end

-- Set temperature with immediate update to all clients
local success, errorMsg = exports.yseries:SetTemperature(25, true)

Set Weather Icon

-- Set custom weather icon
local success, errorMsg = exports.yseries:SetWeatherIcon('humanoid/utils/sunny.png')

-- Set weather icon with immediate update to all clients
local success, errorMsg = exports.yseries:SetWeatherIcon('humanoid/utils/sunny.png', true)

Set Multiple Values at Once

-- Update multiple weather properties
local weatherData = {
    temperature = 28,
    icon = 'humanoid/utils/sunny.png'
}

local success, errorMsg = exports.yseries:SetWeatherData(weatherData)

-- Update with immediate sync to all clients
local success, errorMsg = exports.yseries:SetWeatherData(weatherData, true)

Get Current Weather Data

local weatherData = exports.yseries:GetWeatherData()
print("Current temperature: " .. weatherData.temperature .. "°C")
print("Current icon: " .. weatherData.icon)

Advanced Examples

Integration with External Weather APIs

-- Example: Sync with OpenWeatherMap API
CreateThread(function()
    while true do
        -- Fetch weather data from external API
        local weatherData = GetExternalWeatherData() -- Your implementation
        
        if weatherData then
            exports.yseries:SetWeatherData({
                temperature = weatherData.temp,
                icon = GetWeatherIcon(weatherData.condition) -- Map to your icons
            }, true) -- Force update to all clients
        end
        
        Wait(300000) -- Update every 5 minutes
    end
end)

Weather Icons

Default Icons Available

  • humanoid/utils/cloudy.png - Cloudy weather

  • Add your own custom icons to the UI assets

Custom Weather Icons

  1. Add your weather icon files to ui/public/humanoid/utils/

  2. Reference them in the icon path: humanoid/utils/your-icon.png

Troubleshooting

Weather Not Updating

  1. Check if Config.Weather.Enabled is set to true

  2. Verify the weather system is loaded.

  3. Check for any error messages when calling exports

Icons Not Displaying

  1. Ensure icon paths are correct and files exist in ui/public/

  2. Check browser console for 404 errors on image requests

Performance Considerations

  • The default update interval is 60 seconds to balance real-time updates with performance

  • Consider longer intervals for production servers with many players

  • Weather data is cached and only sent when phones are open

Last updated