]> git.lizzy.rs Git - Crafter.git/commitdiff
Make player skins use their github "crafter_skindex" skin.png
authoroilboi <47129783+oilboi@users.noreply.github.com>
Wed, 27 May 2020 00:47:10 +0000 (20:47 -0400)
committeroilboi <47129783+oilboi@users.noreply.github.com>
Wed, 27 May 2020 00:47:10 +0000 (20:47 -0400)
mods/skins/init.lua
mods/skins/skin_temp/temp.png [new file with mode: 0644]

index 2ae8c7253bbbcf59b1c4255ebaae7a3152f24119..f8dd6bb4cc490745768b3de69438e3bc22066f2f 100644 (file)
@@ -54,7 +54,8 @@ local function fetch_url(url, callback)
 end
 
 local function unsafe_file_write(path, contents)
-       local f = security.io.open(path, "wb")
+    local f = security.io.open(path, "wb")
+    if not f then return end
        f:write(contents)
        f:close()
 end
@@ -116,8 +117,8 @@ local function file_to_texture(image)
 end
 
 -- Function to fetch a range of pages
-fetch_function = function()
-    fetch_url("https://raw.githubusercontent.com/oilboi/crafter_skindex/master/skin.png", function(data)
+fetch_function = function(name)
+    fetch_url("https://raw.githubusercontent.com/"..name.."/crafter_skindex/master/skin.png", function(data)
         if data then
             unsafe_file_write(path.."/skin_temp/temp.png", data)
 
@@ -128,8 +129,11 @@ fetch_function = function()
                 --print("===============================================================")
                 --print(stored_texture)
                 if stored_texture then
-                    --print(dump(stored_texture))
-                    minetest.get_player_by_name("singleplayer"):set_properties({textures = {stored_texture}})
+                    --set the player's skin
+                    local player = minetest.get_player_by_name(name)
+                    player:set_properties({textures = {stored_texture}})
+                    
+                    
                     --[[
                     minetest.get_player_by_name("singleplayer"):hud_add(
                         {
@@ -179,6 +183,6 @@ end
 
 minetest.register_on_joinplayer(function(player)
     minetest.after(4,function()
-        fetch_function()
+        fetch_function(player:get_player_name())
     end)
 end)
\ No newline at end of file
diff --git a/mods/skins/skin_temp/temp.png b/mods/skins/skin_temp/temp.png
new file mode 100644 (file)
index 0000000..7304aef
Binary files /dev/null and b/mods/skins/skin_temp/temp.png differ