Model Switch

I have recently created a DarkRP server and I’m trying to create a class that can change it’s model to “models/Humans/NYPD/male_02_player.mdl” and I want to do this via a command “/changemodel”. However I am not a legendary lua coder like some of you are and I have no idea of how to do either of these tasks. I have read a lot of lua tutorials but none (That I have found) go into such depth and explain how to do this. So can someone please help me with this task.
Your friend,
Tristian

You don’t need to be a legendary coder to do this simple request :confused:

You need to learn lua before you go off and buy a server and expect everything to be simple.

Your best chance is either learning lua OR you hire a lua coder.

But if you insist on avoid doing the hard work, are you talking about a chat command or a console command?

A chat command

Might I suggest studying this gamemode hook.

This is for the old DarkRP version. The new one is almost completely different.

bump

I quote “I have no idea” and I wasn’t kidding. I’m not a good lua coder. All I want is to change “Police Model” to “Citizen Model” using /switch
I read Gamemode Hook But I still have no clue how to do this. So can someone just show some kind of generosity and help me out here?

This should work (you have to put the model path/name in yourself).
[lua]
function SwitchModel( pl, text, teamonly )
if(text == “/switch”)then
pl:SetModel("model/goes/here.mdl)
return false //Remove this line if you want “Playername: /switch” to show up in the chat.
end
end

hook.Add( “PlayerSay”, “SwitchModel”, SwitchModel )
[/lua]

Just saying, it’s totally worth it to actually learn Lua. I’m not a good coder either, but from time to time I’ll throw together seemingly random scripts for the server I run, and that helps me with learning the language.

I am amused by the amount of unhelpfulness of brandonj4’s activities on the forums.
Yet have to encounter something he did that isn’t a post rating.

Thankyou so much, It’s nice to see that there are helpful people who will give up some of there time to help other people, now my next question may be rated dumb (I think it is), but where would I put this? as I am new to lua code, but not to worry I pick coding up as I work with it.

Yeah I agree.

Ah, sorry, that completely slipped my mind. Save it to lua/autorun/server as modelswitch.lua

That’s quite off-topic, but regardless, just the other day he actually helped me a bit with a script I was working on.



local function Changemodel( p, c, a )
    if not ( p:Team( ) == TEAM_EXAMPLE ) then
        Notify( p, 1, 4, "You must be the job example to change your model!" )
        return ""
    end
     
    if p.IsNormal then
        GAMEMODE:PlayerSetModel( p )
        p.IsNormal = false
        p:ChatPrint( "You have returned to your original model!" )
    else
        p:SetModel( "models/Humans/NYPD/male_02_player.mdl" )
        p.IsNormal = true
        p:ChatPrint( "You have changed model!" )
    end
 
    return ""
end
AddChatCommand( "/changemodel", ChangeModel )


Someone on FP gave me this a couple months back, I edited it for you. Basicaly, you can model change by typing in /changemodel only if you are the job TEAM_EXAMPLE (change this).

Add it to the bottom of main.lua.

Yeah use nick’s instead. His is much better.

Atleast you put in Thanks :slight_smile:

This seems much simpler thanks :slight_smile:

It didn’t work :frowning:



local function Changemodel( p, c, a )
    if not ( p:Team( ) == TEAM_EXAMPLE ) then
        Notify( p, 1, 4, "You must be the job example to change your model!" )
        return ""
    end
     
    if p.IsNormal then
        GAMEMODE:PlayerSetModel( p )
        p.IsNormal = false
        p:ChatPrint( "You have returned to your original model!" )
    else
        p:SetModel( "models/Humans/NYPD/male_02_player.mdl" )
        p.IsNormal = true
        p:ChatPrint( "You have changed model!" )
    end
 
    return ""
end
AddChatCommand( "/changemodel", ChangeModel )


Just noticed a mistake. Sorry mate. Try now, should work :3

Thanks it worked <3
Also there was a small error in your code.

Notify( p, 1, 4, “You must be the job example to change your model!” )

Should’ve been

GAMEMODE:Notify( p, 1, 4, “You must be the job example to change your model!” )