function assignCustomItems()
--------------------------------------------------------------------------------------------------------------
--PLACE CUSTOM ASSIGNMENTS BELOW HERE
--------------------------------------------------------------------------------------------------------------
assignTournamentRefereeKits(13,13,5)
assignTournamentRefereeKits(14,14,5)
assignTournamentRefereeKits(201,201,5)
assignTournamentRefereeKits(202,202,5)
assignTournamentRefereeKits(228,13,5)
assignTournamentRefereeKits(16,16,5)
--referees
assignPlayerFace(29)
assignPlayerFace(42)
assignPlayerFace(64)
assignPlayerFace(70)
assignPlayerFace(72)
assignPlayerFace(75)
assignPlayerFace(88)
assignPlayerFace(99)
assignPlayerFace(101)
assignPlayerFace(106)
assignPlayerFace(112)
assignPlayerFace(117)
assignPlayerFace(122)
assignPlayerFace(123)
assignPlayerFace(127)
assignPlayerFace(128)
assignPlayerFace(138)
assignPlayerFace(144)
assignPlayerFace(164)
assignPlayerFace(176)
assignPlayerFace(178)
assignPlayerFace(182)
assignPlayerFace(190)
assignPlayerFace(193)
assignPlayerFace(195)
assignPlayerFace(200)
assignPlayerFace(203)
assignPlayerFace(209)
assignPlayerFace(215)
assignPlayerFace(216)
assignPlayerFace(217)
assignPlayerFace(218)
assignPlayerFace(219)
assignPlayerFace(220)
assignPlayerFace(221)
assignPlayerFace(222)
assignPlayerFace(223)
assignPlayerFace(226)
assignPlayerFace(227)
assignPlayerFace(228)
assignPlayerFace(229)
assignPlayerFace(231)
assignPlayerFace(232)
assignPlayerFace(233)
assignPlayerFace(234)
assignPlayerFace(235)
assignPlayerFace(236)
assignPlayerFace(251)
assignPlayerFace(263)
assignPlayerFace(266)
assignPlayerFace(267)
assignPlayerFace(273)
--------------------------------------------------------------------------------------------------------------
--PLACE CUSTOM ASSIGNMENTS ABOVE HERE
--------------------------------------------------------------------------------------------------------------
end

--------------------------------------------------------------------------------------------------------------

function PlayerUpdate(idx)
	local as = gSportsRNA
	local player = as:GetTable("wvPlayer", idx)
	local state = as:GetTable("wvState")
	
	db.player[idx].envLighting = as:GetInt(state, "wvAttribEnvLighting")
	db.player[idx].stadiumLightID = as:GetInt(state, "wvAttribStadLightID")
	db.player[idx].stadiumID = as:GetInt(state, "wvAttribStadID")
	local weather = as:GetInt(state, "wvAttribStadWeather" )
	if (weather == 1 or weather == 2) then
		db.player[idx].wet = 1
	else
		db.player[idx].wet = 0
	end
	
	db.player[idx].playerassetid = as:GetInt(player, "playerassetid") 
	db.player[idx].teamid = as:GetInt(player, "teamid") 
	db.player[idx].teamside = as:GetInt(player, "teamside") 
	db.player[idx].isgoalie = as:GetInt(player, "goalie") 
	
	db.player[idx].kit = as:GetInt(player, "kit") 
	db.player[idx].kitType = as:GetInt(player, "kitType") 
	db.player[idx].kitYear = as:GetInt(player, "kitYear") 

	local kitNumber = as:GetInt(player, "kitNumber") 
	db.player[idx].kitNumberTens = math.floor ( kitNumber / 10 )
	db.player[idx].kitNumberUnits = math.floor ( math.fmod(kitNumber, 10) )

	db.player[idx].kitNameFont = as:GetInt(player, "kitNameFont")
	db.player[idx].kitNumberFont = as:GetInt(player, "kitNumberFont")
	db.player[idx].kitNumberColor = as:GetInt(player, "kitNumberColor")
	db.player[idx].kitNameColor = as:GetInt(player, "kitNameColor")
	
	db.player[idx].shortsNumberFont = as:GetInt(player, "shortsNumberFont")
	db.player[idx].shortsNumberColor = as:GetInt(player, "shortsNumberColor")
	db.player[idx].jerseyNameVisible = as:GetInt(player, "jerseyNameVisible")
	db.player[idx].jerseyNameLayout = as:GetInt(player, "jerseyNameLayout")
	
	db.player[idx].head = as:GetInt(player, "playerHead") 
	db.player[idx].headClass = as:GetInt(player, "playerHeadClass") 
	
	db.player[idx].jerseyCollarType = as:GetInt(player, "jerseyCollarType") 
	db.player[idx].jerseySleeveLength = as:GetInt(player, "jerseySleeveLength") 
	db.player[idx].jerseyArmBand = as:GetInt(player, "jerseyArmBand") 
	db.player[idx].jerseyTucked = as:GetInt(player, "jerseyTucked") 
	db.player[idx].jerseyfit = as:GetInt(player, "jerseyfit") 
	db.player[idx].socklength = as:GetInt(player, "socklength")
	db.player[idx].shortstyle = as:GetInt(player, "shortstyle")
	
	db.player[idx].bodySkinToneType = as:GetInt(player, "playerBodySkinToneType")
	db.player[idx].headSkinToneType = as:GetInt(player, "playerHeadSkinToneType")
	db.player[idx].headSkinType = as:GetInt(player, "playerHeadSkinType")
	db.player[idx].playerBodySkinColor = as:GetInt(player, "playerBodySkinColor")
	db.player[idx].faceGenSkinToneType = as:GetInt(player, "faceGenSkinToneType")
	
	db.player[idx].shoeType = as:GetInt(player, "shoeType")
	db.player[idx].shoeDesign = as:GetInt(player, "shoeDesign")
	db.player[idx].shoeColorPri = as:GetInt(player, "shoeColorPrim")
	db.player[idx].shoeColorSec = as:GetInt(player, "shoeColorSec")
	db.player[idx].shoeColorTer = as:GetInt(player, "shoeColorTer")

	db.player[idx].faceType = as:GetInt(player, "faceType")
	db.player[idx].faceProxyHeadClass = as:GetInt(player, "faceProxyHeadClass")
	-- Faceproxyheadclass should never be greater than one including createplayer
	if (db.player[idx].faceProxyHeadClass == 2) then
		db.player[idx].faceProxyHeadClass = 1
	end
	
	db.player[idx].faceSideBurn = as:GetInt(player, "faceSideBurn")
	db.player[idx].facialHairColor = as:GetInt(player, "facialHairColor")
	db.player[idx].facialHairType = as:GetInt(player, "facialHairType")
	db.player[idx].eyebrow = as:GetInt(player, "eyebrow")
	
	db.player[idx].isVirtualPro = as:GetInt(player, "isVirtualPro")
	db.player[idx].isCreatePlayer = as:GetInt(player, "isCreatePlayer")
	db.player[idx].faceTexExtension = "rx3"
	
	db.player[idx].isCreationZone = as:GetInt(player, "isFCZ")
	db.player[idx].hasCzCrestImage = as:GetInt(player, "hasCzCrestImage")
	db.player[idx].crestAssetId = as:GetInt(player, "crestAssetId")
	db.player[idx].forceLowResBNM = as:GetInt(player, "forceLowResBNM")
	db.player[idx].forcePowerOfTwoBNM = as:GetInt(player, "forcePowerOfTwoBNM")
	db.player[idx].forceunderarm = as:GetInt(player, "forceunderarm")
	db.player[idx].forceundershorts = as:GetInt(player, "forceundershorts")
	db.player[idx].forceunderneck = as:GetInt(player, "forceunderneck")

	db.player[idx].sponsorAssetId = as:GetInt(player, "sponsorAssetId")
	db.player[idx].hotspotJerseySponsorL = as:GetFloat(player, "hotspotJerseySponsorL")
	db.player[idx].hotspotJerseySponsorT = as:GetFloat(player, "hotspotJerseySponsorT")
	db.player[idx].hotspotJerseySponsorR = as:GetFloat(player, "hotspotJerseySponsorR")
	db.player[idx].hotspotJerseySponsorB = as:GetFloat(player, "hotspotJerseySponsorB")
	
	db.player[idx].kitColourJerseyPri = as:GetInt(player, "kitColourJerseyPri")
	db.player[idx].kitColourJerseySec = as:GetInt(player, "kitColourJerseySec")
	db.player[idx].kitColourJerseyTer = as:GetInt(player, "kitColourJerseyTer")

	db.player[idx].kitColourShortPri = as:GetInt(player, "kitColourShortPri")
	db.player[idx].kitColourShortSec = as:GetInt(player, "kitColourShortSec")
	db.player[idx].kitColourShortTer = as:GetInt(player, "kitColourShortTer")

	db.player[idx].kitColourSocksPri = as:GetInt(player, "kitColourSocksPri")
	db.player[idx].kitColourSocksSec = as:GetInt(player, "kitColourSocksSec")
	db.player[idx].kitColourSocksTer = as:GetInt(player, "kitColourSocksTer")

	db.player[idx].sponsorcolour = as:GetInt(player, "sponsorcolour")

	db.player[idx].crestTexName = "crest_cm"
	
	if (db.player[idx].isCreationZone == 1 and db.player[idx].hasCzCrestImage > 0) then
		db.player[idx].crestTexName = "png";
	end

	if (db.player[idx].isVirtualPro == 1) then
		db.player[idx].faceTexExtension = "dds"
	end
	
	db.player[idx].faceTypeFallback = 0
	db.player[idx].headFallback = 0
	db.player[idx].faceSideBurnFallback = db.player[idx].faceSideBurn
	db.player[idx].facialHairColorFallback = db.player[idx].facialHairColor
	db.player[idx].facialHairTypeFallback = db.player[idx].facialHairType
	db.player[idx].headSkinTypeFallback = db.player[idx].headSkinType
	db.player[idx].headSkinToneTypeFallback = db.player[idx].headSkinToneType
	
	if(db.player[idx].headSkinToneTypeFallback == 1 or db.player[idx].headSkinToneTypeFallback == 3 or db.player[idx].headSkinToneTypeFallback == 7) then
		db.player[idx].headSkinToneTypeFallback = db.player[idx].headSkinToneTypeFallback + 1
	end
	
	-- If create player then we need the create player head
	-- head_{id}_{headClass}.rx2
	-- {id} == 0 is create player
	-- {id} == 1 is create player copy
	-- {id} == 2 is facegen head
	-- {id} == 3 is facegen head copy
 	if (db.player[idx].isCreatePlayer == 1) then
		db.player[idx].headClass = 2
		db.player[idx].faceProxyHeadClass = 1
		
		if (db.player[idx].isVirtualPro == 1) then
			db.player[idx].faceSideBurn = 0
			db.player[idx].facialHairColor = 0
			db.player[idx].facialHairType = 0
			db.player[idx].headSkinType = 0
			db.player[idx].headSkinToneType = 0
			
		end
		
	end
	
	
	db.player[idx].eyeColor = as:GetInt(player, "eyeColor")
	db.player[idx].hair = as:GetInt(player, "hair")
	db.player[idx].hairColor = as:GetInt(player, "hairColor") 
	
	
	--FACE
	db.player[idx].headClass = getPlayerFace(db.player[idx].playerassetid,db.player[idx].headClass)
	db.player[idx].faceProxyHeadClass = getPlayerFace(db.player[idx].playerassetid,db.player[idx].faceProxyHeadClass)
	

	if (db.player[idx].headClass == 0) then
	
		local playerassetid = db.player[idx].playerassetid
		
		db.player[idx].head = playerassetid 
		db.player[idx].eyeColor = playerassetid

		db.player[idx].eyebrow = 0
		db.player[idx].faceType = playerassetid
		db.player[idx].faceSideBurn = 0
		db.player[idx].facialHairColor = 0
		db.player[idx].facialHairType = 0
		db.player[idx].headSkinType = 0
		db.player[idx].headSkinToneType = 0

		db.player[idx].hair = playerassetid
		db.player[idx].hairColor = 0
	else
		if(db.player[idx].headSkinToneType == 1 or db.player[idx].headSkinToneType == 3 or db.player[idx].headSkinToneType == 7) then
			db.player[idx].headSkinToneType = db.player[idx].headSkinToneType + 1
		end
		--tmp
		-- db.player[idx].hairColorIdx = db.player[idx].hairColor
		-- db.player[idx].hairColor = 0	
	end
	
	
