local pfp_table, downloads = {}, {}
local refresh_images = function()
if not engine.is_in_game() then return end
local players = entitylist.get_players(2)
for i = 1, #players do
local player = players[i]
local player_info = engine.get_player_info(player:get_index())
if player_info.is_bot then goto continue end
local steamid = player_info.steam_id64
if pfp_table[tostring(steamid)] == nil then
local request_endpoint = ("https://steamcommunity.com/profiles/%s/?xml=1"):format(steamid)
if downloads[tostring(steamid)] == true then goto continue end
downloads[tostring(steamid)] = true
http.get(request_endpoint, function (success, response)
if response.status ~= 200 or not success then downloads[tostring(steamid)] = nil return end
local xml = response.body
local link_start = string_find(xml, "<avatarIcon><!%[CDATA%[") + 21
local link_end = string_find(xml, "%]%]></avatarIcon>") - 1
local img_endpoint = xml:sub(link_start, link_end)
http.get(img_endpoint, function (success_img, img)
if img.status ~= 200 or not success_img then goto continue end
local img_path = ("nix/metamod/%s.jpg"):format(steamid)
local img_handle = io.open(img_path, "w+")
if img_handle == nil then return end
img_handle:write(img.body)
img_handle:close()
local texture = renderer.setup_texture(img_path)
pfp_table[tostring(steamid)] = texture
::continue::
end)
end)
end
::continue::
end
end