• Help with randomising playermodel of job
    22 replies, posted
I'm trying to randomise the playermodel of the Citizen job, I looked online for a while and found some posts relating to this but I was unable to implement them into my code successfully. TEAM_CITIZEN = DarkRP.createJob("Citizen", {     color = Color(20, 150, 20, 255),     function( ply )         ply:SetModel( table.Random(models) )         models = {           "models/player/Group01/Female_01.mdl",           "models/player/Group01/Female_02.mdl",           "models/player/Group01/Female_03.mdl",           "models/player/Group01/Female_04.mdl",           "models/player/Group01/Female_06.mdl",           "models/player/group01/male_01.mdl",           "models/player/Group01/Male_02.mdl",           "models/player/Group01/male_03.mdl",           "models/player/Group01/Male_04.mdl",           "models/player/Group01/Male_05.mdl",           "models/player/Group01/Male_06.mdl",           "models/player/Group01/Male_07.mdl",           "models/player/Group01/Male_08.mdl",           "models/player/Group01/Male_09.mdl"         }         description = [[The Citizen is the most basic level of society you can hold besides being a hobo. You have no specific role in city life.]]         weapons = {}         command = "citizen"         max = 0         salary = GAMEMODE.Config.normalsalary         admin = 0         vote = false         HasLicense = false         candemote = false         category = "Citizens"     end })
I'm not Lua expert but shouldn't you put the models array before setting them?
Does this look right? TEAM_CITIZEN = DarkRP.createJob("Citizen", {     color = Color(20, 150, 20, 255),     function( ply )       models = {           "models/player/Group01/Female_01.mdl",           "models/player/Group01/Female_02.mdl",           "models/player/Group01/Female_03.mdl",           "models/player/Group01/Female_04.mdl",           "models/player/Group01/Female_06.mdl",           "models/player/group01/male_01.mdl",           "models/player/Group01/Male_02.mdl",           "models/player/Group01/male_03.mdl",           "models/player/Group01/Male_04.mdl",           "models/player/Group01/Male_05.mdl",           "models/player/Group01/Male_06.mdl",           "models/player/Group01/Male_07.mdl",           "models/player/Group01/Male_08.mdl",           "models/player/Group01/Male_09.mdl"         }       ply:SetModel( table.Random(models) )         description = [[The Citizen is the most basic level of society you can hold besides being a hobo. You have no specific role in city life.]]         weapons = {}         command = "citizen"max = 0         salary = GAMEMODE.Config.normalsalary         admin = 0         vote = false         HasLicense = false         candemote = false         category = "Citizens"end })
am i missing something? doesnt darkrp automatically select a random model in the models list of the job? no need to wrap everything in a function to set a random model
If that's the case, might the F4 menu be causing it to be the first playermodel on the model list?
You're overthinking it: TEAM_CITIZEN = DarkRP.createJob("Citizen", {     color = Color(20, 150, 20, 255),          model = {           "models/player/Group01/Female_01.mdl",           "models/player/Group01/Female_02.mdl",           "models/player/Group01/Female_03.mdl",           "models/player/Group01/Female_04.mdl",           "models/player/Group01/Female_06.mdl",           "models/player/group01/male_01.mdl",           "models/player/Group01/Male_02.mdl",           "models/player/Group01/male_03.mdl",           "models/player/Group01/Male_04.mdl",           "models/player/Group01/Male_05.mdl",           "models/player/Group01/Male_06.mdl",           "models/player/Group01/Male_07.mdl",           "models/player/Group01/Male_08.mdl",           "models/player/Group01/Male_09.mdl",         },         description = [[The Citizen is the most basic level of society you can hold besides being a hobo. You have no specific role in city life.]],         weapons = {},         command = "citizen",           max = 0,         salary = GAMEMODE.Config.normalsalary,         admin = 0,         vote = false,         HasLicense = false,         candemote = false,         category = "Citizens",     end }) No function ( ply ) is needed, it's model not "models", and there must be a comma after every designation - e.g: weapons = {}, command = "citizen", max = 0, etc. Try that first, if it doesn't work then, yes, chances are it's your F4 menu.
I tried that and unfortunately no luck. So would there be any way to override the F4 menu and have the playermodels be random without having to change F4 menu files?
More than likely not, we would have to see the code unless it's from the gmodstore. I've used amenu in the past - and it works just fine with the sortOrder (it is from the gmodstore though): Steam Community otherwise I would contact whoever made the addon or just use the default menu
TEAM_CITIZEN = DarkRP.createJob("Citizen", {     color = Color(20, 150, 20, 255),          model = {           "models/player/Group01/Female_01.mdl",           "models/player/Group01/Female_02.mdl",           "models/player/Group01/Female_03.mdl",           "models/player/Group01/Female_04.mdl",           "models/player/Group01/Female_06.mdl",           "models/player/group01/male_01.mdl",           "models/player/Group01/Male_02.mdl",           "models/player/Group01/male_03.mdl",           "models/player/Group01/Male_04.mdl",           "models/player/Group01/Male_05.mdl",           "models/player/Group01/Male_06.mdl",           "models/player/Group01/Male_07.mdl",           "models/player/Group01/Male_08.mdl",           "models/player/Group01/Male_09.mdl",         },         description = [[The Citizen is the most basic level of society you can hold besides being a hobo. You have no specific role in city life.]],         weapons = {},         command = "citizen",         max = 0,         salary = 45,         admin = 0,         vote = false,         HasLicense = false,         candemote = false,         category = "Citizens", })
Is it still creating the same error?
Yeah it still sets the citizen playermodel automatically to "models/player/Group01/Female_01.mdl".
So I just tried this out for myself because I was pretty confident that DarkRP automatically randomizes the player model, however that's not the case. Instead you have to create a global table (probably would want to do it at the top of your jobs.lua file) and then reference it later in the PlayerSpawn function like so: //top of the file randCitizen = { "models/player/Group01/Female_01.mdl", "models/player/Group01/Female_02.mdl", "models/player/Group01/Female_03.mdl", "models/player/Group01/Female_04.mdl", "models/player/Group01/Female_06.mdl", "models/player/group01/male_01.mdl", "models/player/Group01/Male_02.mdl", "models/player/Group01/male_03.mdl", "models/player/Group01/Male_04.mdl", "models/player/Group01/Male_05.mdl", "models/player/Group01/Male_06.mdl", "models/player/Group01/Male_07.mdl", "models/player/Group01/Male_08.mdl", "models/player/Group01/Male_09.mdl", } //at the job you want randomized TEAM_CITIZEN = DarkRP.createJob("Citizen", { color = Color(20, 150, 20, 255), model = { "models/player/Group01/Female_01.mdl", }, description = [[The Citizen is the most basic level of society you can hold besides being a hobo. You have no specific role in city life.]], weapons = {}, command = "citizen", max = 0, salary = 45, admin = 0, vote = false, HasLicense = false, candemote = false, category = "Citizens", PlayerSpawn = function(ply) ply:SetModel(table.Random(randCitizen)) //reference our table from outside of the job, here. end, })
"So I just tried this out for myself because I was pretty confident that DarkRP automatically randomizes the player model, however that's not the case." Incorrect. DarkRP Source: function GM:PlayerSetModel(ply)     local jobTable = ply:getJobTable()     -- Invalid job, return to Sandbox behaviour     if not jobTable then return self.Sandbox.PlayerSetModel(ply) end     if jobTable.PlayerSetModel then         local model = jobTable.PlayerSetModel(ply)         if model then ply:SetModel(model) return end     end     local EndModel = ""     if GAMEMODE.Config.enforceplayermodel then         if istable(jobTable.model) then             local ChosenModel = string.lower(ply:getPreferredModel(ply:Team()) or "")             local found             for _, Models in pairs(jobTable.model) do                 if ChosenModel == string.lower(Models) then                     EndModel = Models                     found = true                     break                 end             end             if not found then                 EndModel = jobTable.model[math.random(#jobTable.model)]             end         else             EndModel = jobTable.model         end         ply:SetModel(EndModel)     else         local cl_playermodel = ply:GetInfo("cl_playermodel")         local modelname = player_manager.TranslatePlayerModel(cl_playermodel)         ply:SetModel(ply:getPreferredModel(ply:Team()) or modelname)     end     self.Sandbox.PlayerSetModel(self, ply)     ply:SetupHands() end If you have a preferred model then you get to be that model, else it's random. Don't do what he is doing above, its stupid.
it's* Ah I thought so but I forgot I'm using an F4 menu that decides what model to use based on the one you select in the F4 menu itself. Which sounds like OP's issue - that they're using a custom F4 menu that does the same thing. Obviously the default model selection for the DarkRP menu isn't working in this case. Unless you can explain any other reason the job's model wouldn't be randomized then no, it's not stupid.
Doesn't matter what you say, your method is stupid. He has no idea what he's doing and you have absolutely no idea what you're doing. Just c+p some jobs or use an online tool like everyone else.
The only other option would be to go digging through someone else's code that created the addon and change it or add the random table function from DarkRP. I know I don't want to go digging through someone else's code but 👌 If you have nothing to contribute... we're trying to solve an issue.
Would I have to add a random table function into the f4 menu i'm using?
Well that's the thing... in order for it to work as intended you would need to go rooting around inside the darkrp essential f4 menu first, find whatever function it is that sets the mode, then go into darkrp and do the same thing, then figure out how to write darkrp's function into the f4 menu... OR you can just do this: //top of the file randCitizen = { "models/player/Group01/Female_01.mdl", "models/player/Group01/Female_02.mdl", "models/player/Group01/Female_03.mdl", "models/player/Group01/Female_04.mdl", "models/player/Group01/Female_06.mdl", "models/player/group01/male_01.mdl", "models/player/Group01/Male_02.mdl", "models/player/Group01/male_03.mdl", "models/player/Group01/Male_04.mdl", "models/player/Group01/Male_05.mdl", "models/player/Group01/Male_06.mdl", "models/player/Group01/Male_07.mdl", "models/player/Group01/Male_08.mdl", "models/player/Group01/Male_09.mdl", } //at the job you want randomized TEAM_CITIZEN = DarkRP.createJob("Citizen", { color = Color(20, 150, 20, 255), model = { "models/player/Group01/Female_01.mdl"}, //you HAVE to have a model here - DarkRP will not accept the job otherwise description = [[The Citizen is the most basic level of society you can hold besides being a hobo. You have no specific role in city life.]], weapons = {}, command = "citizen", max = 0, salary = 45, admin = 0, vote = false, hasLicense = false, candemote = false, category = "Citizens", PlayerSpawn = function(ply) ply:SetModel(table.Random(randCitizen)) //reference our table from outside of the job, here. end, }) Which is a million times easier, it's not your responsibility to fix someone else's addon - so just try this. Let me know if you're still having issues and you can add me on Discord.
I found these sections of the f4 menu addon in a file called cl_jobs.lua and they look to be related to what we're trying to do. local function addJobModel() if istable(essentialDarkRPF4Menu.selectedJob.model) and util.IsValidModel(essentialDarkRPF4Menu.selectedJob.model[1]) then modelPanel:SetModel(essentialDarkRPF4Menu.selectedJob.model[1]) elseif (not istable(essentialDarkRPF4Menu.selectedJob.model)) and util.IsValidModel(essentialDarkRPF4Menu.selectedJob.model) then modelPanel:SetModel(essentialDarkRPF4Menu.selectedJob.model) else modelPanel:SetModel('models/error.mdl') end end -- Check if model is valid before we become a job if util.IsValidModel(modelPanel:GetModel()) then DarkRP.setPreferredJobModel(essentialDarkRPF4Menu.selectedJob.team, modelPanel:GetModel()) end if essentialDarkRPF4Menu.selectedJob.vote then RunConsoleCommand('darkrp', 'vote' .. essentialDarkRPF4Menu.selectedJob.command) else RunConsoleCommand('darkrp', essentialDarkRPF4Menu.selectedJob.command) end end
Right, that's what I was talking about - but if you replace those with the DarkRP function for randomizing player models then you're going to have to remake the entire addon because you'll have to do the same line of code for every "essentialDarkRPF4Menu" instance.
I just found out while I was testing, that when a player dies, their playermodel will be random.
That's what happens when you use PlayerSpawn. Try use something like OnPlayerChangedTeam if you only want it to alter upon changing team.
Thank you all for the help, but unfortunately I was unable to get a successful outcome. I've edited and tested multiple variations of the code numerous times and so I've resorted to adding the bodyGroupr addon which allows players to change their playermodel and so that every player isn't female01 when they spawn.
Sorry, you need to Log In to post a reply to this thread.