-- Seasonal Assets --
	-- These exist only here and not in the code:
	local seasonal = as:GetInt(player, "seasonaljersey")
	
	
	
	--local weather2 = as:GetInt(state, "wvAttribStadWeather" )
	
	--GET ACCESSORY WEATHER
	local winterAcc = getWinterAccessoriesWeather(weather)
	
	--GET PLAYER WINTER ACCESSORIES
	if (db.player[idx].kitType == 5) then
	seasonal = getRefereeWinterAccessories(seasonal)
	end
	
	seasonal = getWinterAccessories(db.player[idx].playerassetid,seasonal)
	
	--SLEEVE LENGTH
	db.player[idx].jerseySleeveLength = getSleeveLength(db.player[idx].playerassetid,db.player[idx].jerseySleeveLength)
		
	
	
	if (not winterAcc) then
	--if(db.player[idx].wet == 0) then
		seasonal = db.player[idx].jerseySleeveLength
	end
	
	if (seasonal == 1) then
		db.player[idx].jerseySleeveLength  = 1
		db.player[idx].underneck = -1
		db.player[idx].underarms = -1
		db.player[idx].armLength = 1
	-- Long Sleeves and just underarmor neck
	elseif (seasonal == 2) then
		db.player[idx].jerseySleeveLength = 1
		db.player[idx].underneck = 0    
		db.player[idx].underarms = -1
		db.player[idx].armLength = 1
	-- Short sleeves with underarmor arms no neck
	elseif (seasonal == 3) then
		db.player[idx].jerseySleeveLength  = 0
		db.player[idx].underneck = -1
		db.player[idx].underarms = 0
		db.player[idx].armLength = 1
	-- Short sleeves with underarmor neck and arms
	elseif (seasonal == 4) then
		db.player[idx].jerseySleeveLength  = 0
		db.player[idx].underneck = 0
		db.player[idx].underarms = 0
		db.player[idx].armLength = 1
	-- Short Sleeves no underarmor stuff
	else
		db.player[idx].jerseySleeveLength  = 0
		db.player[idx].underneck = -1
		db.player[idx].underarms = -1
		db.player[idx].armLength = 0
	end
	
	if (winterAcc or db.player[idx].isVirtualPro == 1 or db.player[idx].isCreatePlayer == 1) then
	--if (db.player[idx].wet > 0 or db.player[idx].isVirtualPro == 1 or db.player[idx].isCreatePlayer == 1) then
		db.player[idx].undershorts = 0 
	else
		db.player[idx].undershorts = -1
	end
		

	-- end of seasonal assets
	
	-- check if we need to force underwear for injuries
	if ( db.player[idx].forceunderarm == 1 ) then
		db.player[idx].jerseySleeveLength  = 0
		db.player[idx].underarms = 0
		db.player[idx].armLength = 1
	end
	
	if ( db.player[idx].forceundershorts == 1 ) then
		db.player[idx].undershorts = 0 
	end
	
	if ( db.player[idx].forceunderneck == 1 ) then
		db.player[idx].underneck = 0 
	end

	-- Goalie long pants, turn off necessary assets.
	if( db.player[idx].shortstyle == 1 ) then
		db.player[idx].socklength = -1
		db.player[idx].undershorts = -1
	end
	
	db.player[idx].useTextureComposition = as:GetInt(player, "useTextureComposition")
	
	
	
	
	--COUNTER
	if (idx == 0) then
	if (idx ~= oldplayeridx) then
	assignCustomItems()
	end
	end
	oldplayeridx = idx
	
	
	local stadium = as:GetTable("wvStadium", 1)
	
	-- db.stadium[1].homeKitTeamID = 0
	-- db.stadium[1].awayKitTeamID = 0
	-- db.stadium[1].homeKitTypeID = 0
	-- db.stadium[1].awayKitTypeID = 0
	
	db.stadium[1].homeKitTeamID = as:GetInt(stadium, "homeKitTeamID" )
	db.stadium[1].awayKitTeamID = as:GetInt(stadium, "awayKitTeamID" )
	db.stadium[1].homeKitTypeID = as:GetInt(stadium, "homeKitTypeID" )
	db.stadium[1].awayKitTypeID = as:GetInt(stadium, "awayKitTypeID" )
	
	
	local wipe3d = as:GetTable("wvWipe", 1)
	
	-- db.wipe3d[1].leagueID = 0
	
	db.wipe3d[1].leagueID = as:GetInt(wipe3d, "leagueID")
	
	db.wipe3d[1].leagueID = getTournamentGraphics(db.wipe3d[1].leagueID)
	

	
	
	
	
	
	
	--GK KIT SPEC
	if (db.player[idx].kitType == 2) then
	db.player[idx].kit = getSpecificGKKit(db.player[idx].teamid,db.player[idx].kit)
	end
	
	--ARENA PLAYER KIT
	if (idx == 0) then
	db.player[idx].kit = getHomeArenaKit(db.player[idx].teamid,db.player[idx].kit)
	db.player[idx].kitType = getHomeArenaKitType(db.player[idx].teamid,db.player[idx].kitType)
	db.player[idx].kitYear = 0
	end

	--ARENA GK KIT
	if (idx == 1) then
	db.player[idx].kit = getAwayArenaKit(db.player[idx].teamid,db.player[idx].kit)
	db.player[idx].kitType = getAwayArenaKitType(db.player[idx].teamid,db.player[idx].kitType)
	db.player[idx].kitYear = 0
	end
	
	--TRAINING KIT HOME
	if ((db.player[idx].kit == 7000) and (db.player[idx].kitType == 6)) then
	db.player[idx].kit = getHomeTrainingKit(db.player[idx].teamid,db.player[idx].kit)
	db.player[idx].kitType = getHomeTrainingKitType(db.player[idx].teamid,db.player[idx].kitType)
	end
	
	--TRAINING KIT AWAY
	if ((db.player[idx].kit == 7000) and (db.player[idx].kitType == 7)) then
	db.player[idx].kit = getAwayTrainingKit(db.player[idx].teamid,db.player[idx].kit)
	db.player[idx].kitType = getAwayTrainingKitType(db.player[idx].teamid,db.player[idx].kitType)
	end

	
	--GK KITS
	if ((db.player[idx].kitType == 2) and (idx > 1)) then
	
	local isHome = true
	local outidx = 3
	
	if ((idx == 13) or (idx > 26)) then
	isHome = false
	outidx = 14
	end
	
	--CLASSIC GK KIT
	local outplayer = as:GetTable("wvPlayer", outidx)
	local kitYearOutfield = as:GetInt(outplayer, "kitYear")
	db.player[idx].kitYear = getClassicGKKit(db.player[idx].kit,kitYearOutfield,db.player[idx].kitYear)
	
	if (db.player[idx].kitYear == 0) then
	if (isHome) then
	--if (db.player[idx].kit == db.stadium[1].homeKitTeamID) then
	db.player[idx].kitType = getGKKit(db.player[idx].kit,db.stadium[1].homeKitTypeID,db.stadium[1].homeKitTeamID,db.stadium[1].awayKitTeamID,db.player[idx].kitType)
	else
	db.player[idx].kitType = getGKKit(db.player[idx].kit,db.stadium[1].awayKitTypeID,db.stadium[1].homeKitTeamID,db.stadium[1].awayKitTeamID,db.player[idx].kitType)
	end
	end
	
	--NON GK KIT
	else
	
	--SPECIFIC MATCH KIT
	if (db.player[idx].kitYear == 0) then
	db.player[idx].kitType = getGameKit(db.player[idx].kit,db.stadium[1].homeKitTeamID,db.stadium[1].awayKitTeamID,db.player[idx].kitType)
	end
	
	end
	
	
	--PLAYER KIT SET
	if ((db.player[idx].kitType ~= 5) and (db.player[idx].kitYear == 0)) then
	db.player[idx].kitYear = getTournamentPlayerKits(db.player[idx].kit,db.wipe3d[1].leagueID,db.player[idx].kitYear)
	elseif ((db.player[idx].kitType ~= 5) and (db.player[idx].kitYear ~= 0)) then
	db.wipe3d[1].leagueID = db.player[idx].kitYear
	end
	
	
	--KIT DETAILS
	db.player[idx].kitNameFont = getKitNameFont(db.player[idx].kit,db.player[idx].kitType,db.player[idx].kitNameFont,db.wipe3d[1].leagueID,db.player[idx].teamid)
	db.player[idx].kitNumberFont = getKitNumberSet(db.player[idx].kit,db.player[idx].kitType,db.player[idx].kitNumberFont,db.wipe3d[1].leagueID,db.player[idx].teamid)
	db.player[idx].kitNumberColor = getKitNumberColourShirt(db.player[idx].kit,db.player[idx].kitType,db.player[idx].kitNumberColor,db.wipe3d[1].leagueID)
	db.player[idx].kitNameColor = getKitNameColour(db.player[idx].kit,db.player[idx].kitType,db.player[idx].kitNameColor,db.wipe3d[1].leagueID)
	db.player[idx].shortsNumberFont = getKitNumberSet(db.player[idx].kit,db.player[idx].kitType,db.player[idx].shortsNumberFont,db.wipe3d[1].leagueID,db.player[idx].teamid)
	db.player[idx].shortsNumberColor = getKitNumberColourShort(db.player[idx].kit,db.player[idx].kitType,db.player[idx].shortsNumberColor,db.wipe3d[1].leagueID)
	db.player[idx].jerseyNameLayout = getKitNameCurve(db.player[idx].kit,db.player[idx].kitType,db.player[idx].jerseyNameLayout,db.wipe3d[1].leagueID)
	db.player[idx].jerseyCollarType = getKitCollar(db.player[idx].kit,db.player[idx].kitType,db.player[idx].jerseyCollarType,db.wipe3d[1].leagueID)
	db.player[idx].jerseyfit = getKitFit(db.player[idx].kit,db.player[idx].kitType,db.player[idx].jerseyfit,db.wipe3d[1].leagueID,db.player[idx].playerassetid)

	

	--REF KITS
	if (db.player[idx].kitType == 5) then
	
	if (db.player[idx].kit > 6100) then
	db.player[idx].kit = db.player[idx].kit - 100
	end
	
	db.player[idx].kitYear = getTournamentRefereeKits(db.wipe3d[1].leagueID,db.player[idx].kitYear,db.stadium[1].homeKitTeamID)
	db.player[idx].jerseyCollarType = getTournamentRefereeKitsCollar(db.wipe3d[1].leagueID,db.player[idx].jerseyCollarType,db.stadium[1].homeKitTeamID)
	end
	
	
	
	

	
	--BOOTS
	db.player[idx].shoeType = getPlayerBoot(db.player[idx].playerassetid,db.player[idx].shoeType)
	if (db.player[idx].shoeType > 0) then
	db.player[idx].shoeDesign = 0
	db.player[idx].shoeColorPri = hex("FF0000")
	db.player[idx].shoeColorSec = hex("00FF00")
	db.player[idx].shoeColorTer = hex("0000FF")
	end
	
	--GK PANTS
	db.player[idx].shortstyle = getGKPants(db.player[idx].playerassetid,db.player[idx].shortstyle)
	db.player[idx].shortstyleset = getTeamGKPants(db.player[idx].kit,0)
	
	--SKIN TONE
	db.player[idx].bodySkinToneType = getPlayerPlayerSkinTone(db.player[idx].playerassetid,db.player[idx].bodySkinToneType)
	
	--JERSEY TUCK
	db.player[idx].jerseyTucked = getJerseyTuck(db.player[idx].playerassetid,db.player[idx].jerseyTucked)
	
	--SOCK HEIGHT
	db.player[idx].socklength = getSockHeight(db.player[idx].playerassetid,db.player[idx].socklength)
	
	
	
		
