local function readDefaultSkinFile() local file = io.openlocal("client/defaultskincolors.dat", "r") if not file then return {} end local result = {} local key = nil for line in file:lines() do if line ~= "" then if key then result[key] = line key = nil else key = line end end end file:close() return result end local function writeDefaultSkinFile(toWrite) local file = io.openlocal("client/defaultskincolors.dat", "w") for k, v in pairs(toWrite) do file:write(tostring(k)+"\n"+tostring(v)+"\n") end file:close() end local function recallDefaultSkin(player) local color = player.defaultskincolortable[player.mo.skin] if color then if R_GetColorByName(color) then COM_BufInsertText(player, "color " + color) else CONS_Printf(player, "Warning: Color \"" + color + "\" does not exist. Perhaps a skincolor mod is missing?") end end end addHook("PlayerThink", function(player) if not player.defaultskincolortable then if player == consoleplayer then player.defaultskincolortable = readDefaultSkinFile() end elseif player and player.valid and player.mo then if ((player.oldskin == nil) or (player.skin ~= player.oldskin)) and multiplayer then recallDefaultSkin(player) end player.oldskin = player.skin end end) COM_AddCommand("setdefaultskincolor", function(player, ...) if (not player) or (not player.valid) or (not player.mo) then CONS_Printf(player, "Error: Player is either invalid or dead.") return end if not multiplayer then CONS_Printf(player, "Error: Not currently in a multiplayer game.") return end local arg = {...} local skinsToSet = {} local color = nil if #arg == 0 then CONS_Printf(player, "Usage:\nsetdefaultskincolor\nShows this help message\nsetdefaultskincolor [color]\nSets your default skin color for the current skin to the specified color. Color may be specified as a color name or as a color number. 0 or \"default\" may be used to set the default color to that of the skin's default. -1 or \"none\" may be used to stop setting the skin to the specified color. -2 or \"opposite\" may be used to set the default color to the opposite of that of the skin.\nsetdefaultskincolor [skin1] [skin2] ... [skinn] [color]\nSets skin color of all specified skins to the specified color. Any number of skins may be specified. Entering * as a skin name substitutes it for a list of all skins enabled in the current game. Skins may be specified by name or by number. Special colors (0, -1, -2/\"default\", \"none\", \"opposite\") may be used.") return elseif #arg == 1 then table.insert(skinsToSet, player.mo.skin) color = arg[1] else for i=1, (#arg - 1) do skinsToSet[i] = arg[i] end color = arg[#arg] end local outputSet = {} local usedAster = false for _, v in pairs(skinsToSet) do if tonumber(v) ~= nil then v = tonumber(v) if skins[v].name then table.insert(outputSet, skins[v].name) else CONS_Printf(player, "Warning: Skin #"+v+" does not exist. Ignoring.") end else if v == "*" then if not usedAster then usedAster = true for skin in skins.iterate table.insert(outputSet, skin.name) end end else table.insert(outputSet, v) end end end skinsToSet = outputSet if tonumber(color) == nil then if color:lower() == "opposite" then color = -2 elseif color:lower() == "none" then color = -1 elseif color:lower() == "default" then color = 0 else local oldcolor = color color = R_GetColorByName($) if color == SKINCOLOR_NONE then CONS_Printf(player, "Error: Color \"" + oldcolor + "\" is not a valid color.") return end end else color = tonumber(color) end if (color < -2) or (color >= MAXSKINCOLORS) then CONS_Printf(player, "Error: Color #" + color + " is out of range.") return end for _, skin in pairs(skinsToSet) local scolor = color if color == -2 then if skins[skin] then scolor = ColorOpposite(skins[skin].prefcolor) else CONS_Printf(player, "Warning: Skin \"" + skin + "\" is not currently loaded; cannot set skincolor to opposite.") continue end elseif color == -1 then player.defaultskincolortable[skin] = nil continue elseif color == 0 then if skins[skin] then scolor = skins[skin].prefcolor else CONS_Printf(player, "Warning: Skin \"" + skin + "\" is not currently loaded; cannot set skincolor to default.") continue end end if skin == player.mo.skin then COM_BufInsertText(player, "color " + scolor) end player.defaultskincolortable[skin] = R_GetNameByColor(scolor) end if (player == consoleplayer) then writeDefaultSkinFile(player.defaultskincolortable) end end)