Setting playermodel in lua

[lua]PlayerModelTable = {
“models/Humans/Group01/Female_01.mdl”,
“models/Humans/Group01/Female_02.mdl”,
“models/Humans/Group01/Female_03.mdl”,
“models/Humans/Group01/Female_04.mdl”,
“models/Humans/Group01/Female_06.mdl”,
“models/Humans/Group01/Female_07.mdl”,
“models/Humans/Group01/Male_01.mdl”,
“models/Humans/Group01/male_02.mdl”,
“models/Humans/Group01/male_03.mdl”,
“models/Humans/Group01/Male_04.mdl”,
“models/Humans/Group01/Male_05.mdl”,
“models/Humans/Group01/male_06.mdl”,
“models/Humans/Group01/male_07.mdl”,
“models/Humans/Group01/male_08.mdl”,
“models/Humans/Group01/male_09.mdl”,
“models/Humans/Group03/Female_01.mdl”,
“models/Humans/Group03/Female_02.mdl”,
“models/Humans/Group03/Female_03.mdl”,
“models/Humans/Group03/Female_04.mdl”,
“models/Humans/Group03/Female_06.mdl”,
“models/Humans/Group03/Female_07.mdl”,
“models/Humans/Group03/Male_01.mdl”,
“models/Humans/Group03/male_02.mdl”,
“models/Humans/Group03/male_03.mdl”,
“models/Humans/Group03/Male_04.mdl”,
“models/Humans/Group03/Male_05.mdl”,
“models/Humans/Group03/male_06.mdl”,
“models/Humans/Group03/male_07.mdl”,
“models/Humans/Group03/male_08.mdl”,
“models/Humans/Group03/male_09.mdl”,
“models/Humans/Group03m/male_07.mdl”,
“models/Humans/Group03m/Female_07.mdl”
}

function RoundRestart()
local UsedMod = {}
for k, v in pairs(AllPlayers) do
local NumRand = math.random(1, MaxPlayers)
while UsedMod[NumRand]==true do
NumRand = math.random(1, MaxPlayers)
end
UsedMod[NumRand] = true
v.Model = PlayerModelTable[NumRand]
v:SetModel(v.Model)
end
RoundStart()
end

function RoundStart()
for num, pl in pairs(AllPlayers) do
pl:UnSpectate()
pl:Spawn()
DataToClient(pl)
end
Timer(RoundTime, RoundEndCD)
end
[/lua]

DataToClient, Timer, and AllPlayers are all legit.

Now, this doesnt give me any errors, yet it royally screws over my gamemode with strange stuff, and it doesnt change the players model.

Please tell me why this won’t work?

you should work with “print()”.
As Example at the PlayerModelTable(Numrand) part
To see what is now right or wrong

Its fine, It turns out a model.
Ive also tried just pl:SetModel(“models/wwhatever/legitmodel.mdl”) and it STILL wont set it.

And I’ve tried making a small function that sets in on the server side

I dunt understand

[lua]
ply:SetModel( “path/to/model.mdl” )
[/lua]

Put in GM:PlayerSpawn or wherever

ooh
k

Tested and it works now, thank you!

You mean, PlayerSetModel. :3


PlayerModelTable = {
"models/Humans/Group01/Female_0*1*7*.mdl",
"models/Humans/Group01/Male_0*1*9*.mdl",
"models/Humans/Group03/Female_0*1*7*.mdl",
"models/Humans/Group03/Male_0*1*9*.mdl",
"models/Humans/Group03m/male_07.mdl",
"models/Humans/Group03m/Female_07.mdl"
 }

function randomizeModel(model) --Checks to see if a model wants to be randomized, then randomizes.
	if string.find(model, "*") then --Allows for a randomized model.
		local sep = string.Explode("*", model)
		return sep[1] .. math.random(tonumber(sep[2]), tonumber(sep[3])) .. sep[4]
	end
	return model
end
 
function GM:PlayerSetModel(ply)
	local model = randomizeModel(PlayerModelTable[math.random(#PlayerModelTable)])
	util.PrecacheModel(model)
	ply:SetModel(model)
end

Just a quick clean up. :stuck_out_tongue:

I figured that out, but now I cant get them to look right, they look like the “noob” kleiners, and dont have the correct player animations.
I even did:
[lua]local AnimTranslateTable = {}
AnimTranslateTable[ PLAYER_RELOAD ] = ACT_HL2MP_GESTURE_RELOAD
AnimTranslateTable[ PLAYER_JUMP ] = ACT_HL2MP_JUMP
AnimTranslateTable[ PLAYER_ATTACK1 ] = ACT_HL2MP_GESTURE_RANGE_ATTACK

function GM:SetPlayerAnimation( pl, anim )

local act = ACT_HL2MP_IDLE
local Speed = pl:GetVelocity():Length()
local OnGround = pl:OnGround()

// If it's in the translate table then just straight translate it
if ( AnimTranslateTable[ anim ] != nil ) then

	act = AnimTranslateTable[ anim ]

else

	// Crawling on the ground
	if ( OnGround && pl:Crouching() ) then

		act = ACT_HL2MP_IDLE_CROUCH

		if ( Speed > 0 ) then
			act = ACT_HL2MP_WALK_CROUCH
		end

	// Player is running on ground
	elseif (Speed > 0) then

		act = ACT_HL2MP_RUN

	end

end

// Attacking/Reloading is handled by the RestartGesture function
if ( act == ACT_HL2MP_GESTURE_RANGE_ATTACK ||
	 act == ACT_HL2MP_GESTURE_RELOAD ) then

	pl:RestartGesture( pl:Weapon_TranslateActivity( act ) )

	// If this was an attack send the anim to the weapon model
	if (act == ACT_HL2MP_GESTURE_RANGE_ATTACK) then

		pl:Weapon_SetActivity( pl:Weapon_TranslateActivity( ACT_RANGE_ATTACK1 ), 0 );

	end

return end

// Always play the jump anim if we're in the air
if ( !OnGround ) then

	act = ACT_HL2MP_JUMP

end

// Ask the weapon to translate the animation and get the sequence
// ( ACT_HL2MP_JUMP becomes ACT_HL2MP_JUMP_AR2 for example)
local seq = pl:SelectWeightedSequence( pl:Weapon_TranslateActivity( act ) )

// If we're in a vehicle just sit down
// We should let the vehicle decide this when we have scripted vehicles
if (pl:InVehicle()) then

	// TODO! Different ACTS for different vehicles!

	if ( pl:GetVehicle():GetTable().HandleAnimation ) then

		seq = pl:GetVehicle():GetTable().HandleAnimation( pl )

	else

		local class = pl:GetVehicle():GetClass()

		if ( class == "prop_vehicle_jeep" ) then
			seq = pl:LookupSequence( "drive_jeep" )
		elseif ( class == "prop_vehicle_airboat" ) then
			seq = pl:LookupSequence( "drive_airboat" )
		else
			seq = pl:LookupSequence( "drive_pd" )
		end

	end

end

// If the weapon didn't return a translated sequence just set
//	the activity directly.
if (seq == -1) then

	// Hack.. If we don't have a weapon and we're jumping we
	// use the SLAM animation (prevents the reference anim from showing)
	if (act == ACT_HL2MP_JUMP) then

		act = ACT_HL2MP_JUMP_SLAM

	end

	seq = pl:SelectWeightedSequence( act )

end

// Don't keep switching sequences if we're already playing the one we want.
if (pl:GetSequence() == seq) then return end

// Set and reset the sequence
pl:SetPlaybackRate( 1.0 )
pl:ResetSequence( seq )
pl:SetCycle( 0 )

end[/lua]