end

---------------------------------------------------------------------------------------------------
-- Get hair color for generic hair recoloring 
function GetHairColorARGB(idx)
	hairColourList = { 0x00edac57, 0x000e0e0d, 0x00a07741, 0x001f160e, 
                       0x00ffd286, 0x006e4d2b, 0x003b2816, 0x00782c08, 
                       0x00c8c9cf, 0x00525355, 0x00345a34, 0x00263f67,
                       0x00f62f0a }

	local clr = 0x00FF0000
	if (db.player[idx].headClass > 0) then
		clr = hairColourList[db.player[idx].hairColor + 1]
		if (clr == nil) then
			clr = 0x00FF0000
		end
	else
		clr = 0x00808080
	end
	return clr
end

---------------------------------------------------------------------------------------------------
function EASWMorphFile(idx)
	if (db.player[idx].isVirtualPro == 1) then
		return string.format("data/easw/deltas_%d.easwmorph", db.player[idx].faceType) --12366)
	else
		return "dummyasset.easwmorph"
	end
end

---------------------------------------------------------------------------------------------------
function GetHeadAndHairAssetType(idx)
	if (db.player[idx].isCreatePlayer == 1) then
		return "cloneasset"
	else
		return ""
	end
end

---------------------------------------------------------------------------------------------------
function MorphFile(idx)
	if (db.player[idx].isCreatePlayer == 1 and db.player[idx].isVirtualPro == 0) then
		return "data/sceneassets/createplayer/head_0_2_0_1_morphtargets.rx3"
	else
		return "dummyasset.rx3"
	end
end

---------------------------------------------------------------------------------------------------
function PlayerAssetShadow(player, lod)
	local gr = gRenderables
	gr:AddAsset(player, lod, "shadow", "data/sceneassets/body/playershadow_4_1_0.rx3")
	gr:CreateMaterial(player, lod, "shadow", "missingShader.fx")
end

---------------------------------------------------------------------------------------------------
function GetCrestAsset(idx)
	if (db.player[idx].isCreationZone == 1) then
		if (db.player[idx].hasCzCrestImage > 0) then
			-- // The "\\" is so that the mounted image can be found properly by Apt
			return "data\\ugc/cz_crest/${db.player[?].crestAssetId}.png;data/ugc/cz_crest/1.png"
		else
			return "data/sceneassets/crest/crest_${db.player[?].crestAssetId}.rx3"
		end
	else
		return "data/sceneassets/kit/kit_${db.player[?].kit}_${db.player[?].kitType}_${db.player[?].kitYear}.rx3"
	end

end

---------------------------------------------------------------------------------------------------
function GetSkinTone(idx, lod)
	local useLight = false
	if (db.player[idx].isVirtualPro == 1) then
		-- // 0 is light, 1 is dark
		useLight = ( db.player[idx].faceGenSkinToneType == 0 )
	else
		useLight = ( db.player[idx].bodySkinToneType < 5 )
	end
	
	if ( useLight ) then
		return ( lod == 0 ) and "skin_light" or "skin_lod_light"
	else
		return ( lod == 0 ) and "skin_dark" or "skin_lod_dark"
	end
end

---------------------------------------------------------------------------------------------------
function GetFaceTone(idx, lod)
	local useLight = false
	if (db.player[idx].isVirtualPro == 1) then
		-- // 0 is light, 1 is dark
		useLight = ( db.player[idx].faceGenSkinToneType == 0 )
	else
		useLight = ( db.player[idx].bodySkinToneType < 5 )
	end
	
	if ( useLight ) then
		return ( lod == 0 ) and "face_light" or "face_lod_light"
	else
		return ( lod == 0 ) and "face_dark" or "face_lod_dark"
	end
end

---------------------------------------------------------------------------------------------------
function PlayerAssetHighLod(player, lod)
	local gr = gRenderables
	
    -- GEO's
	gr:AddAsset(player, lod, "jersey", "data/sceneassets/body/jersey_0_${db.player[?].jerseyCollarType}_${db.player[?].jerseySleeveLength}_${db.player[?].jerseyArmBand}_${db.player[?].jerseyTucked}_${db.player[?].jerseyfit}.rx3")
	gr:AddAsset(player, lod, "arms", "data/sceneassets/body/arms_0_${db.player[?].armLength}.rx3")
	gr:AddAsset(player, lod, "shorts", "data/sceneassets/body/shorts_0_${db.player[?].shortstyle}.rx3")
	gr:AddAsset(player, lod, "shoes",  "data/sceneassets/shoe/playershoe_${db.player[?].playerassetid}.rx3;data/sceneassets/shoe/shoe_${db.player[?].shoeType}.rx3")
	gr:AddAsset(player, lod, "socks", "data/sceneassets/body/sock_0_${db.player[?].socklength}.rx3")
	gr:AddAsset(player, lod, "legs",  "data/sceneassets/body/legs_0_${db.player[?].socklength}.rx3")
	gr:AddAssetEx(player, lod, "${GetHeadAndHairAssetType(?)}", "hair1", "data/sceneassets/hair/hair_${db.player[?].playerassetid}_0_0.rx3;data/sceneassets/hair/hair_${db.player[?].hair}_${db.player[?].faceProxyHeadClass}_0.rx3")
	gr:AddAssetEx(player, lod, "${GetHeadAndHairAssetType(?)}", "hair2", "data/sceneassets/hair/hair_${db.player[?].playerassetid}_0_0.rx3;data/sceneassets/hair/hair_${db.player[?].hair}_${db.player[?].faceProxyHeadClass}_0.rx3")
	gr:AddAssetEx(player, lod, "${GetHeadAndHairAssetType(?)}", "head",  "data/sceneassets/heads/head_${db.player[?].playerassetid}_0.rx3;data/sceneassets/heads/head_${db.player[?].head}_${db.player[?].headClass}.rx3")
    -- Point the eyes to the same asset the head uses, whether it being cloned or not.
	gr:AddAssetEx(player, lod, "fromasset", "eyes", "head")
	-- non volume texture normalMap for socks
	gr:AddAsset(player, lod, "sockbnmlod", "data/sceneassets/kit/shorts_${db.player[?].shortstyle}_bnm_lod.rx3")
	
	-- Add the morph files
	
	local priority = 0	-- default priority
	local temporary = 1	-- mark as temporary asset
	gr:AddAsset(player, lod, "morphhead", "${MorphFile(?)}", priority, temporary)
	gr:AddAsset(player, lod, "easwmorph", "${EASWMorphFile(?)}")
	
	local part = "jersey"
	gr:CreateMaterialFromAttribulator(player, lod, part, "jersey_material", "${AttribMaterial('jersey')}" )
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "jersey_tex", "jersey_cm")
	gr:SetTexture(player, lod, part, "textures", "specularMap", "kittex_common", "jersey_coeff")
	gr:SetTexture(player, lod, part, "textures", "occlusionMap", "jerseyam", "jersey_am")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(player, lod, part, "textures", "weavePatternNormalMap", "cmnweave", "kit_weave")
	gr:SetTexture(player, lod, part, "textures", "wrinkleMap", "jerseybnm", "jersey_nm")
	gr:SetTexture(player, lod, part, "textures", "jerseyNumberShirt_Tens", "kitnumbers", "${db.player[?].kitNumberTens}.Raster")
	gr:SetTexture(player, lod, part, "textures", "jerseyNumberShirt_Units", "kitnumbers", "${db.player[?].kitNumberUnits}.Raster")
	gr:SetTexture(player, lod, part, "textures", "tex_decalmap", "cresttex", "${db.player[?].crestTexName}")
	gr:SetTextureFromRuntime(player, lod, part, "textures", "jerseyName", "namestamp${?}")
	gr:SetTextureFromRuntime(player, lod, part, "textures", "coverageMap", "covmap_${db.player[?].stadiumID}_${db.player[?].stadiumLightID}")
	
	gr:SetHotSpot(player, lod, part, "global", "jersey_decalBounds", "kithotspots", "jersey", "team")
	gr:SetHotSpot(player, lod, part, "global", "jersey_nameBound", "kithotspots", "jersey", "name")
	gr:SetHotSpot(player, lod, part, "global", "jersey_nameArcCenter", "kithotspots", "jersey", "name_arccenter")
		
	gr:SetConstantInt(player, lod, part, "global", "jersey_nameLayout", "${db.player[?].jerseyNameLayout}")
	
	gr:SetConstantARGB(player, lod, part, "global", "jersey_nameColor", "${db.player[?].kitNameColor}")

	skinTone = "${GetSkinTone(?,"..lod..")}"
	faceTone = "${GetFaceTone(?,"..lod..")}"
	
	part = "arms"
	gr:CreateMaterialFromAttribulator(player, lod, part, "head_material",  skinTone)
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "skintex", "body_${db.player[?].bodySkinToneType}_cm.Raster")  
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(player, lod, part, "textures", "normalMap", "bodycmn", "body_nm")
	gr:SetTexture(player, lod, part, "textures", "coeffMap", "bodycmn", "body_coeff")
	gr:SetConstantARGB(player, lod, part, "global", "skincolor", "${db.player[?].playerBodySkinColor}")
	gr:SetTextureFromRuntime(player, lod, part, "textures", "coverageMap", "covmap_${db.player[?].stadiumID}_${db.player[?].stadiumLightID}")

	part = "legs"
	gr:CreateMaterialFromAttribulator(player, lod, part, "head_material", skinTone )
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "skintex", "body_${db.player[?].bodySkinToneType}_cm.Raster")	
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(player, lod, part, "textures", "normalMap", "bodycmn", "body_nm")
	gr:SetTexture(player, lod, part, "textures", "coeffMap", "bodycmn", "body_coeff")
	gr:SetConstantARGB(player, lod, part, "global", "skincolor", "${db.player[?].playerBodySkinColor}")
	gr:SetTextureFromRuntime(player, lod, part, "textures", "coverageMap", "covmap_${db.player[?].stadiumID}_${db.player[?].stadiumLightID}")

	part = "shorts"
	gr:CreateMaterialFromAttribulator(player, lod, part, "shorts_material", "${AttribMaterial('shorts')}") 
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "shortstex", "shorts_cm")
	gr:SetTexture(player, lod, part, "textures", "specularMap", "shortstex", "shorts_coeff")
	gr:SetTexture(player, lod, part, "textures", "occlusionMap", "shortsam", "shorts_am")
	gr:SetTexture(player, lod, part, "textures", "wrinkleMap", "shortsbnm", "shorts_nm")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(player, lod, part, "textures", "weavePatternNormalMap", "cmnweave", "kit_weave")
	gr:SetTexture(player, lod, part, "textures", "tex_decalmap", "cresttex", "${db.player[?].crestTexName}")	
	gr:SetTexture(player, lod, part, "textures", "jerseyNumberShorts_Tens", "shortsnumbers", "${db.player[?].kitNumberTens}.Raster")
	gr:SetTexture(player, lod, part, "textures", "jerseyNumberShorts_Units", "shortsnumbers", "${db.player[?].kitNumberUnits}.Raster")
	gr:SetHotSpot(player, lod, part, "global", "shorts_decalBounds", "shortshotspots", "shorts", "team")
	gr:SetTextureFromRuntime(player, lod, part, "textures", "coverageMap", "covmap_${db.player[?].stadiumID}_${db.player[?].stadiumLightID}")

	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorPri", "${db.player[?].kitColourShortPri}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorSec", "${db.player[?].kitColourShortSec}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorTer", "${db.player[?].kitColourShortTer}")

	-- head
	part = "head"
	gr:CreateMaterialFromAttribulator(player, lod, part, "head_material", faceTone )
	gr:SetSubMesh(player, lod, part, "head")
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "facetex", "head_")
	gr:SetTexture(player, lod, part, "textures", "normalMap", "headcmn", "head_0_nm")
	gr:SetTexture(player, lod, part, "textures", "coeffMap", "headcmn", "head_coeff")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(player, lod, part, "textures", "wrinkleMap", "headcmn", "head_nm_wkl.Raster")
	gr:SetTexture(player, lod, part, "textures", "wrinkleMask", "headcmn", "head_nm_mask.Raster")
	gr:SetTextureFromRuntime(player, lod, part, "textures", "coverageMap", "covmap_${db.player[?].stadiumID}_${db.player[?].stadiumLightID}")

	-- Eyes
	part = "eyes"	 
	gr:CreateMaterialFromAttribulator(player, lod, part, "eye_material", "${AttribMaterial('eyes')}" )
	gr:SetSubMesh(player, lod, part, "eyes")
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "eyetex", "eyes_")
	gr:SetTexture(player, lod, part, "textures", "coeffMap", "headcmn", "eye_coeff")
	gr:SetTexture(player, lod, part, "textures", "normalMap", "headcmn", "eyes_nm")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "env_")
	gr:SetTextureFromRuntime(player, lod, part, "textures", "coverageMap", "covmap_${db.player[?].stadiumID}_${db.player[?].stadiumLightID}")

	-- hair1
	part = "hair1"
	gr:CreateMaterialFromAttribulator(player, lod, part, "hair_material", "${AttribMaterial('player_hair_kk_alphaA')}")
	gr:SetSubMesh(player, lod, part, "alphaA")
	gr:SetPriority(player, lod, part, 1)             -- haircap render before hair 2
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "hairtex", "hair_cm") 
	gr:SetTexture(player, lod, part, "textures", "specAlphaMap", "hairtex", "hair_coeff")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetConstantARGB(player, lod, part, "global", "hairColor", "${GetHairColorARGB(?)}")
	gr:SetTextureFromRuntime(player, lod, part, "textures", "coverageMap", "covmap_${db.player[?].stadiumID}_${db.player[?].stadiumLightID}")

	-- hair2
	part = "hair2"
	gr:CreateMaterialFromAttribulator(player, lod, part, "hair_material2", "${AttribMaterial('player_hair_kk_alphaB')}")
	gr:SetSubMesh(player, lod, part, "alphaB")
	gr:SetPriority(player, lod, part, 2)             -- strands render after hair 1
	gr:SetSelfShadowAlpha(player, lod, part)          -- will use different self shadow shader that accounts for alpha
	--gr:DisableSelfShadow(player, lod, part)          -- Don't render the hairstrands into the selfshadow.
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "hairtex", "hair_cm")
	gr:SetTexture(player, lod, part, "textures", "specAlphaMap", "hairtex", "hair_coeff")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetConstantARGB(player, lod, part, "global", "hairColor", "${GetHairColorARGB(?)}")
	gr:SetTextureFromRuntime(player, lod, part, "textures", "coverageMap", "covmap_${db.player[?].stadiumID}_${db.player[?].stadiumLightID}")

	-- socks
	part = "socks"
	gr:CreateMaterialFromAttribulator(player, lod, "socks", "socks_material", "${AttribMaterial('sock')}" )  
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "shortstex", "shorts_cm")
	gr:SetTexture(player, lod, part, "textures", "specularMap", "shortstex", "shorts_coeff")
	gr:SetTexture(player, lod, part, "textures", "occlusionMap", "shortsam", "shorts_am")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(player, lod, part, "textures", "weavePatternNormalMap", "cmnweave", "kit_weave")
	gr:SetTexture(player, lod, part, "textures", "wrinkleMap", "sockbnmlod", "shorts_nm")
	gr:SetTextureFromRuntime(player, lod, part, "textures", "coverageMap", "covmap_${db.player[?].stadiumID}_${db.player[?].stadiumLightID}")

	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorPri", "${db.player[?].kitColourSocksPri}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorSec", "${db.player[?].kitColourSocksSec}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorTer", "${db.player[?].kitColourSocksTer}")

	-- shoes
	part = "shoes"
	gr:CreateMaterialFromAttribulator(player, lod, part, "shoe_material", "${AttribMaterial('shoe')}" )
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "shoetex", "shoe_cm")	
	gr:SetTexture(player, lod, part, "textures", "normalMap", "shoetex", "shoe_nm")
	gr:SetTexture(player, lod, part, "textures", "coeffMap", "shoetex", "shoe_coeff")	
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTextureFromRuntime(player, lod, part, "textures", "coverageMap", "covmap_${db.player[?].stadiumID}_${db.player[?].stadiumLightID}")

	gr:SetConstantARGB(player, lod, part, "global", "customColorPri", "${db.player[?].shoeColorPri}")
	gr:SetConstantARGB(player, lod, part, "global", "customColorSec", "${db.player[?].shoeColorSec}")
	gr:SetConstantARGB(player, lod, part, "global", "customColorTer", "${db.player[?].shoeColorTer}")
	
	--underarmor neck
	local part = "underneck"
	gr:CreateMaterialFromAttribulator(player, lod, part, "underneck_material", "${AttribMaterial('undergear')}" )
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "jersey_tex", "jersey_cm")
	gr:SetTexture(player, lod, part, "textures", "specularMap", "kittex_common", "jersey_coeff")
	gr:SetTexture(player, lod, part, "textures", "occlusionMap", "jerseyam", "jersey_am")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(player, lod, part, "textures", "weavePatternNormalMap", "cmnweave", "kit_weave")
	gr:SetTexture(player, lod, part, "textures", "wrinkleMap", "jerseybnm", "jersey_nm")
	gr:SetTextureFromRuntime(player, lod, part, "textures", "coverageMap", "covmap_${db.player[?].stadiumID}_${db.player[?].stadiumLightID}")

	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorPri", "${db.player[?].kitColourJerseyPri}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorSec", "${db.player[?].kitColourJerseySec}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorTer", "${db.player[?].kitColourJerseyTer}")
	
	--underarmor sleeves
	local part = "underarms"
	gr:CreateMaterialFromAttribulator(player, lod, part, "underarms_material", "${AttribMaterial('undergear')}" )
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "jersey_tex", "jersey_cm")
	gr:SetTexture(player, lod, part, "textures", "specularMap", "kittex_common", "jersey_coeff")
	gr:SetTexture(player, lod, part, "textures", "occlusionMap", "jerseyam", "jersey_am")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(player, lod, part, "textures", "weavePatternNormalMap", "cmnweave", "kit_weave")
	gr:SetTexture(player, lod, part, "textures", "wrinkleMap", "jerseybnm", "jersey_nm")
	gr:SetTextureFromRuntime(player, lod, part, "textures", "coverageMap", "covmap_${db.player[?].stadiumID}_${db.player[?].stadiumLightID}")
	
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorPri", "${db.player[?].kitColourJerseyPri}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorSec", "${db.player[?].kitColourJerseySec}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorTer", "${db.player[?].kitColourJerseyTer}")

	--undershorts
	local part = "undershorts"
	gr:CreateMaterialFromAttribulator(player, lod, part, "undershorts_material", "${AttribMaterial('undergear')}") 
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "shortstex", "shorts_cm")
	gr:SetTexture(player, lod, part, "textures", "specularMap", "shortstex", "shorts_coeff")
	gr:SetTexture(player, lod, part, "textures", "occlusionMap", "shortsam", "shorts_am")
	gr:SetTexture(player, lod, part, "textures", "wrinkleMap", "shortsbnm", "shorts_nm")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(player, lod, part, "textures", "weavePatternNormalMap", "cmnweave", "kit_weave")
	gr:SetTextureFromRuntime(player, lod, part, "textures", "coverageMap", "covmap_${db.player[?].stadiumID}_${db.player[?].stadiumLightID}")

	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorPri", "${db.player[?].kitColourShortPri}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorSec", "${db.player[?].kitColourShortSec}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorTer", "${db.player[?].kitColourShortTer}")
	
