• Set Player Model Through .Lua
    7 replies, posted
I am creating a custom game mode, to increase immersion of course I require to have a a specific player model set to all the characters. Unfortunately I am still quite new to scripting with LUA and do not know how to set this. I have tried searching around on the forum but nothing that realy helps comes up. What I need to know. 1. What code should I use to set a player model. 2. In what file (init.lua/shared.lua/player.lua/whatever.lua) 3. Is using a custom player model like using a custom weapon? DO you just put the files you need into the conent foler? Thanks! EDIT: Alright I have a custom model working for it but unfortunately when I die and then shoot my dead corpse sudenly the ragdoll goes into slow motion and splits into 6 more ragdolls. So then there are 6 slowmo ragdolls lying there. Anyone know why?
[b][url=wiki.garrysmod.com/?title=Entity.SetModel]Entity.SetModel [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] Works on players as players are derived from entities.
Alright, that answers number one. And i thank you for the quick help but what .lua file should i set this in? Also, how would I find out the exact name of a model.
It's a serverside functions, so place it in the init.lua file. You can find the models with the modelviewer in source sdk, and i think you can use GCFScape too. edit: Here's the table i use for the models for my gamemode. The models are sorted into different tables. You can merge the tables together. I just have them seperated due to the way the player pick a model. [lua] Playermodels = {} Playermodels[1] = {} Playermodels[2] = {} Playermodels[3] = {} Playermodels[4] = {} Playermodels[1].Female = { //Citizen "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/Group02/Female_01.mdl", "models/humans/Group02/Female_03.mdl", "models/humans/Group02/Female_06.mdl" } Playermodels[1].Male = { //Citizen "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/Group01/male_09.mdl", "models/humans/Group01/Male_01.mdl", "models/humans/Group01/male_03.mdl", "models/humans/Group01/Male_05.mdl", "models/humans/Group01/male_09.mdl" } Playermodels[2].Female = { //Some with white shirts "models/humans/Group02/Female_02.mdl", "models/humans/Group02/Female_04.mdl", "models/humans/Group02/Female_07.mdl" } Playermodels[2].Male = { //Some with white shirts "models/humans/Group02/male_02.mdl", "models/humans/Group02/Male_04.mdl", "models/humans/Group02/male_06.mdl", "models/humans/Group02/male_08.mdl" } Playermodels[3].Female = { //Rebels with green cloth "models/humans/Group03/Female_01.mdl", "models/humans/Group03/Female_03.mdl", "models/humans/Group03/Female_06.mdl", "models/humans/Group03/Female_07.mdl" } Playermodels[3].Male = { //Rebels with green cloth "models/humans/Group03/Male_01.mdl", "models/humans/Group03/Male_04.mdl", "models/humans/Group03/male_06.mdl", "models/humans/Group03/male_08.mdl", "models/humans/Group03/male_09.mdl" } Playermodels[4].Male = { //Rebels with blue cloth "models/humans/Group03/male_02.mdl", "models/humans/Group03/male_03.mdl", "models/humans/Group03/Male_05.mdl", "models/humans/Group03/male_07.mdl" } Playermodels[4].Female = { //Rebels with blue cloth "models/humans/Group03/Female_02.mdl", "models/humans/Group03/Female_04.mdl" } [/lua]
Alright, im still a bit confused, as I said im still quite new to LUA. I probly screwed up the code a bunch but... Entity.SetModel( "models/humans/Group03/male_02.mdl" ) Thats what I had. In this whole init Entity.SetModel( "models/humans/Group03/male_02.mdl" ) function GM:PlayerSpawn( ply ) self.BaseClass:PlayerSpawn( ply ) ply:SetGravity( 1, 900 ) ply:SetMaxHealth( 75, true ) ply:SetWalkSpeed( 165 ) ply:SetRunSpeed( 355 ) end function GM:PlayerLoadout( ply ) ply:StripWeapons() ply:Give( "kermite_pist_m23" ) if ply:IsAdmin() then ply:Give() end end function GM:PlayerInitialSpawn( ply ) self.BaseClass:PlayerInitialSpawn( ply ) if ply:IsAdmin() then ply:PrintMessage( HUD_PRINTTALK, "Call of Gmod welcomes you admin!") end end
Try this: [lua]ply:SetModel( "models/humans/Group03/male_02.mdl" )[/lua]
This should work: [lua] function GM:PlayerSpawn( ply ) self.BaseClass:PlayerSpawn( ply ) ply:SetGravity( 1, 900 ) ply:SetMaxHealth( 75, true ) ply:SetWalkSpeed( 165 ) ply:SetRunSpeed( 355 ) ply:SetModel( "models/humans/Group03/male_02.mdl" ) end function GM:PlayerLoadout(ply) ply:StripWeapons() ply:Give( "kermite_pist_m23" ) end function GM:PlayerInitialSpawn(ply) self.BaseClass:PlayerInitialSpawn( ply ) if ply:IsAdmin() then ply:PrintMessage( HUD_PRINTTALK, "Call of Gmod welcomes you admin!") end end [/lua]
[QUOTE=Svendbenno;19711139]This should work: [lua] function GM:PlayerSpawn( ply ) self.BaseClass:PlayerSpawn( ply ) ply:SetGravity( 1, 900 ) ply:SetMaxHealth( 75, true ) ply:SetWalkSpeed( 165 ) ply:SetRunSpeed( 355 ) ply:SetModel( "models/humans/Group03/male_02.mdl" ) end function GM:PlayerLoadout(ply) ply:StripWeapons() ply:Give( "kermite_pist_m23" ) end function GM:PlayerInitialSpawn(ply) self.BaseClass:PlayerInitialSpawn( ply ) if ply:IsAdmin() then ply:PrintMessage( HUD_PRINTTALK, "Call of Gmod welcomes you admin!") end end [/lua][/QUOTE] Thank you so much, that worked. now to figure out how to use custom ones.... Alright I have a custom model working for it but unfortunately when I die and then shoot my dead corpse sudenly the ragdoll goes into slow motion and splits into 6 more ragdolls. So then there are 6 slowmo ragdolls lying there. Anyone know why?
Sorry, you need to Log In to post a reply to this thread.