• One Player Model?!
    10 replies, posted
I need a lua addon/script so that when people join my server they all are the same model and if they try to change their model, it doesn't let them because I have a pointshop for my server and there are player models to choose from and it kinda defeats the object if they can just change the player model for free.. Thanks!
Here's something you can modify: [lua] -- server autorun DefaultModel = "modelpath" timer.Create("CheckModels",5,0,function() -- 5 seconds, infinite times for k,v in pairs(player.GetAll()) do -- change v.hascustommodel to check if the player owns custom model if v.hascustommodel == false and v:GetModel() != DefaultModel then v:SetModel(DefaultModel) end end end) [/lua]
Ok, so I've put the model path inside the quotes presuming that's what you do. models/Humans/Group01/male_07.mdl Do you save it alone in autorun? Do you need to save it into a folder or something? Sorry I'm a noob when it comes to lua.
Save it as something.lua in garrysmod/lua/autorun [b]serverside[/b]! But note that it won't work as is, you need to change v.hascustommodel bit before you can use it.
I still don't understand. Could you like give me the complete finish code? Sorry for wasting your time :/ I want the model to be models/Humans/Group01/male_07.mdl
Ugh, you will need a checking function, if a player already has custom model so it wont change his model.
[lua]function GM:PlayerSetModel(ply) ply:SetModel(Model("models/whatever")) end[/lua] Should really do this
[lua]DefaultModel = "models/Humans/Group01/male_07.mdl" function GM:PlayerSetModel(ply) ply:SetModel(DefaultModel) end function InitModel (ply) ply:SetModel(DefaultModel) end hook.Add( "PlayerInitialSpawn", "InitTehModel", InitModel ) [/lua] Create a Lua file named however you want and add the script in it with a text editor of your choice. Move the Lua file to "garrysmod/lua/autorun" on your server. Remeber: If you want your players to load the model they disconnected with, you should change the code. I hope this will help !
[QUOTE=MrManiak;38172720][lua]DefaultModel = "models/Humans/Group01/male_07.mdl" function GM:PlayerSetModel(ply) ply:SetModel(DefaultModel) end function InitModel (ply) ply:SetModel(DefaultModel) end hook.Add( "PlayerInitialSpawn", "InitTehModel", InitModel ) [/lua] Create a Lua file named however you want and add the script in it with a text editor of your choice. Move the Lua file to "garrysmod/lua/autorun" on your server. Remeber: If you want your players to load the model they disconnected with, you should change the code. I hope this will help ![/QUOTE] It says on startup on my server: [ERROR] lua/autorun/defaultmodel.lua:3: attempt to index global 'GM' (a nil value) 1. unknown - lua/autorun/defaultmodel.lua:3 in yellow. :/
You will have to put it in the gamemode files, such as init.lua.
[QUOTE=xMerkzAd;38191275]It says on startup on my server: [ERROR] lua/autorun/defaultmodel.lua:3: attempt to index global 'GM' (a nil value) 1. unknown - lua/autorun/defaultmodel.lua:3 in yellow. :/[/QUOTE] Change "GM" by "GAMEMODE", it should be working.
Sorry, you need to Log In to post a reply to this thread.