end

---------------------------------------------------------------------------------------------------
function PlayerAssetLowLod(player, lod)
	local gr = gRenderables

	skinLodTone = "${GetSkinTone(?,"..lod..")}"
	faceLodTone = "${GetFaceTone(?,"..lod..")}"


	-- GEO's
	if (lod == 1) then
		gr:AddAsset(player, lod, "jersey", "data/sceneassets/body/jersey_1_${db.player[?].jerseyCollarType}_${db.player[?].jerseySleeveLength}_${db.player[?].jerseyArmBand}_${db.player[?].jerseyTucked}_${db.player[?].jerseyfit}.rx3")
		gr:AddAsset(player, lod, "shorts", "data/sceneassets/body/shorts_1_${db.player[?].shortstyle}.rx3")
		gr:AddAsset(player, lod, "bodyskinlod", "data/sceneassets/body/body_1_${db.player[?].armLength}_0.rx3")
		gr:AddAsset(player, lod, "bodyshoelod", "data/sceneassets/body/shoes_1_0.rx3")
		gr:AddAsset(player, lod, "bodysocklod", "data/sceneassets/body/socks_1_${db.player[?].socklength}.rx3")
		gr:AddAsset(player, lod, "headlod",  "data/sceneassets/body/head_1.rx3")
		gr:AddAsset(player, lod, "eyeslod",  "data/sceneassets/body/head_1.rx3")
	elseif (lod == 2) then
		gr:AddAsset(player, lod, "jersey", "data/sceneassets/body/jersey_2_${db.player[?].jerseySleeveLength}_${db.player[?].jerseyArmBand}_${db.player[?].jerseyTucked}.rx3")
		gr:AddAsset(player, lod, "shorts", "data/sceneassets/body/shorts_2_${db.player[?].shortstyle}.rx3")
		gr:AddAsset(player, lod, "bodyskinlod", "data/sceneassets/body/body_2_${db.player[?].armLength}_0.rx3")
		gr:AddAsset(player, lod, "bodyshoelod", "data/sceneassets/body/shoes_2_0.rx3")
		gr:AddAsset(player, lod, "bodysocklod", "data/sceneassets/body/socks_2_${db.player[?].socklength}.rx3")
		gr:AddAsset(player, lod, "headlod",  "data/sceneassets/body/head_2.rx3")
		gr:AddAsset(player, lod, "eyeslod",  "data/sceneassets/body/head_2.rx3")
	end
	
	gr:AddAsset(player, lod, "hairlod",  "data/sceneassets/hairlod/hairlod_${db.player[?].playerassetid}_0_0.rx3;data/sceneassets/hairlod/hairlod_${db.player[?].hair}_${db.player[idx].faceProxyHeadClass}_0.rx3")
	gr:AddAsset(player, lod, "jerseybnmlod", "data/sceneassets/kit/jersey_${db.player[?].jerseyTucked}_${db.player[?].jerseyfit}_bnm_lod.rx3")
	gr:AddAsset(player, lod, "shortsbnmlod", "data/sceneassets/kit/shorts_${db.player[?].shortstyle}_bnm_lod.rx3")

	local part = "jersey"
	gr:CreateMaterialFromAttribulator(player, lod, part, "jersey_material", "${AttribMaterial('jerseylod')}" )
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "jersey_tex", "jersey_cm")
	gr:SetTexture(player, lod, part, "textures", "specularMap", "kittex_common", "jersey_coeff")
	gr:SetTexture(player, lod, part, "textures", "occlusionMap", "jerseyam", "jersey_am")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(player, lod, part, "textures", "weavePatternNormalMap", "cmnweave", "kit_weave")
	gr:SetTexture(player, lod, part, "textures", "wrinkleMap", "jerseybnmlod", "jersey_nm")
	gr:SetTexture(player, lod, part, "textures", "jerseyNumberShirt_Tens", "kitnumbers", "${db.player[?].kitNumberTens}.Raster")
	gr:SetTexture(player, lod, part, "textures", "jerseyNumberShirt_Units", "kitnumbers", "${db.player[?].kitNumberUnits}.Raster")
	gr:SetTexture(player, lod, part, "textures", "tex_decalmap", "cresttex", "${db.player[?].crestTexName}")
	gr:SetTextureFromRuntime(player, lod, part, "textures", "jerseyName", "namestamp${?}")
	gr:SetTextureFromRuntime(player, lod, part, "textures", "coverageMap", "covmap_${db.player[?].stadiumID}_${db.player[?].stadiumLightID}")
	
	gr:SetHotSpot(player, lod, part, "global", "jersey_decalBounds", "kithotspots", "jersey", "team")
	gr:SetHotSpot(player, lod, part, "global", "jersey_nameBound", "kithotspots", "jersey", "name")
	gr:SetHotSpot(player, lod, part, "global", "jersey_nameArcCenter", "kithotspots", "jersey", "name_arccenter")
	gr:SetConstantInt(player, lod, part, "global", "jersey_nameLayout", "${db.player[?].jerseyNameLayout}")
	
	gr:SetConstantARGB(player, lod, part, "global", "jersey_nameColor", "${db.player[?].kitNameColor}")

	part = "shorts"
	gr:CreateMaterialFromAttribulator(player, lod, part, "body_material", "${AttribMaterial('shortslod')}" )
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "shortstex", "shorts_cm")
	gr:SetTexture(player, lod, part, "textures", "specularMap", "shortstex", "shorts_coeff")
	gr:SetTexture(player, lod, part, "textures", "occlusionMap", "shortsam", "shorts_am")
	gr:SetTexture(player, lod, part, "textures", "wrinkleMap", "shortsbnmlod", "shorts_nm")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(player, lod, part, "textures", "weavePatternNormalMap", "cmnweave", "kit_weave")
	gr:SetTexture(player, lod, part, "textures", "tex_decalmap", "cresttex", "${db.player[?].crestTexName}")
	gr:SetTexture(player, lod, part, "textures", "jerseyNumberShorts_Tens", "shortsnumbers", "${db.player[?].kitNumberTens}.Raster")
	gr:SetTexture(player, lod, part, "textures", "jerseyNumberShorts_Units", "shortsnumbers", "${db.player[?].kitNumberUnits}.Raster")
	gr:SetHotSpot(player, lod, part, "global", "shorts_decalBounds", "shortshotspots", "shorts", "team")
	gr:SetTextureFromRuntime(player, lod, part, "textures", "coverageMap", "covmap_${db.player[?].stadiumID}_${db.player[?].stadiumLightID}")

	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorPri", "${db.player[?].kitColourShortPri}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorSec", "${db.player[?].kitColourShortSec}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorTer", "${db.player[?].kitColourShortTer}")

	part = "bodyskinlod"
	gr:CreateMaterialFromAttribulator(player, lod, part, "body_material", skinLodTone )
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "skintex", "body_${db.player[?].bodySkinToneType}_cm")  
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(player, lod, part, "textures", "normalMap", "bodycmn", "body_nm")
	gr:SetTexture(player, lod, part, "textures", "coeffMap", "bodycmn", "body_coeff")
	gr:SetConstantARGB(player, lod, part, "global", "skincolor", "${db.player[?].playerBodySkinColor}")
	gr:SetTextureFromRuntime(player, lod, part, "textures", "coverageMap", "covmap_${db.player[?].stadiumID}_${db.player[?].stadiumLightID}")

	part = "bodyshoelod"
	gr:CreateMaterialFromAttribulator(player, lod, part, "body_material", "${AttribMaterial('shoelod')}" )
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "shoetex", "shoe_cm")	
	gr:SetTexture(player, lod, part, "textures", "normalMap", "shoetex", "shoe_nm")
	gr:SetTexture(player, lod, part, "textures", "coeffMap", "shoetex", "shoe_coeff")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")	
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTextureFromRuntime(player, lod, part, "textures", "coverageMap", "covmap_${db.player[?].stadiumID}_${db.player[?].stadiumLightID}")

	gr:SetConstantARGB(player, lod, part, "global", "customColorPri", "${db.player[?].shoeColorPri}")
	gr:SetConstantARGB(player, lod, part, "global", "customColorSec", "${db.player[?].shoeColorSec}")
	gr:SetConstantARGB(player, lod, part, "global", "customColorTer", "${db.player[?].shoeColorTer}")

	part = "bodysocklod"
	gr:CreateMaterialFromAttribulator(player, lod, part, "body_material", "${AttribMaterial('socklod')}" )
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "shortstex", "shorts_cm")
	gr:SetTexture(player, lod, part, "textures", "specularMap", "shortstex", "shorts_coeff")
	gr:SetTexture(player, lod, part, "textures", "occlusionMap", "shortsam", "shorts_am")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(player, lod, part, "textures", "weavePatternNormalMap", "cmnweave", "kit_weave")
	gr:SetTexture(player, lod, part, "textures", "wrinkleMap", "shortsbnmlod", "shorts_nm")
	gr:SetTextureFromRuntime(player, lod, part, "textures", "coverageMap", "covmap_${db.player[?].stadiumID}_${db.player[?].stadiumLightID}")

	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorPri", "${db.player[?].kitColourSocksPri}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorSec", "${db.player[?].kitColourSocksSec}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorTer", "${db.player[?].kitColourSocksTer}")

	-- eyes
	part = "eyeslod"
	gr:CreateMaterialFromAttribulator(player, lod, part, "head_material", "${AttribMaterial('eyeslod')}" )
	gr:SetSubMesh(player, lod, part, "eye")
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "eyetex", "eyes_")
	gr:SetTexture(player, lod, part, "textures", "coeffMap", "headcmn", "eye_coeff")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "env_")
	gr:SetTextureFromRuntime(player, lod, part, "textures", "coverageMap", "covmap_${db.player[?].stadiumID}_${db.player[?].stadiumLightID}")

	-- head
	part = "headlod"
	gr:CreateMaterialFromAttribulator(player, lod, part, "head_material", faceLodTone )
	gr:SetSubMesh(player, lod, part, "head")
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "facetex", "head_")
	gr:SetTexture(player, lod, part, "textures", "normalMap", "headcmn", "head_0_nm")
	gr:SetTexture(player, lod, part, "textures", "coeffMap", "headcmn", "head_coeff")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTextureFromRuntime(player, lod, part, "textures", "coverageMap", "covmap_${db.player[?].stadiumID}_${db.player[?].stadiumLightID}")

	-- hair
	part = "hairlod"
	gr:CreateMaterialFromAttribulator(player, lod, part, "hair_material", "${AttribMaterial('player_hair_kk_alphaA_lod')}")
	gr:SetSubMesh(player, lod, part, "alphaA")
	gr:SetPriority(player, lod, part, 1)
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "hairtex", "hair_cm")
	gr:SetTexture(player, lod, part, "textures", "specAlphaMap", "hairtex", "hair_coeff")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetConstantARGB(player, lod, part, "global", "hairColor", "${GetHairColorARGB(?)}")
	
	--underarmor neck
	local part = "underneck"
	gr:CreateMaterialFromAttribulator(player, lod, part, "underneck_material", "${AttribMaterial('socklod')}" )
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "jersey_tex", "jersey_cm")
	gr:SetTexture(player, lod, part, "textures", "specularMap", "kittex_common", "jersey_coeff")
	gr:SetTexture(player, lod, part, "textures", "occlusionMap", "jerseyam", "jersey_am")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(player, lod, part, "textures", "weavePatternNormalMap", "cmnweave", "kit_weave")
	gr:SetTexture(player, lod, part, "textures", "wrinkleMap", "jerseybnmlod", "jersey_nm")
	gr:SetTextureFromRuntime(player, lod, part, "textures", "coverageMap", "covmap_${db.player[?].stadiumID}_${db.player[?].stadiumLightID}")

	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorPri", "${db.player[?].kitColourJerseyPri}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorSec", "${db.player[?].kitColourJerseySec}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorTer", "${db.player[?].kitColourJerseyTer}")

	--underarmor sleeves
	local part = "underarms"
	gr:CreateMaterialFromAttribulator(player, lod, part, "underarms_material", "${AttribMaterial('socklod')}" )
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "jersey_tex", "jersey_cm")
	gr:SetTexture(player, lod, part, "textures", "specularMap", "kittex_common", "jersey_coeff")
	gr:SetTexture(player, lod, part, "textures", "occlusionMap", "jerseyam", "jersey_am")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(player, lod, part, "textures", "weavePatternNormalMap", "cmnweave", "kit_weave")
	gr:SetTexture(player, lod, part, "textures", "wrinkleMap", "jerseybnm", "jersey_nm")
	gr:SetTextureFromRuntime(player, lod, part, "textures", "coverageMap", "covmap_${db.player[?].stadiumID}_${db.player[?].stadiumLightID}")

	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorPri", "${db.player[?].kitColourJerseyPri}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorSec", "${db.player[?].kitColourJerseySec}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorTer", "${db.player[?].kitColourJerseyTer}")

	
	--undershorts
	local part = "undershorts"
	gr:CreateMaterialFromAttribulator(player, lod, part, "undershorts_material", "${AttribMaterial('socklod')}") 
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "shortstex", "shorts_cm")
	gr:SetTexture(player, lod, part, "textures", "specularMap", "shortstex", "shorts_coeff")
	gr:SetTexture(player, lod, part, "textures", "occlusionMap", "shortsam", "shorts_am")
	gr:SetTexture(player, lod, part, "textures", "wrinkleMap", "shortsbnmlod", "shorts_nm")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(player, lod, part, "textures", "weavePatternNormalMap", "cmnweave", "kit_weave")
	gr:SetTextureFromRuntime(player, lod, part, "textures", "coverageMap", "covmap_${db.player[?].stadiumID}_${db.player[?].stadiumLightID}")

	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorPri", "${db.player[?].kitColourShortPri}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorSec", "${db.player[?].kitColourShortSec}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorTer", "${db.player[?].kitColourShortTer}")
	
