Code to Change Player Model

This code doesn’t give me an error or anything it just does nothing and I’m not sure why:


if SERVER then
    AddCSLuaFile("playermodel.lua")
end

util.PrecacheModel("models/lucy.mdl")
function changeplayermodel(ply)
    ply:SetModel("models/lucy.mdl")
end
concommand.Add("changeplayermodel", changeplayermodel)

lucy.mdl is in my models folder and the script is in lua/autorun.


local function AssignProperModel( ply )
	if ply:IsAdmin() then
			ply:SetModel( "models/lucy.mdl" )
		else
			ply:SetModel( "models/lucy.mdl" )
		end

Don’t let the client execute it. It’s not sending the command to the server if you do that and it’s obviously not going to do much if you set the player’s model on someone’s client.

what

I was just pasting a snippet from my gamemode, it will work though.

okay, I won’t go in to how that snippet is retarded because I’m sure you already know and are just pretending.

Lol

[editline]6th June 2013[/editline]

So I need to make the server run this I see. I’ll mess with it a bit.

[editline]6th June 2013[/editline]

So I have this in my gamemode folder:


util.PrecacheModel( "models/lucy.mdl" )
function GM:PlayerSetModel( ply )
    ply:SetModel( "models/lucy.mdl" )
end

hook.Add("PlayerSpawn", "SetModel", function(ply)
    GAMEMODE:PlayerSetModel( ply )
end)

Getting error:


[ERROR] lua/autorun/player_spawn.lua:2: attempt to index global 'GM' (a nil value)
  1. unknown - lua/autorun/player_spawn.lua:2

?

[editline]6th June 2013[/editline]

My kingdom for working code!

[editline]6th June 2013[/editline]

Here’s the code from the pointshop I don’t understand why mine isn’t working.


function ITEM:OnEquip(ply, modifications)
	if not ply._OldModel then
		ply._OldModel = ply:GetModel()
	end
	
	timer.Simple(1, function() ply:SetModel(self.Model) end)
end

Give us all of the code we need to have a look at i don’t know how point shop works, but what you just shown doesn’t help!

If you’re just looking to make a console command by itself that changes your player model, then make a lua file in lua/autorun/server called changeplayermodel.lua or whatever, and include your code from before.



function changeplayermodel(ply)
    ply:SetModel("models/lucy.mdl")
end
concommand.Add("changeplayermodel", changeplayermodel)


It worked perfectly for me. You don’t need to include anything in the autorun folder, and putting it in the server folder will force it to run serverside.

EDIT: Care to elaborate why you rated me dumb? Based on Caratt’s main post, he wants a simple console command that changes his playermodel. That’s exactly what the example I posted does.

Ignore the dumb rating. In most cases the label befits the giver.

Thanks FrozenFire I’ll mess around with it.