SetModel()

Hello later today i tried to make a small script to make all players that are administrators have the Grigori model and the others have the Mossman, does not work no matter what don’t know why:



function model()
	for _, v in pairs(player.GetAll()) do	
if v:IsAdmin()
then
v:SetModel("models/monk.mdl")
else
v:SetModel("models/mossman.mdl")
end
end
end
model()


As far as i know this should work. Any help?

may you need to hook it with this : **[Gamemode.PlayerSetModel

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Gamemode.PlayerSetModel)**

Ah i need to do this in the gamemode itself?

no, i think you can use it like [lua] util.PrecacheModel( “models/player/odessa.mdl” )

hook.Add(“PlayerSetModel”, “myhook”, function(ply) ply:SetModel( “models/player/odessa.mdl” )
end)[/lua]

Did not work, hmm could the sandbox Player model system be overriding the script?

… You’re not editing this in the sandbox files, are you?

'Cause you cant do that; the sandbox files are in GCFScape, meaning they get initialized/loaded, whenever Garrys Mod is ran.

Also, may I ask you


function model()
	for _, v in pairs(player.GetAll()) do	
if v:IsAdmin()
then
v:SetModel("models/monk.mdl")
else
v:SetModel("models/mossman.mdl")
end
end
end
model() -- What the heck is that doing?

If you havent removed “model()” yet, do it. Most likely the problem.

I think he is calling the function as soon as it is initialized… Which might be his problem…

Try

GM:PlayerInitialSpawn( ply )
model()
end

instead. This way it will run when the player is ready to have the model set, and not before.

Note this is untested theory, you may have to do it on the playerloadout.

Hm, I didnt know you could do it like that.

I may be mistaken but it should work, on the initial spawn the player object is created. And as such should be ready to have the model changed. He is calling it when the script is initialized, at which point the player is most likely not spawned yet and therefore he is setting the model of nil.

Most likely right about that.


hook.Add("PlayerInitialSpawn", "MahModels", model)

the fuck

that is too messy for me to read. :I

[lua]
hook.Add(“PlayerSpawn”, “setAdminModel”, function§
if( p:IsAdmin() ) then
p:SetModel(“models/monk.mdl”);
else
p:SetModel(“models/mossman.mdl”);
end
end)
[/lua]

Calling his already made “model()” function is just an unnecessary for loop.

Use the PlayerSetModel hook, and if that doesn’t work, use PlayerSpawn.

PlayerSpawn is what calls PlayerSetModel so I don’t really think there is a difference apart from neatness.

But yea either of the two would probably be better than InitialSpawn… Otherwise they can change it.

PlayerSpawn, PlayerSetModel, InitialSpawn none of these hooks worked



function model()
	for _, v in pairs(player.GetAll()) do	
if v:IsAdmin()
then
v:SetModel("models/monk.mdl")
else
v:SetModel("models/mossman.mdl")
end
 end
  end
hook.Add("InitialSpawn", "Model", model)


Why is SetModel() so tricky?

Because PlayerInitialSpawn != InitialSpawn


hook.Add("**

Player


**InitialSpawn", "Model", model)