end

---------------------------------------------------------------------------------------------------
function GetFaceTexTemplate(idx)
	if(db.player[idx].isVirtualPro == 1) then
		--return "data/sceneassets/faces/face_"..db.player[idx].faceType.."_"..db.player[idx].faceProxyHeadClass.."_0_"..db.player[idx].eyebrow.."_"..db.player[idx].faceSideBurn.."_"..db.player[idx].facialHairColor.."_"..db.player[idx].facialHairType.."_"..db.player[idx].headSkinType.."_"..db.player[idx].headSkinToneType.."_textures."..db.player[idx].faceTexExtension..";data/sceneassets/faces/face_"..db.player[idx].faceTypeFallback.."_"..db.player[idx].faceProxyHeadClass.."_0_"..db.player[idx].eyebrow.."_"..db.player[idx].faceSideBurnFallback.."_"..db.player[idx].facialHairColorFallback.."_"..db.player[idx].facialHairTypeFallback.."_"..db.player[idx].headSkinTypeFallback.."_"..db.player[idx].headSkinToneTypeFallback.."_textures.rx3"
		facetex = string.format("data/easw/head_%d.dds", db.player[idx].faceType)
		return facetex..";data/sceneassets/faces/face_"..db.player[idx].faceTypeFallback.."_"..db.player[idx].faceProxyHeadClass.."_0_"..db.player[idx].eyebrow.."_"..db.player[idx].faceSideBurnFallback.."_"..db.player[idx].facialHairColorFallback.."_"..db.player[idx].facialHairTypeFallback.."_"..db.player[idx].headSkinTypeFallback.."_"..db.player[idx].headSkinToneTypeFallback.."_textures.rx3"
	else
		return "data/sceneassets/faces/face_"..db.player[idx].playerassetid.."_0_0_0_0_0_0_0_0_textures.rx3;data/sceneassets/faces/face_"..db.player[idx].faceType.."_"..db.player[idx].faceProxyHeadClass.."_0_"..db.player[idx].eyebrow.."_"..db.player[idx].faceSideBurn.."_"..db.player[idx].facialHairColor.."_"..db.player[idx].facialHairType.."_"..db.player[idx].headSkinType.."_"..db.player[idx].headSkinToneType.."_textures."..db.player[idx].faceTexExtension
	end
end

---------------------------------------------------------------------------------------------------
function GetJerseyBMN(idx)

	if(db.player[idx].forceLowResBNM == 1 or db.player[idx].forcePowerOfTwoBNM == 1) then
		return "data/sceneassets/kit/jersey_${db.player[?].jerseyTucked}_${db.player[?].jerseyfit}_bnm_x2.rx3"
	end
		
	return "data/sceneassets/kit/jersey_${db.player[?].jerseyTucked}_${db.player[?].jerseyfit}_bnm.rx3"
end

