Changing player models for other players.

Hey, thanks again to “Jamie932” for helping me when I was last stuck.

The problem now is, I want to make it so I can change player models for other people (to props), what I have so far is:

[lua]function PlayerModel(ply, cmd, args)

 if ply:IsAdmin() then  
    if args[1] then  
       ply:SetModel(args[1])  
       ply:ChatPrint("Player model changed!")  
    else  
       ply:ChatPrint("Error!")  
    end  
 else  
      ply:ChatPrint("You are not an admin on this server!")  
 end  

end
concommand.Add(“playermodel”, PlayerModel)[/lua]

If you could also explain what you added/modified does, I would appreciate it, as I’m learning Lua. - I wanted to be able to change it through their name (in-game)
I did try adding some stuff to it, but none of it worked, and since I got such a nice response last time I was stuck, I thought I ask again.
Thanks.

This is how I would do it. I commented it so you can understand better.

[lua]
– This function finds people by their names. Usage: FindByName(“NameHere”)
function FindByName(str)
for _,v in ipairs(player.GetAll()) do
if string.find(string.lower(v:Name()), string.lower(str)) ~= nil then
return v
end
end
return nil
end

function PlayerModel(ply, cmd, args)

 if not ply:IsAdmin() then ply:ChatPrint("You are not an admin on this server!") return end -- If the player is not an admin, they cannot use this.
 
 local Player = FindByName(args[1]) -- Finding the player by their name.
 local Model = args[2] -- The model.
 
    if Player and Model then -- If both the Player and the Model exist, then...
        Player:SetModel(Model)  -- Set the model to the model.
        ply:ChatPrint("You have changed "..Player:Nick().."'s model!") -- Write something in their chat.
    elseif Model and not Player then -- If the model exists, but not the player then...
       ply:SetModel(Model)  -- Set the person who is running the console command's model to the model.
       ply:ChatPrint("Your model was changed!") -- Write something in their chat.
    elseif not Model and not Player then -- If both the model and the player do not exist then...
        ply:ChatPrint("Your arguments are invalid!") -- Write something in their chat.
 end  

end
concommand.Add(“playermodel”, PlayerModel)

– Usage: playermodel “playername” “modelhere”[/lua]

[lua]
function PlayerModel(ply, cmd, args)

 if ply:IsAdmin() then ply:ChatPrint("You are not an admin on this server!") return end -- If the player is not an admin, they cannot use this.  

[/lua]

You’re basically saying that if the player is an admin then something in the chat will say “You’re not an admin” even when you are. :stuck_out_tongue:

My mistake, I missed an exclamation mark.

What do you mean? I’m confused…

I think he meant to put !isadmin.

I put

[lua]if ply:IsAdmin() then blah return end[/lua]

but I missed out the word not (or exclamation mark).

[lua] if not ply:IsAdmin() then blah return end[/lua]
[lua] if !ply:IsAdmin() then blah return end[/lua]

Thanks, you’re too helpful ^^

Your welcome.

Hmm, when I try to change player’s models, on my screen, it works, but one everyone else’s it doesn’t… Also, non admins can change models, and it fully registers then :confused:

If it means anything; the admin mod we are running is “Evolve”.

EDIT: Removing the script from my “autorun” folder is allowing me to make myself a prop.

Have you tried putting it in lua/autorun/server/somename.lua?

Sadly I’m not the owner, so I don’t have access to the files, I’ll ask an owner soon :slight_smile:
However, the script itself is awesome :smiley:

You’re running it clientside, has to be serverside.

^^
I’ll tell the owner to put it in the right place. :slight_smile: