Playermodels for Usergroups

Hi!
I have a DarkRP Server with the default job as citizen. The theme of the server is Half-Life 2 and with that there is loyalists. What I want to do is have diffrent playermodels for the citizens if a player is a loyalist.
What decides if the player is a loyalist or not is Usergroups.

To be clear, I want a player to have default citizen models if they’re not the usergroup “Loyalist” and if they are the usergroup “Loyalist” then I want them to only have the loyalist models. Also I want the playermodel to change, but for the player to still be the same person so to speak.

Example:
Player is “Male09” and becomes a loyalist(gets the usergroup/usergroup is updated), his playermodel changes to “loyalist/male09” (If the player loses the usergroup, his playermodel would revert back to default “male09”)

Note: I want Loyalist to get the model on spawn aswell, when they join.

Mod for loyalist playermodels: Lambda Wars Citizen Loyalists ( Playermodels + NPCs )

Edit: Default playermodel for citizen (male09) = models/player/group01/male_09.mdl
Loyalist playermodel for citizen (male09) = models/player/loyalists/male_09.mdl

Basically:



local plymodel = "models/player/loyalists/male_09.mdl"

hook.Add("PlayerSpawn", "Playermodel Init", function(ply)

if ply:IsUserGroup("Loyalist") then

    ply:SetModel(plymodel)

end

end)


You can make it better by doing this:



local plymodel = "models/player/loyalists/male_09.mdl"

hook.Add("PlayerSpawn", "Playermodel Init", function(ply)

if ply:IsUserGroup("Loyalist") and ply:getDarkRPVar("job") == citizen then

    ply:SetModel(plymodel)

end

end)


This worked, quite simple but maybe not the most efficient way.


PlayerSpawn = function(ply)
           local color = Color(61,87,105) -- Set Color Here
           ply:SetPlayerColor( Vector( color.r/255, color.g/255, color.b/255 ) )
		   if ply:IsUserGroup("Loyalist") and ply:GetModel() == "models/player/group01/male_09.mdl" then
		   ply:SetModel("models/player/loyalists/male_09.mdl")
		   elseif ply:IsUserGroup("Loyalist") and ply:GetModel() == "models/player/group01/male_08.mdl" then
		   ply:SetModel("models/player/loyalists/male_08.mdl")
		   elseif ply:IsUserGroup("Loyalist") and ply:GetModel() == "models/player/group01/male_07.mdl" then
		   ply:SetModel("models/player/loyalists/male_07.mdl")
		   elseif ply:IsUserGroup("Loyalist") and ply:GetModel() == "models/player/group01/male_06.mdl" then
		   ply:SetModel("models/player/loyalists/male_06.mdl")
		   elseif ply:IsUserGroup("Loyalist") and ply:GetModel() == "models/player/group01/male_05.mdl" then
		   ply:SetModel("models/player/loyalists/male_05.mdl")
		   elseif ply:IsUserGroup("Loyalist") and ply:GetModel() == "models/player/group01/male_04.mdl" then
		   ply:SetModel("models/player/loyalists/male_04.mdl")
		   elseif ply:IsUserGroup("Loyalist") and ply:GetModel() == "models/player/group01/male_03.mdl" then
		   ply:SetModel("models/player/loyalists/male_03.mdl")
		   elseif ply:IsUserGroup("Loyalist") and ply:GetModel() == "models/player/group01/male_02.mdl" then
		   ply:SetModel("models/player/loyalists/male_02.mdl")
		   elseif ply:IsUserGroup("Loyalist") and ply:GetModel() == "models/player/group01/male_01.mdl" then
		   ply:SetModel("models/player/loyalists/male_01.mdl")
		   elseif ply:IsUserGroup("Loyalist") and ply:GetModel() == "models/player/group01/female_06.mdl" then
		   ply:SetModel("models/player/loyalists/female_06.mdl")
		   elseif ply:IsUserGroup("Loyalist") and ply:GetModel() == "models/player/group01/female_05.mdl" then
		   ply:SetModel("models/player/loyalists/female_07.mdl")
		   elseif ply:IsUserGroup("Loyalist") and ply:GetModel() == "models/player/group01/female_04.mdl" then
		   ply:SetModel("models/player/loyalists/female_04.mdl")
		   elseif ply:IsUserGroup("Loyalist") and ply:GetModel() == "models/player/group01/female_03.mdl" then
		   ply:SetModel("models/player/loyalists/female_03.mdl")
		   elseif ply:IsUserGroup("Loyalist") and ply:GetModel() == "models/player/group01/female_02.mdl" then
		   ply:SetModel("models/player/loyalists/female_02.mdl")
		   elseif ply:IsUserGroup("Loyalist") and ply:GetModel() == "models/player/group01/female_01.mdl" then
		   ply:SetModel("models/player/loyalists/female_01.mdl")
		   else
		   end
        end,

The only problem I still have is changing the playermodel upon usergroup change. Is this even possible?

Don’t use PlayerSpawn, use PlayerSetModel. If the gamemode is coded right, that’s where you want to overwrite their model.

Not sure how to use PlayerSetModel, I’ve tried this:


function GM:PlayerSetModel( ply )
if ply:IsUserGroup("Loyalist") and ply:GetModel() == "models/player/group01/male_09.mdl" then
ply:SetModel("models/player/loyalists/male_09.mdl")
elseif ply:IsUserGroup("Loyalist") and ply:GetModel() == "models/player/group01/male_08.mdl" then
ply:SetModel("models/player/loyalists/male_08.mdl")
elseif ply:IsUserGroup("Loyalist") and ply:GetModel() == "models/player/group01/male_07.mdl" then
ply:SetModel("models/player/loyalists/male_07.mdl")
elseif ply:IsUserGroup("Loyalist") and ply:GetModel() == "models/player/group01/male_06.mdl" then
ply:SetModel("models/player/loyalists/male_06.mdl")
elseif ply:IsUserGroup("Loyalist") and ply:GetModel() == "models/player/group01/male_05.mdl" then
ply:SetModel("models/player/loyalists/male_05.mdl")
elseif ply:IsUserGroup("Loyalist") and ply:GetModel() == "models/player/group01/male_04.mdl" then
ply:SetModel("models/player/loyalists/male_04.mdl")
elseif ply:IsUserGroup("Loyalist") and ply:GetModel() == "models/player/group01/male_03.mdl" then
ply:SetModel("models/player/loyalists/male_03.mdl")
elseif ply:IsUserGroup("Loyalist") and ply:GetModel() == "models/player/group01/male_02.mdl" then
ply:SetModel("models/player/loyalists/male_02.mdl")
elseif ply:IsUserGroup("Loyalist") and ply:GetModel() == "models/player/group01/male_01.mdl" then
ply:SetModel("models/player/loyalists/male_01.mdl")
elseif ply:IsUserGroup("Loyalist") and ply:GetModel() == "models/player/group01/female_06.mdl" then
ply:SetModel("models/player/loyalists/female_06.mdl")
elseif ply:IsUserGroup("Loyalist") and ply:GetModel() == "models/player/group01/female_05.mdl" then
ply:SetModel("models/player/loyalists/female_07.mdl")
elseif ply:IsUserGroup("Loyalist") and ply:GetModel() == "models/player/group01/female_04.mdl" then
ply:SetModel("models/player/loyalists/female_04.mdl")
elseif ply:IsUserGroup("Loyalist") and ply:GetModel() == "models/player/group01/female_03.mdl" then
ply:SetModel("models/player/loyalists/female_03.mdl")
elseif ply:IsUserGroup("Loyalist") and ply:GetModel() == "models/player/group01/female_02.mdl" then
ply:SetModel("models/player/loyalists/female_02.mdl")
elseif ply:IsUserGroup("Loyalist") and ply:GetModel() == "models/player/group01/female_01.mdl" then
ply:SetModel("models/player/loyalists/female_01.mdl")
else
end
end

But this just make my playermodel the ‘grey placeholder’ playermodel. Maybe I put it in the wrong place?


hook.Add("PlayerSetModel", "SetModels", function(ply)
    if(ply:GetModel():StartWith("models/player/group01/")) then
        ply:SetModel("models/player/loyalists/"..table.remove(string.Explode("/", ply:GetModel())))
    end
end)

This should work. If not, change PlayerSetModel at the top to PlayerSpawn.

Didn’t work :why:

You could either do what I replied to and changed, except you can add in a local RandNum = math.random(1, (number of player models) and say if RandNum == 1 then (set a player model) elseif RandNum == 2 then (set a different player model), etc.
Since you are using DarkRP and supposedly using jobs.lua, you can also make two citizen jobs, one which can only be seen by loyalists, and the other can be seen by everyone except loyalists. You can also set the starting job at the bottom, i.e if ply:IsUserGroup(“loyalists”) then GAMEMODE.DefaultTeam = TEAM_LOYALCITIZEN else GAMEMODE.DefaultTeam = TEAM_CITIZEN. Not sure if that would work though as I have never really tested it.

Using my solution, I only need to change the playermodel when changing the usergroup.

I don’t know how to do it, but something that say checks your usergroup upon changes and changes the playermodel once a change has been made (getting the Loyalist usergroup)

**Edit: ** Players joining gets the correct model and spawning with the ccorrect model after death, but upon change in usergroup I would like the playermodel to update.