---------------------------------------------------------------------------------------------------
function GetShortsBMN(idx)

	if(db.player[idx].forcePowerOfTwoBNM == 1 or db.player[idx].forceLowResBNM == 1) then
		return "data/sceneassets/kit/shorts_0_bnm_x2.rx3"
	end
	
	return "data/sceneassets/kit/shorts_${db.player[idx].shortstyle}_bnm.rx3"
end

---------------------------------------------------------------------------------------------------
-- returns kit texture or goalie pants kit 5200
function GetShortsTex(idx)
	if(db.player[idx].shortstyle == 1) then
		return "data/sceneassets/kit/kit_5200_0_0.rx3"
	else
		return "data/sceneassets/kit/kit_${db.player[?].kit}_${db.player[?].kitType}_${db.player[?].kitYear}.rx3"
	end
end

function GetKitTextureOperation(idx)
	if (db.player[idx].useTextureComposition == 1) then
		-- Creation Zone requires generated textures, describe the operation
		-- assetOperation generatetexture: "generatetexture texname width, height, mipCount, compression"
		return "generatetexture jersey_cm 1024,1024,9,eadxt1"
	else
		-- For others we do not need to generate the texture, so we just extract the source asset
		return "extracttexture jersey_cm"
	end
end

function GetKitTextureAssetName(idx)
	if (db.player[idx].useTextureComposition == 1) then
		-- Creation Zone requires generated textures, thus give the asset a unique name
		-- For CZ, kittype is always home, and year is always zero.
		return "gentex_kit_${db.player[?].kit}_${db.player[?].kitType}_${db.player[?].kitYear}_${db.player[?].teamside}_${db.player[?].kitColourJerseyPri}_${db.player[?].kitColourJerseySec}_${db.player[?].kitColourJerseyTer}"
	else
		-- Keep regular rx3 name as this is the source of the texture
		return "data/sceneassets/kit/kit_${db.player[?].kit}_${db.player[?].kitType}_${db.player[?].kitYear}.rx3"
	end
end


---------------------------------------------------------------------------------------------------
function PlayerAssetLod(player, lod)
	local gr = gRenderables
	
	local defaultpriority = 0	-- default priority

	gr:AddCallback(player, lod, "PlayerUpdate(?)")
	
	local kitTexAsset = "data/sceneassets/kit/kit_${db.player[?].kit}_${db.player[?].kitType}_${db.player[?].kitYear}.rx3"
	
	-- Generic files needed by all LODs
	gr:AddAsset(player, lod, "shader", "data/fifarna/shader.big")		
	gr:AddAsset(player, lod, "charcmn", "data/sceneassets/charactercmn/charactercmn_${db.player[?].envLighting}.rx3")	
	gr:AddAsset(player, lod, "bodycmn", "data/sceneassets/body/body_common_textures.rx3")	
	gr:AddAsset(player, lod, "headcmn", "data/sceneassets/heads/head_common_textures.rx3")	

	-- Sponsor image for stamping onto kit
	gr:AddAsset(player, lod, "sponsortex", "data/ugc/cz_sponsor/${db.player[?].sponsorAssetId}.png;data/ugc/cz_sponsor/1.png", defaultpriority, ALLOCTYPE_TEMP_AUTO_RELEASE)
	
	-- gr:AddAssetEx(asset, lod, assetOperation, assetPart, containerName)
	-- extracttexture will create an asset with just the texture you extract from the source asset, this way we can free the original rx3, freeing unused textures.
	gr:AddAssetEx(player, lod, "extracttexture jersey_coeff", "kittex_common" , kitTexAsset)
	gr:AddAssetEx(player, lod, "extracttexture shorts_cm,shorts_coeff", "shortstex" , "${GetShortsTex(?)}")
	gr:AddAssetEx(player, lod, "extracthotspots", "kithotspots" , kitTexAsset)
	gr:AddAssetEx(player, lod, "extracthotspots", "shortshotspots",  "${GetShortsTex(?)}")
	gr:AddAssetEx(player, lod, "extracttexture ${db.player[?].crestTexName}", "cresttex", "${GetCrestAsset(?)}")
	

	-- Texture composition code
	-- Add the template asset as a temporary asset, auto releasing it when it's not being used (after texture generation in this case)
	gr:AddAssetEx(player, lod, "extracttexture jersey_cm", "kittex_cm_template" , kitTexAsset, defaultpriority, ALLOCTYPE_TEMP_AUTO_RELEASE)
	local part = "jersey_tex"
	-- GetKitTextureOperation will determine if texture composition is needed.
	gr:AddAssetEx(player, lod, "${GetKitTextureOperation(?)}", part , "${GetKitTextureAssetName(?)}")
	-- Describe texture composition in case we have to generate the texture, this material won't be created if no composition is needed.
	gr:CreateMaterial(player, lod, part, "texcomp.fx" )
	gr:SetTexture(player, lod, part, "textures", "texcomp_tex0", "kittex_cm_template", "jersey_cm")
	gr:SetTexture(player, lod, part, "textures", "texcomp_tex1", "sponsortex", "png")
	gr:SetConstantARGB(player, lod, part, "global", "recolorCustomColorPri", "${db.player[?].kitColourJerseyPri}")
	gr:SetConstantARGB(player, lod, part, "global", "recolorCustomColorSec", "${db.player[?].kitColourJerseySec}")
	gr:SetConstantARGB(player, lod, part, "global", "recolorCustomColorTer", "${db.player[?].kitColourJerseyTer}")
	gr:SetConstantARGB(player, lod, part, "global", "recolourMult", "${db.player[?].sponsorcolour}")
	gr:SetConstantHotSpot(player, lod, part, "global", "samplerBounds1", "${db.player[?].hotspotJerseySponsorL};${db.player[?].hotspotJerseySponsorT};${db.player[?].hotspotJerseySponsorR};${db.player[?].hotspotJerseySponsorB}")
	-- End of texture composition
	
	-- Set the jersey texture as a runtime texture so we can use it outside of player
	gr:SetRuntimeTexture(player, lod, "jersey_${db.player[?].kit}_${db.player[?].kitType}_${db.player[?].isgoalie}_${db.player[?].teamside}" , "jersey_tex", "jersey_cm")
	
	gr:AddAsset(player, lod, "shoetex", "data/sceneassets/shoe/playershoe_${db.player[?].playerassetid}_0_textures.rx3;data/sceneassets/shoe/shoe_${db.player[?].shoeType}_${db.player[?].shoeDesign}_textures.rx3")	
	gr:AddAsset(player, lod, "skintex", "data/sceneassets/body/skin_${db.player[?].bodySkinToneType}_textures.rx3")
	
	gr:AddAsset(player, lod, "hairtex", "data/sceneassets/hair/hair_${db.player[?].playerassetid}_0_textures.rx3;data/sceneassets/hair/hair_${db.player[?].hair}_${db.player[?].faceProxyHeadClass}_textures.rx3")
	gr:AddAsset(player, lod, "shortsam", "data/sceneassets/kit/shorts_${db.player[?].shortstyle}_${db.player[?].wet}_textures.rx3")
	gr:AddAsset(player, lod, "jerseyam", "data/sceneassets/kit/jersey_${db.player[?].jerseyTucked}_${db.player[?].wet}_textures.rx3")
	local jerseyBNM = "${GetJerseyBMN(?)}"
	gr:AddAsset(player, lod, "jerseybnm", jerseyBNM)

	gr:AddAsset(player, lod, "cmnweave", "data/sceneassets/kit/kitweave.rx3")	
	local shortsBNM = "${GetShortsBMN(?)}"
	gr:AddAsset(player, lod, "shortsbnm", shortsBNM)
	
	-- Dirt masks not used in FIFARNA There is no runtime logic to drive them besides the expensiveness
	-- gr:AddAsset(player, lod, "shortsdk", "data/sceneassets/kit/shorts_dk.rx3")
	-- gr:AddAsset(player, lod, "jerseydk", "data/sceneassets/kit/jersey_dk.rx3")

	gr:AddAsset(player, lod, "eyetex", "data/sceneassets/heads/eyes_${db.player[?].playerassetid}_0_textures.rx3;data/sceneassets/heads/eyes_${db.player[?].eyeColor}_${db.player[?].faceProxyHeadClass}_textures.rx3")

	
	-- Add font as a temporary asset, because the font is used after the load (bind time), we still have to manually release it from the renderable
	-- TODO: add font stamping support to composite instead of having the renderable do this at bind time
	gr:AddAsset(player, lod, "font", "data/sceneassets/jerseyfonts/font_${db.player[?].kitNameFont}.ttf", defaultpriority, ALLOCTYPE_TEMP_MANUAL_RELEASE)
	gr:AddAsset(player, lod, "kitnumbers", "data/sceneassets/kitnumbers/kitnumbers_${db.player[?].kitNumberFont}_${db.player[?].kitNumberColor}.rx3;data/sceneassets/kitnumbers/kitnumbers_0_0.rx3")
	gr:AddAsset(player, lod, "shortsnumbers", "data/sceneassets/kitnumbers/kitnumbers_${db.player[?].shortsNumberFont}_${db.player[?].shortsNumberColor}.rx3;data/sceneassets/kitnumbers/kitnumbers_0_0.rx3")
	
	local faceGenTemplate = "${GetFaceTexTemplate(?)}"
	gr:AddAsset(player, lod, "facetex", faceGenTemplate)
	
	gr:AddAsset(player, lod, "underarms", "data/sceneassets/body/underarms_0_${db.player[?].underarms}.rx3")
	gr:AddAsset(player, lod, "underneck", "data/sceneassets/body/underneck_0_${db.player[?].underneck}.rx3")
	gr:AddAsset(player, lod, "undershorts", "data/sceneassets/body/undershorts_0_${db.player[?].undershorts}.rx3")


	if (lod == 0) then
		PlayerAssetHighLod(player, lod)
	elseif (lod == 1) then
		PlayerAssetLowLod(player, lod)	
	elseif (lod == 2) then
		PlayerAssetLowLod(player, lod)	
	elseif (lod == 3) then
		PlayerAssetShadow(player, lod)
	end	
	
end

---------------------------------------------------------------------------------------------------
function PlayerAssetBind(player)
	PlayerAssetLod(player, 0)
	PlayerAssetLod(player, 1)
	PlayerAssetLod(player, 2)
	PlayerAssetLod(player, 3)

end










tournamentRefereeKits = {}
tournamentRefereeKitsCollar = {}

function assignTournamentRefereeKits(tournament,id,collar)
tournamentRefereeKits[tournament] = id
tournamentRefereeKitsCollar[tournament] = collar
end

function getTournamentRefereeKits(tourn,id,home)

if (tournamentRefereeKits[tourn] ~= nil) then
return tournamentRefereeKits[tourn]
elseif (((tourn == -1) or (tourn == 15)) and (teamTournament[home] ~= nil)) then

if (tournamentRefereeKits[teamTournament[home]] ~= nil) then
return tournamentRefereeKits[teamTournament[home]]
else
return id
end

else
return id
end

end

function getTournamentRefereeKitsCollar(tourn,id,home)

if (tournamentRefereeKitsCollar[tourn] ~= nil) then
return tournamentRefereeKitsCollar[tourn]
elseif (((tourn == -1) or (tourn == 15)) and (teamTournament[home] ~= nil)) then

if (tournamentRefereeKitsCollar[teamTournament[home]] ~= nil) then
return tournamentRefereeKitsCollar[teamTournament[home]]
else
return id
end

else
return id
end

end


tournamentPlayerKits = {}
tournamentPlayerKitsNumber = {}
tournamentPlayerKitsName = {}

function assignTournamentPlayerKits(team,tourn,set,number,name)

if (tournamentPlayerKits[team] == nil) then
tournamentPlayerKits[team] = {}
tournamentPlayerKitsNumber[team] = {}
tournamentPlayerKitsName[team] = {}
end

-- if (tournamentPlayerKits[team][tourn] == nil) then
-- tournamentPlayerKits[team][tourn] = {}
-- end

tournamentPlayerKits[team][tourn] = set
tournamentPlayerKitsNumber[team][tourn] = number
tournamentPlayerKitsName[team][tourn] = name
end

