c_arms for playermodel with 2 outfits

Hello,

first, sorry for my english :).
I made a playermodel with 2 Outfits (via Bodygroups) and I made 2 c_arms for each outfit.
But how can I add both c_arms in lua (player_manager.AddValidHands), that gmod switch automatically to the right c_arm?
Is that possible?

I hope you understand what I mean :slight_smile:

https://wiki.garrysmod.com/page/Using_Viewmodel_Hands

Thank you :o)
I’m not sure how it works… I tried it with 01000000 but gmod changed not the c_arm model.

I have 1 playermodel, but with 2 Bodygrupos/Outfits. One with a short shirt and one with a long shirt. You can choose it via Bodygroup.
For each shirt I made a own c_arm.
But I can only add 1 c_arm to my Playermodel…

I’m afraid that you can’t change the c_model bodygroup of a playermodel when it’s changing thought the default player model changer (sandbox).
This can only be done by a hacky workaround in lua.

Like, putting under the “player_manager.AddValidHands”, a hook to change when it happens.



-- somes player_manager.AddValidHands()
hook.Add("PreDrawViewModel","SwitchHandsBodygroup",function(vm,ply)
-- If the current c_model used is not matching the model that should draw when the player's bodygroup is 0, then change it.
if ply:GetBodygroup(your_bodygroup_id) == 0 && vm:GetModel() != "c_model_that_should_draw.mdl" then
vm:SetModel("c_model_that_should_draw.mdl")
-- Ditto. Except this times. It's for Bodygroup "1/Or whatever you set".
elseif ply:GetBodygroup(your_bodygroup_id) == 1 && vm:GetModel() != "c_model_that_should_draw.mdl" then -- Might not be 1 on your side!
vm:SetModel("c_model_that_should_draw.mdl")
end
end)



You can know which bodygroup you need to use by using:

Entity:GetBodyGroups

Gedo, isn’t that running on the viewmodel, not the hands? Additionally, you’re looking at more performance overhead than necessary by performing the operation each frame. Consider: in most instances, playermodel is only changed on respawn. Thus, one might modify ply:GetHands on PlayerSpawn. There’s also the option of changing the hand model on PlayerSetModel, which might work in additional cases for Sandbox, but not necessarily other gamemodes.

Assuming your hands are compiled into two separate models, you could do this:



local targetmodel = "models/player.mdl"
local handtable = {
	[0] = "models/weapons/c_player_hands_0.mdl",
	[1] = "models/weapons/c_player_hands_1.mdl"
}
hook.Add("PlayerSpawn","PlayerUpdateHands",function(ply)
	if !IsValid(ply) then return end
	if ply:GetModel() != targetmodel then return end
	local hnd = ply:GetHands()
	if !IsValid(hnd) then return end
	local hmdl = handtable[ ply:GetBodygroup( id ) ] or hnd:GetModel()
	hnd:SetModel(hmdl)
end)


If you made your arm variant a bodygroup, you could do this:



local targetmodel = "models/player.mdl"
local handtable = {
	[0] = {
		[0] = 0
	},
	[1] = {
		[0] = 1
	}
}
hook.Add("PlayerSpawn","PlayerUpdateHands",function(ply)
	if !IsValid(ply) then return end
	if ply:GetModel() != targetmodel then return end
	local hnd = ply:GetHands()
	if !IsValid(hnd) then return end
	local bgtbl = handtable[ ply:GetBodygroup( bodygroup_id ) ] or {}
	for k,v in ipairs(bgtbl) do
		hnd:SetBodygroup(k,v)
	end
end)


  1. Hands = Viewmodel
    If you didn’t know, the c_model is a model with 2 arms with hands for animating stuffs to hands/arms.
    The c_model include too all the standard bones (and so, is ValveBiped) required for making player model.

2. I’m aware of performing this each frame. But I didn’t found anythings satisfying for that.
I could like you said, use a hook for PlayerSetModel, as this woulds of course, works in Sandbox gamemode.
But I was thinking of a case, where a player, could set the bodygroup directly without going into the sandbox player model changer.
And this is where the problem lie. How I can know if a player changed his bodygroup? For that. There is no way by hooking.

In any ways for 2., you’re right. Realtime change for viewmodel shoulds be the job of others addons. And not a player model addons itself likes I’m trying to do.

Yes, I should know considering I make them frequently. Hands are not equal to the viewmodel. They are in fact a separate entity, gmod_hands, and require a different function, ply:GetHands().

With regards to your second point, there’s still a better solution. The same check as within PlayerSpawn could be performed on the tick hook, or even in a shared timer ( at the cost of a minute and unnoticable delay. )

@Gedo789, TFA
Thank you very much for the help :slight_smile:

I see, it’s not easy :).
I tried it, but I got an error: attempt to index local ‘ply’ (a nil value)

and with the code from TFA nothing happens…

I’ll look at them later, after finish the model textures etc…

(Edit: how can I give a “thanks” to a posting in this forum?)

Pay attention. If you’re using my code, then, this must be run on the clientside only. (Because the file made for adding player model run both sides)
If it’s the TFA’s code one, then, it’s another problem.
Before judging TFA’s code, you need to make sure that:
1.You replaced the value of targetmodel to your player model’s mdl.
2.You replaced the values of handtable correctly with yours.
3.For checking if it works, you have to change the bodygroup in sandbox using LUA/dedicated addons and then, kill yourself (in-game of course).
4.If after respawn, it works, then it’s working. Else, there is a problem lying around.

If instead, it was my code, then, you need to put this before adding my code after player_manager.AddValidHands():


if SERVER then return end -- After this, any codes that will be written after this line, won't be run on the serverside. But only on clientside.

Except that steps 3. and 4. don’t apply to my code. You only need to change your bodygroup and nothings else.

[sp]Hover your mouse at the bottom right of a post[/sp]
[sp]But IIRC, you can’t, because you need to post at least 50 on the forum (You have posted 25)[/sp]