Fixing Playermodel Names

How would I fix playermodel names that have caps. I tried using this modified bit of code from GmodLegs but it does not work. (I have already added Valkyrie to ask for permission to use this bit of code in my swep, and will not be using it till I have been given permission.)


model.FixedModelNames = {
	["models/player/group01/female_01.mdl"] = "models/player/group01/female_01.mdl",
}

function model:FixModelName( mdl )
    mdl = mdl:lower()
    return self.FixedModelNames[ mdl ] or mdl
end
-- Example code from GmodLegs by Valkyrie

Um, string.lower()?


if CLIENT then

    function GetPlayerModel( ply )
        return ply and ply != LocalPlayer() and ply or ( ply:ShouldDrawLocalPlayer() or LocalPlayer() )
    end
	
    model.FixedModelNames = {
		-- Half Life 2 Citizens
		["models/player/group01/female_01.mdl"] = "models/player/group01/female_01.mdl",
		["models/player/group01/female_02.mdl"] = "models/player/group01/female_02.mdl",
		["models/player/group01/female_03.mdl"] = "models/player/group01/female_03.mdl",
		["models/player/group01/female_04.mdl"] = "models/player/group01/female_04.mdl",
		["models/player/group01/female_05.mdl"] = "models/player/group01/female_05.mdl",
		["models/player/group01/female_06.mdl"] = "models/player/group01/female_06.mdl",
		["models/player/group01/male_01.mdl"] = "models/player/group01/male_01.mdl",
		["models/player/group01/male_02.mdl"] = "models/player/group01/male_02.mdl",
		["models/player/group01/male_03.mdl"] = "models/player/group01/male_03.mdl",
		["models/player/group01/male_04.mdl"] = "models/player/group01/male_04.mdl",
		["models/player/group01/male_05.mdl"] = "models/player/group01/male_05.mdl",
		["models/player/group01/male_06.mdl"] = "models/player/group01/male_06.mdl",
		["models/player/group01/male_07.mdl"] = "models/player/group01/male_07.mdl",
		["models/player/group01/male_08.mdl"] = "models/player/group01/male_08.mdl",
		["models/player/group01/male_09.mdl"] = "models/player/group01/male_09.mdl"
	}
	
    function model:FixModelName( mdl )
        mdl = string.lower()
        return model.FixedModelNames[ mdl ] or mdl -- Line 39
    end
end

This is what I have, and It’s still giving me the same error in console.


cl_init.lua:35: attempt to index global 'model' (a nil value)

What are you trying to do? What are you fixing? Why do you have table of model paths that have keys and values being the same?



if CLIENT then

    function GetPlayerModel( ply )
        return ply and ply != LocalPlayer() and ply or ( ply:ShouldDrawLocalPlayer() or LocalPlayer() )
    end
	
    local FixedModelNames = {
		-- Half Life 2 Citizens
		["models/player/group01/female_01.mdl"] = "models/player/group01/female_01.mdl",
		["models/player/group01/female_02.mdl"] = "models/player/group01/female_02.mdl",
		["models/player/group01/female_03.mdl"] = "models/player/group01/female_03.mdl",
		["models/player/group01/female_04.mdl"] = "models/player/group01/female_04.mdl",
		["models/player/group01/female_05.mdl"] = "models/player/group01/female_05.mdl",
		["models/player/group01/female_06.mdl"] = "models/player/group01/female_06.mdl",
		["models/player/group01/male_01.mdl"] = "models/player/group01/male_01.mdl",
		["models/player/group01/male_02.mdl"] = "models/player/group01/male_02.mdl",
		["models/player/group01/male_03.mdl"] = "models/player/group01/male_03.mdl",
		["models/player/group01/male_04.mdl"] = "models/player/group01/male_04.mdl",
		["models/player/group01/male_05.mdl"] = "models/player/group01/male_05.mdl",
		["models/player/group01/male_06.mdl"] = "models/player/group01/male_06.mdl",
		["models/player/group01/male_07.mdl"] = "models/player/group01/male_07.mdl",
		["models/player/group01/male_08.mdl"] = "models/player/group01/male_08.mdl",
		["models/player/group01/male_09.mdl"] = "models/player/group01/male_09.mdl"
	}
	
    function FixModelName( mdl )
        mdl = string.lower( mdl )
        return model.FixedModelNames[ mdl ] or mdl -- Line 39
    end
end

You get that error because “model” is not defined and you were trying to use it as a table.