function getTournamentPlayerKits(team,tourn,set)

if (tournamentPlayerKits[team] ~= nil) then
if (tournamentPlayerKits[team][tourn] ~= nil) then
return tournamentPlayerKits[team][tourn]
end
end

return set
end

-- function getTournamentPlayerKitsNumber(team,tourn,num)

-- if (tournamentPlayerKitsNumber[team][tourn] == -1) then
-- return num
-- end

-- return tournamentPlayerKitsNumber[team][tourn]
-- end

-- function getTournamentPlayerKitsName(team,tourn,name)
-- if (tournamentPlayerKitsName[team][tourn] == -1) then
-- return name
-- end

-- return tournamentPlayerKitsName[team][tourn]
-- end



playerBoot = {}

function assignPlayerBoot(id,boot)

if (type(boot) == "number") then
playerBoot[id] = boot
else
playerBoot[id] = boot[math.random(#boot)]
end


end

function getPlayerBoot(id,boot)

if (globalBoot ~= -1) then
return globalBoot
end

if (playerBoot[id] ~= nil) then
return playerBoot[id]
end

if ((genericBootReplace ~= nil) and (boot == 0)) then
return genericBootReplace[(id%#genericBootReplace)+1]
end

return boot
end


gkPants = {}

function assignGKPants(id)
gkPants[id] = 1
end

function getGKPants(id,pant)

if (gkPants[id] ~= nil) then
return gkPants[id]
else
return pant
end

end


playerFace = {}

function assignPlayerFace(id)
playerFace[id] = 0
end

function getPlayerFace(id,headtype)

if (playerFace[id] ~= nil) then
return playerFace[id]
else
return headtype
end

end


gkKits = {}
gkKitsRandom = {}

function assignGKKit(team,player,gk)

if (gkKits[team] == nil) then
gkKits[team] = {}
end

if (type(gk) == "number") then
gkKits[team][player] = gk
else
--gkKits[team][player] = gk[(gkKitSeed % #gk)+1]
gkKits[team][player] = gk[math.random(#gk)]
end

end

function assignRandomGKKit(team,player,gk)

if (gkKitsRandom[team] == nil) then
gkKitsRandom[team] = {}
end

gkKitsRandom[team][player] = gk
end

function getGKKit(team,player,home,away,gk)

-- if (matchGK[team] ~= nil) then
-- if (matchGK[team][home] ~= nil) then
-- if (matchGK[team][home][away] ~= nil) then
-- return matchGK[team][home][away]
-- end
-- end
-- end

if (matchKit[team] ~= nil) then
if (matchKit[team][home] ~= nil) then
if (matchKit[team][home][away] ~= nil) then
if (matchKit[team][home][away][gk] ~= nil) then
return matchKit[team][home][away][gk]
end
end
end
end


if (gkKitsRandom[team] ~= nil) then
if (gkKitsRandom[team][player] ~= nil) then
local count = #gkKitsRandom[team][player]
count = (home + away) % count
return gkKitsRandom[team][player][count+1]
end
end

if (gkKits[team] ~= nil) then
if (gkKits[team][player] ~= nil) then
return gkKits[team][player]
end
end

return gk
end


kitCollar = {}
kitNumberSet = {}
kitNumberColourShirt = {}
kitNumberColourShort = {}
kitNameFont = {}
kitNameColour = {}
kitFit = {}
kitNameCurve = {}


function assignKitDetails(team,kit,namefont,namecolour,lay,numberset,numbercolourshirt,numbercolourshort,fit,collar)

if (kitCollar[team] == nil) then
kitCollar[team] = {}
end

if (kitNumberSet[team] == nil) then
kitNumberSet[team] = {}
end

if (kitNumberColourShirt[team] == nil) then
kitNumberColourShirt[team] = {}
end

if (kitNumberColourShort[team] == nil) then
kitNumberColourShort[team] = {}
end

if (kitNameFont[team] == nil) then
kitNameFont[team] = {}
end

if (kitNameColour[team] == nil) then
kitNameColour[team] = {}
end

if (kitFit[team] == nil) then
kitFit[team] = {}
end

if (kitNameCurve[team] == nil) then
kitNameCurve[team] = {}
end


kitCollar[team][kit] = collar
kitNumberSet[team][kit] = numberset
kitNumberColourShirt[team][kit] = numbercolourshirt
kitNumberColourShort[team][kit] = numbercolourshort
kitNameFont[team][kit] = namefont

if (namecolour ~= -1) then
kitNameColour[team][kit] = hex(namecolour)
end

kitFit[team][kit] = fit
kitNameCurve[team][kit] = lay
end


kitCollarTournament = {}
kitNumberSetTournament = {}
kitNumberColourShirtTournament = {}
kitNumberColourShortTournament = {}
kitNameFontTournament = {}
kitNameColourTournament = {}
kitFitTournament = {}
kitNameCurveTournament = {}


function assignTournamentKitDetails(team,kit,tournament,namefont,namecolour,lay,numberset,numbercolourshirt,numbercolourshort,fit,collar)

if (kitCollarTournament[team] == nil) then
kitCollarTournament[team] = {}
end

if (kitNumberSetTournament[team] == nil) then
kitNumberSetTournament[team] = {}
end

if (kitNumberColourShirtTournament[team] == nil) then
kitNumberColourShirtTournament[team] = {}
end

if (kitNumberColourShortTournament[team] == nil) then
kitNumberColourShortTournament[team] = {}
end

if (kitNameFontTournament[team] == nil) then
kitNameFontTournament[team] = {}
end

if (kitNameColourTournament[team] == nil) then
kitNameColourTournament[team] = {}
end

if (kitFitTournament[team] == nil) then
kitFitTournament[team] = {}
end

if (kitNameCurveTournament[team] == nil) then
kitNameCurveTournament[team] = {}
end



if (kitCollarTournament[team][kit] == nil) then
kitCollarTournament[team][kit] = {}
end

if (kitNumberSetTournament[team][kit] == nil) then
kitNumberSetTournament[team][kit] = {}
end

if (kitNumberColourShirtTournament[team][kit] == nil) then
kitNumberColourShirtTournament[team][kit] = {}
end

if (kitNumberColourShortTournament[team][kit] == nil) then
kitNumberColourShortTournament[team][kit] = {}
end

if (kitNameFontTournament[team][kit] == nil) then
kitNameFontTournament[team][kit] = {}
end

if (kitNameColourTournament[team][kit] == nil) then
kitNameColourTournament[team][kit] = {}
end

if (kitFitTournament[team][kit] == nil) then
kitFitTournament[team][kit] = {}
end

if (kitNameCurveTournament[team][kit] == nil) then
kitNameCurveTournament[team][kit] = {}
end



kitCollarTournament[team][kit][tournament] = collar
kitNumberSetTournament[team][kit][tournament] = numberset
kitNumberColourShirtTournament[team][kit][tournament] = numbercolourshirt
kitNumberColourShortTournament[team][kit][tournament] = numbercolourshort
kitNameFontTournament[team][kit][tournament] = namefont

if (namecolour ~= -1) then
kitNameColourTournament[team][kit][tournament] = hex(namecolour)
end

kitFitTournament[team][kit][tournament] = fit
kitNameCurveTournament[team][kit][tournament] = lay
end


function getKitCollar(team,kit,item,tournament)

if (kitCollarTournament[team] ~= nil) then
if (kitCollarTournament[team][kit] ~= nil) then
if ((kitCollarTournament[team][kit][tournament] ~= nil) and (kitCollarTournament[team][kit][tournament] ~= -1)) then
return kitCollarTournament[team][kit][tournament]
end
end
end

if (tournament < 1800) then

if (kitCollar[team] ~= nil) then
if ((kitCollar[team][kit] ~= nil) and (kitCollar[team][kit] ~= -1)) then
return kitCollar[team][kit]
end
end

end

return item
end

function getKitNumberSet(team,kit,item,tournament,teamdef)

if (kitNumberSetTournament[team] ~= nil) then
if (kitNumberSetTournament[team][kit] ~= nil) then
if ((kitNumberSetTournament[team][kit][tournament] ~= nil) and (kitNumberSetTournament[team][kit][tournament] ~= -1)) then
return kitNumberSetTournament[team][kit][tournament]
end
end
end

if (tournament < 1800) then

if ((globalTournamentKitNumbers[tournament] ~= nil) and (globalTournamentKitNumbers[tournament] ~= -1)) then
return globalTournamentKitNumbers[tournament]
end

if (tournamentPlayerKitsNumber[team] ~= nil) then
if ((tournamentPlayerKitsNumber[team][tournament] ~= nil) and (tournamentPlayerKitsNumber[team][tournament] ~= -1)) then
return tournamentPlayerKitsNumber[team][tournament]
end
end

if (kitNumberSet[team] ~= nil) then
if ((kitNumberSet[team][kit] ~= nil) and (kitNumberSet[team][kit] ~= -1)) then
return kitNumberSet[team][kit]
end
end

if (teamTournament[teamdef] ~= nil) then
if ((globalTournamentKitNumbers[teamTournament[teamdef]] ~= nil) and (globalTournamentKitNumbers[teamTournament[teamdef]] ~= -1)) then
return globalTournamentKitNumbers[teamTournament[teamdef]]
end
-- if ((genericLeagueKitNumbers[teamTournament[teamdef]] ~= nil) and (genericLeagueKitNumbers[teamTournament[teamdef]] ~= -1)) then
-- return genericLeagueKitNumbers[teamTournament[teamdef]]
-- end
end

end

return item
end

function getKitNumberColourShirt(team,kit,item,tournament)

if (kitNumberColourShirtTournament[team] ~= nil) then
if (kitNumberColourShirtTournament[team][kit] ~= nil) then
if ((kitNumberColourShirtTournament[team][kit][tournament] ~= nil) and (kitNumberColourShirtTournament[team][kit][tournament] ~= -1)) then
return kitNumberColourShirtTournament[team][kit][tournament]
end
end
end

if (tournament < 1800) then

if (kitNumberColourShirt[team] ~= nil) then
if ((kitNumberColourShirt[team][kit] ~= nil) and (kitNumberColourShirt[team][kit] ~= -1)) then
return kitNumberColourShirt[team][kit]
end
end

end

return item
end

function getKitNumberColourShort(team,kit,item,tournament)

if (kitNumberColourShortTournament[team] ~= nil) then
if (kitNumberColourShortTournament[team][kit] ~= nil) then
if ((kitNumberColourShortTournament[team][kit][tournament] ~= nil) and (kitNumberColourShortTournament[team][kit][tournament] ~= -1)) then
return kitNumberColourShortTournament[team][kit][tournament]
end
end
end

if (tournament < 1800) then

if (kitNumberColourShort[team] ~= nil) then
if ((kitNumberColourShort[team][kit] ~= nil) and (kitNumberColourShort[team][kit] ~= -1)) then
return kitNumberColourShort[team][kit]
end
end

end

return item
end

function getKitNameFont(team,kit,item,tournament,teamdef)

if (kitNameFontTournament[team] ~= nil) then
if (kitNameFontTournament[team][kit] ~= nil) then
if ((kitNameFontTournament[team][kit][tournament] ~= nil) and (kitNameFontTournament[team][kit][tournament] ~= -1)) then
return kitNameFontTournament[team][kit][tournament]
end
end
end

if (tournament < 1800) then

if ((globalTournamentKitName[tournament] ~= nil) and (globalTournamentKitName[tournament] ~= -1)) then
return globalTournamentKitName[tournament]
end

if (tournamentPlayerKitsName[team] ~= nil) then
if ((tournamentPlayerKitsName[team][tournament] ~= nil) and (tournamentPlayerKitsName[team][tournament] ~= -1)) then
return tournamentPlayerKitsName[team][tournament]
end
end

if (kitNameFont[team] ~= nil) then
if ((kitNameFont[team][kit] ~= nil) and (kitNameFont[team][kit] ~= -1)) then
return kitNameFont[team][kit]
end
end

if (teamTournament[teamdef] ~= nil) then
if ((globalTournamentKitName[teamTournament[teamdef]] ~= nil) and (globalTournamentKitName[teamTournament[teamdef]] ~= -1)) then
return globalTournamentKitName[teamTournament[teamdef]]
end
-- if ((genericLeagueKitName[teamTournament[teamdef]] ~= nil) and (genericLeagueKitName[teamTournament[teamdef]] ~= -1)) then
-- return genericLeagueKitName[teamTournament[teamdef]]
-- end
end

end

return item
end

function getKitNameColour(team,kit,item,tournament)

if (kitNameColourTournament[team] ~= nil) then
if (kitNameColourTournament[team][kit] ~= nil) then
if ((kitNameColourTournament[team][kit][tournament] ~= nil) and (kitNameColourTournament[team][kit][tournament] ~= -1)) then
return kitNameColourTournament[team][kit][tournament]
end
end
end

if (tournament < 1800) then

if (kitNameColour[team] ~= nil) then
if ((kitNameColour[team][kit] ~= nil) and (kitNameColour[team][kit] ~= -1)) then
return kitNameColour[team][kit]
end
end

end

return item
end

function getKitFit(team,kit,item,tournament,player)

if (globalJerseyFit ~= nil) then
return globalJerseyFit
end

if (kitFitTournament[team] ~= nil) then
if (kitFitTournament[team][kit] ~= nil) then
if ((kitFitTournament[team][kit][tournament] ~= nil) and (kitFitTournament[team][kit][tournament] ~= -1)) then
return kitFitTournament[team][kit][tournament]
end
end
end

if (tournament < 1800) then

if (kitFit[team] ~= nil) then
if ((kitFit[team][kit] ~= nil) and (kitFit[team][kit] ~= -1)) then
return kitFit[team][kit]
end
end

end

if (kitFitPlayer[player] ~= nil) then
return kitFitPlayer[player]
end

return item
end



playerSkinTone = {}

function assignPlayerSkinTone(player,tone)
playerSkinTone[player] = tone
end

function getPlayerPlayerSkinTone(player,tone)

if (playerSkinTone[player] ~= nil) then
return playerSkinTone[player]
else
return tone
end

end


arenaModePlayerKitTeam = -1
arenaModePlayerKitType = -1

arenaModeGKKitTeam = -1
arenaModeGKKitType = -1

function setArenaModePlayerKit(team,ktype)
arenaModePlayerKitTeam = team
arenaModePlayerKitType = ktype
end

function setArenaModeGKKit(team,ktype)
arenaModeGKKitTeam = team
arenaModeGKKitType = ktype
end


specificGKKit = {}

function assignSpecificGKKit(id)
specificGKKit[id] = 1
end

function getSpecificGKKit(id,gen)

if (specificGKKit[id] ~= nil) then
return id
else
return gen
end

end


--teamRefKits = {}

teamTournament = {}

frTourn = -1
gloTourn = nil

function useTournamentGraphicsInFriendly(id)
frTourn = id
end

function useGlobalTournamentGraphics(id)
gloTourn = id
end

function getTournamentGraphics(id)

if (gloTourn ~= nil) then
return gloTourn
end

if (id == -1) then
return frTourn
end

return id
end


customGKPants = {}

function assignTeamGKPants(team,set)
customGKPants[team] = set
end

function getTeamGKPants(player,set)

if (customGKPants[player] ~= nil) then
return customGKPants[player]
else
return set
end

end

globalBoot = -1

function useGlobalBoot(boot)
globalBoot = boot
end


-- matchGK = {}

-- function assignGameGKKit(team,home,away,gk)

-- if (matchGK[team] == nil) then
-- matchGK[team] = {}
-- end

-- if (matchGK[team][home] == nil) then
-- matchGK[team][home] = {}
-- end

-- matchGK[team][home][away] = gk
-- end


function assignRandomPlayerBoot(id,boot)
local count = #boot
playerBoot[id] = boot[math.random(count)]
end




function assignKitNameLayout(team,kit,lay)

if (kitNameCurve[team] == nil) then
kitNameCurve[team] = {}
end

kitNameCurve[team][kit] = lay
end

nameLayout = {}

function assignTournamentNameLayout(team,tourn,lay)

if (nameLayout[team] == nil) then
nameLayout[team] = {}
end

nameLayout[team][tourn] = lay
end

function getKitNameCurve(team,kit,lay,tournament)

if (nameLayout[team] ~= nil) then
if ((nameLayout[team][tournament] ~= nil) and (nameLayout[team][tournament] ~= -1)) then
return nameLayout[team][tournament]
end
end

if (kitNameCurveTournament[team] ~= nil) then
if (kitNameCurveTournament[team][kit] ~= nil) then
if ((kitNameCurveTournament[team][kit][tournament] ~= nil) and (kitNameCurveTournament[team][kit][tournament] ~= -1)) then
return kitNameCurveTournament[team][kit][tournament]
end
end
end

if (tournament < 1800) then

if (kitNameCurve[team] ~= nil) then
if ((kitNameCurve[team][kit] ~= nil) and (kitNameCurve[team][kit] ~= -1)) then
return kitNameCurve[team][kit]
end
end

end

return lay

end


jerseyTuck = {}

function setJerseyTuck(player,tuck)
jerseyTuck[player] = tuck
end

function getJerseyTuck(player,tuck)

if (jerseyTuck[player] ~= nil) then
return jerseyTuck[player]
end

return tuck
end


sockHeight = {}

function setSockHeight(player,sock)
sockHeight[player] = sock
end

function getSockHeight(player,sock)

if (sockHeight[player] ~= nil) then
return sockHeight[player]
end

return sock
end


weatherAcc = {}
weatherAcc[0] = 0
weatherAcc[1] = 1
weatherAcc[2] = 1

function setWinterAccessoriesWeather(weather,option)
weatherAcc[weather] = option
end

function getWinterAccessoriesWeather(weather)

if (weatherAcc[weather] ~= nil) then
return (weatherAcc[weather] == 1)
end

return true
end


winterAccessories = {}

function assignWinterAccessories(player,option)
winterAccessories[player] = option
end

function getWinterAccessories(player,option)

if (winterAccessories[player] ~= nil) then
return winterAccessories[player]
end

return option
end


sleeveLength = {}

function setSleeveLength(player,option)
sleeveLength[player] = option
end

function getSleeveLength(player,option)

if (sleeveLength[player] ~= nil) then
return sleeveLength[player]
end

return option
end


matchKit = {}

function assignGameKit(team,home,away,type1,type2)

if (matchKit[team] == nil) then
matchKit[team] = {}
end

if (matchKit[team][home] == nil) then
matchKit[team][home] = {}
end

if (matchKit[team][home][away] == nil) then
matchKit[team][home][away] = {}
end

if (type(type2) == "number") then
matchKit[team][home][away][type1] = type2
else
--matchKit[team][home][away][type1] = type2[(gkKitSeed % #type2)+1]
matchKit[team][home][away][type1] = type2[math.random(#type2)]

end

end

function getGameKit(team,home,away,type1)

if (matchKit[team] ~= nil) then
if (matchKit[team][home] ~= nil) then
if (matchKit[team][home][away] ~= nil) then
if (matchKit[team][home][away][type1] ~= nil) then
return matchKit[team][home][away][type1]
end
end
end
end

if (swapKit[team] ~= nil) then
if (swapKit[team][type1] ~= nil) then
return swapKit[team][type1]
end
end

return type1
end


function hex(s)

return tonumber(s,16) + 4278190080

end

gkKitSeed = 0


nameWhite = "d5d9d5"
nameBlack = "0d0c0d"
nameBlue = "0046b0"
nameRed = "a00005"
nameYellow = "e8d628"
nameGreen = "007a00"
nameOrange = "f88500"
namePurple = "7a19b8"
nameBrown = "553210"
namePink = "ed80b0"
nameDarkRed = "750e05"
nameLightBlue = "7dc1f0"
nameDarkBlue = "001450"
nameGrey = "a0a2a0"
nameLightGold = "c5c965"
nameGold = "98864d"
nameDarkYellow = "f8c932"
nameLightRed = "c53232"
nameDarkGreen = "003c00"

numberWhite = 1
numberBlack = 2
numberBlue = 3
numberRed = 4
numberYellow = 5
numberGreen = 6
numberOrange = 7
numberPurple = 8
numberBrown = 9
numberPink = 10
numberDarkRed = 11
numberLightBlue = 12
numberDarkBlue = 13
numberGrey = 14
numberLightGold = 15
numberGold = 16
numberDarkYellow = 17
numberLightRed = 18
numberDarkGreen = 19


kitFitPlayer = {}

function setJerseyFit(player,fit)
kitFitPlayer[player] = fit
end


homeTraining = {}
awayTraining = {}

function assignHomeTrainingKit(team,id)
homeTraining[team] = id
end

function assignAwayTrainingKit(team,id)
awayTraining[team] = id
end

function getHomeTrainingKit(team,id)

if (homeTraining[team] ~= nil) then
return team
end

return id
end

function getAwayTrainingKit(team,id)
if (awayTraining[team] ~= nil) then
return team
end

return id
end

function getHomeTrainingKitType(team,id)

if (homeTraining[team] ~= nil) then
return homeTraining[team]
end

return id
end

function getAwayTrainingKitType(team,id)
if (awayTraining[team] ~= nil) then
return awayTraining[team]
end

return id
end


winterAccessoriesRef = nil

function useGlobalRefereeWinterAccessories(option)
winterAccessoriesRef = option
end

function getRefereeWinterAccessories(option)

if (winterAccessoriesRef ~= nil) then
return winterAccessoriesRef
end

return option
end


globalJerseyFit = nil

function useGlobalJerseyFit(option)
globalJerseyFit = option
end


trainingKitsInArena = false

function useTrainingKitsInArenaMode()
trainingKitsInArena = true
end



function getHomeArenaKit(team,id)
if (trainingKitsInArena and (homeTraining[team] ~= nil)) then
return team
end

if (arenaModePlayerKitTeam ~= -1) then
return arenaModePlayerKitTeam
end

return id
end

function getAwayArenaKit(team,id)
if (trainingKitsInArena and (awayTraining[team] ~= nil)) then
return team
end

if (arenaModeGKKitTeam ~= -1) then
return arenaModeGKKitTeam
end

return id
end

function getHomeArenaKitType(team,id)
if (trainingKitsInArena and (homeTraining[team] ~= nil)) then
return homeTraining[team]
end

if (arenaModePlayerKitTeam ~= -1) then
return arenaModePlayerKitType
end

return id
end

function getAwayArenaKitType(team,id)
if (trainingKitsInArena and (awayTraining[team] ~= nil)) then
return awayTraining[team]
end

if (arenaModeGKKitTeam ~= -1) then
return arenaModeGKKitType
end

return id
end


-- genericLeagueKitName = {}
-- genericLeagueKitNumbers = {}

globalTournamentKitName = {}
globalTournamentKitNumbers = {}

-- function setDefaultLeagueKitNameAndNumbers(tourn,name,num)
-- genericLeagueKitName[tourn] = name
-- genericLeagueKitNumbers[tourn] = num
-- end

function assignTournamentKitNameAndNumbers(tourn,name,num)
globalTournamentKitName[tourn] = name
globalTournamentKitNumbers[tourn] = num
end


classicGKKit = {}

function assignClassicGKKit(team,year)
if (classicGKKit[team] == nil) then
classicGKKit[team] = {}
end

classicGKKit[team][year] = 1
end

function getClassicGKKit(team,year,set)

if (classicGKKit[team] ~= nil) then
if (classicGKKit[team][year] ~= nil) then
return year
end
end

return set
end


genericBootReplace = nil

function replaceGenericBoots(list)

if (type(list) == "number") then
genericBootReplace = {list}
else
genericBootReplace = list
end

end


swapKit = {}

function swapTeamKit(team,type1,type2)

if (swapKit[team] == nil) then
swapKit[team] = {}
end

if (type(type2) == "number") then
swapKit[team][type1] = type2
else
swapKit[team][type1] = type2[math.random(#type2)]

end

end


oldplayeridx = 0

--Revolution Mod 13 1.3
--Edited by scouser09