Lua · Examples · Storage and web

Website data and images

Fetches JSON and an image from adolfjon.uz and shows them in a panel.

Uses: http.get, json.decode, draw.load_image_data

website_data_and_images.lua
-- name: Site Card
-- author: Adolfjon
-- version: 1.0
-- description: Loads an image from adolfjon.uz into a HUD panel.
-- permissions: network

local logo
local status = "loading"
local white = color(240, 242, 246)

local started = http.get("https://adolfjon.uz/storage/uploads/white.png", function(ok, body)
    if not ok then status = "offline" return end
    logo = draw.load_image_data(body)
    status = logo and "ready" or "bad image"
end)
if not started then status = "allow network on the script page" end

function on_frame()
    local x, y, shown = hud.panel("card", "adolfjon.uz", 180, 64)
    if not shown then return end
    if logo then
        draw.image(logo, x + 10, y + 8, 48, 48)
        draw.text(x + 68, y + 24, "Adolfjon", white, 16)
    else
        draw.text(x + 10, y + 24, status, white, 14)
    end
end

Install it

  1. Press Copy on the code above.
  2. In the menu, open Lua and press From Clipboard. The file is named from its -- name: line.
  3. Turn the script on in the list. Its settings show on its own tab.

Change anything you like and press Save (Ctrl+S) in the editor; the script reloads at once. See Getting started for the other ways to add scripts.