[Lua] GetPlayerColorTexture

A small Lua function to get the PlayerColor FilePath of a player, the function respects enabled ally-enemy color mode. Might be of use in custom UI code.
Lua:
--By Tasyen
---GetPlayerColorTexture
---@param player player
---@param enforcePlayerColor? boolean  (true) ignore enemy ally color mode
---@return string
function GetPlayerColorTexture(player, enforcePlayerColor)
    -- normal mode
    if GetAllyColorFilterState() == 0 or enforcePlayerColor then
        if GetHandleId(GetPlayerColor(player)) < 10 then
            return "ReplaceableTextures\\TeamColor\\TeamColor0"..GetHandleId(GetPlayerColor(player))
        else
            return "ReplaceableTextures\\TeamColor\\TeamColor"..GetHandleId(GetPlayerColor(player))
        end
    else
    -- enemy friend self mode
        if player == GetLocalPlayer() then
            return "ReplaceableTextures\\TeamColor\\TeamColor01"
        elseif player == Player(PLAYER_NEUTRAL_AGGRESSIVE) then
            return "ReplaceableTextures\\TeamColor\\TeamColor24"
        elseif IsPlayerAlly(player, GetLocalPlayer()) then
            return "ReplaceableTextures\\TeamColor\\TeamColor02"
        elseif IsPlayerEnemy(player, GetLocalPlayer()) then
            return "ReplaceableTextures\\TeamColor\\TeamColor00"
        else
            return "ReplaceableTextures\\TeamColor\\TeamColor00"
        end
    end
end
 
Last edited:
Back
Top