• Problem with CLASS.PlayerModel
    13 replies, posted
Hey guys, I've been having a problem setting the model for a player class. I'm not getting any script errors in the console, but the model won't change. I've been using "thirdperson" in the console, and the player model still remains as GIGN (which I use in sandbox) instead of the specified model. It would be great if you could help. [CODE]DEFINE_BASECLASS( "player_default" ) local CLASS = {} CLASS.WalkSpeed = 200 CLASS.RunSpeed = 400 CLASS.DisplayName = "NCO" CLASS.PlayerModel = "models/player/american_assault" function CLASS:Loadout() self.Player:RemoveAllAmmo() self.Player:Give( "bb_m1carbine" ) self.Player:Give( "bb_colt" ) self.Player:Give( "bb_alliedsmoke" ) self.Player:Give( "bb_alliedfrag" ) end player_manager.RegisterClass( "allied_nco", CLASS, "player_default" )[/CODE]
That's because it is not supposed to change. You must do Player:SetModel("models/yourmodel.mdl") in one of the hooks, see base gamemode for examples.
Thanks for the reply, but I still can't get it to work. I've added this function to the same file (allied_nco.lua) [CODE]function CLASS:Spawn() self.Player:SetModel( "models/player/american_assault.mdl" ) end [/CODE]
There must be a hook, most likely it is [URL="http://wiki.garrysmod.com/page/GM/PlayerSetModel"]GM:PlayerSetModel[/URL] that is overriding the model, so your choices: 1) Override it in your gamemode and set the player model from it 2) Set the player model from it using hook.Add 3) Override it in your gamemode and leave it empty and set the model from your player class
Using the third method I got it to work... somewhat. The model changed to the proper one, but it's missing all the animations. [url]http://steamcommunity.com/sharedfiles/filedetails/?id=193947623[/url] How can I fix this?
[QUOTE=Offisir;42821937]Using the third method I got it to work... somewhat. The model changed to the proper one, but it's missing all the animations. [url]http://steamcommunity.com/sharedfiles/filedetails/?id=193947623[/url] How can I fix this?[/QUOTE] Then that's the ragdoll and not the playermodel. Click Q, go to top left search box, enter "player" and search. Then find the model there, right click > copy to clipboard, thats the playermodel.
use "models/player/dod_american.mdl" or "models/player/dod_german.mdl", They have bodygroups that reflect each class.
Thanks to all of you I finally got it working! Here's the finished snippet, in case someone else has the same problem in the future: allied_nco.lua: [CODE]function CLASS:Spawn() self.Player:SetModel( "models/player/dod_american.mdl" ) self.Player:SetBodygroup( 1, 0 ); end player_manager.RegisterClass( "allied_nco", CLASS, "player_default" )[/CODE] init.lua: [CODE]function GM:PlayerInitialSpawn( pl ) player_manager.SetPlayerClass( pl, "allied_nco" ) end function GM:PlayerSetModel( ply ) end[/CODE]
[code]function GM:PlayerSetModel( ply ) util.PrecacheModel( "models/player/american_assault.mdl" ) end[/code] That is the most useless function I have seen in quite a while.
[QUOTE=EvacX;42823284][code]function GM:PlayerSetModel( ply ) util.PrecacheModel( "models/player/american_assault.mdl" ) end[/code] That is the most useless function I have seen in quite a while.[/QUOTE] Whoops, kinda forgot to take that out...
[QUOTE=EvacX;42823284][code]function GM:PlayerSetModel( ply ) util.PrecacheModel( "models/player/american_assault.mdl" ) end[/code] That is the most useless function I have seen in quite a while.[/QUOTE] It's not useless when used properly.
[QUOTE=Robotboy655;42827237]It's not useless when used properly.[/QUOTE] Kindly elaborate?
[QUOTE=EvacX;42830328]Kindly elaborate?[/QUOTE] Precaching weapon models so it doesn't freeze the client when you load them for first time when spawning that weapon.
[QUOTE=Robotboy655;42831016]Precaching weapon models so it doesn't freeze the client when you load them for first time when spawning that weapon.[/QUOTE] But he's only precaching the same model so there's no reason to hook it into a function.
Sorry, you need to Log In to post a reply to this thread.