Bodygroups & Pointshop issue with certain model pack

Edit: Most of what I’ve written below the line is pretty much irrelevant now as I have learned a little more about the problem, however, sadly I still need help.

Basically the player models I’m trying to use in PointShop on my dedicated server have 3-4 body group submenu’s. The selections work fine in singleplayer but unfortunately don’t carry over into multiplayer. I had pretty much already accepted the fact that I wouldn’t be able to let people choose between all of the different leg/torso/hat options so decided to settle for 4 self-selected combinations. I thought I was being clever by finding the combinations by going into singleplayer, spawning a ragdoll and using command ‘ent_fire !picker setbodygroup #’ on them until I found a nice shirt/leg/hat combination to use on the server. Unfortunately that doesn’t seem to be the case at all and those numbers have nothing to do with the code I’m using (linked below in the original post).

The code I’ve been using, from what I have discovered so far, only allows me to modify one of the models sub menus. For example, I can only change a models hat, or torso, but not both, and I haven’t figured out how to actually select which one it changes. Changing the modifications.group for one model pack changes their hat, whilst doing it with another different model pack changes it’s torso even though the code is exactly the same. What I need help with is trying to figure out how to make it so that I can modify hats, torso, legs and whatever other bodygroup submenu is included with the models and then make them accessible from the PointShop interface. I really threw myself in at the deep end with this one I think. I hope I’m making sense. Does anyone know or have any ideas how I could solve this?

Hello guys,

I’ve been trying to figure this one out for a while with no luck so I’m hoping someone here would be so kind as to offer some assistance. Basically I have just started fiddling about with bodygroups in PointShop on my dedicated server thanks to another member of Facepunch who posted this really handy code: http://forum.facepunch.com/showthread.php?t=1370552&p=44207601&viewfull=1#post44207601

[del]I’ll warn you in advance that this explanation might get overly confusing. So far I’ve managed to get it working problem-free with two model packs however there’s one in particular I’d like on the server that features a ton of torso, skin, leg and even glove options via bodygroups but for some reason just refuses to work with this code. I believe I have set it up correctly but unlike the other packs it seems to completely ignore my “modifications.group” numbers and instead forces the model to constantly wear the default bodygroup clothing. The bodygroup options I select in singleplayer do not carry over to multiplayer either. One of the two working model packs is similar to the broken one and actually uses some of the same hat models.

I managed to get the broken models to change bodygroup by going through a rather arduous process as follows:

  1. Join a singleplayer sandbox game
  2. Choose a player model from the broken pack that doesn’t change bodygroup in multiplayer
  3. Join my multiplayer server
  4. Open PointShop and equip a player model that I have added to the shop from the working pack
  5. Modify the bodygroup of said player model to, for example, 1 by using Eccid’s Derma_Query box
  6. Unequip working player model.

At this point it will have put me back into my broken model but instead of being in the default clothing that I joined in it is using the same bodygroup of the previous model that I just unequipped (aka it’s changing clothing). I could use this process to get the broken model that I want by setting the working model to whatever bodygroup number it is and then going through this process every time but obviously I’d rather figure out why it’s not working.[/del] Unfortunately I’m still very new to this so it’s not that easy. Does anyone have any ideas? I can post any code necessary if it would help but for now I’ll just include lua file of the broken model that refuses to change bodygroup:


ITEM.Name = 'Metro Male 1'
ITEM.Price = 250
ITEM.Model = 'models/half-dead/metroll/a4b1.mdl', 'models/half-dead/metroll/c_arms_male1.mdl'

function ITEM:OnEquip(ply, modifications)
	if not ply._OldModel then
		ply._OldModel = ply:GetModel()
	end
	timer.Simple(1, function()
		ply:SetModel(self.Model)
		ply:SetBodygroup(47, modifications.group or 0)
	end)	                                          
end

function ITEM:OnHolster(ply)
	if ply._OldModel then
		ply:SetModel(ply._OldModel)
	end
end

function ITEM:Modify(modifications)
	Derma_Query("Choose Bodygroup", "", 
			"Outfit 1 No mask", function()
				modifications.group = 47 
				PS:SendModifications(self.ID, modifications) 
			end,
			"Outfit 1 Gasmask", function() 
				modifications.group = 119 
				PS:SendModifications(self.ID, modifications)
			end,
			"Outfit 2 No mask", function()
				modifications.group = 18 
				PS:SendModifications(self.ID, modifications) 
			end,
			"Outfit 2 Gasmask", function() 
				modifications.group = 90 
				PS:SendModifications(self.ID, modifications)
			end)
			print("modify")
	
end

function ITEM:OnModify(ply, modifications)
   self:OnHolster(ply)
   self:OnEquip(ply, modifications)
end

[del]Some notes; I use this exact same code for a model in another pack and it works fine, and in order to find the modification group numbers I went into singleplayer and spammed the console command ‘ent_fire !picker setbodygroup #’ until I found clothing combinations that I wanted to use on the server. There is a lot of combinations so it took a while.[/del] Thanks in advance, I hope this was at least somewhat understandable.

Alright so I’ve done a bit more testing and it seems that my ent_fire !picker setbodygroup # theory was wrong. Changing the modifications.group = # for the ‘working models’ only changes their hat, which is only one type of bodygroup that they have. It doesn’t affect their gloves/backpack/skin/shirt logo etc. There’s about 7 hats so setting the number to anything above 7 seemingly has no effect. Turns out this also applies to the ‘broken models’. I can change between 6 torsos with this code on the previously assumed broken ones but now I need to figure out a way to also change their legs/hat etc.

So now it seems that I need help figuring out how to change the other types of bodygroups. Does anyone know how to do this? Or if it’s even possible.

New discovery. This line chooses whether its torso/legs/hat etc:

ply:SetBodygroup(1, modifications.group or 0)

1 = Torso, 2 = Legs, 3 = Hat etc. So what I have done is changed the code to:


ITEM.Name = 'Metro Male 1'
ITEM.Price = 250
ITEM.Model = 'models/half-dead/metroll/a4b1.mdl', 'models/half-dead/metroll/c_arms_male1.mdl'

function ITEM:OnEquip(ply, modifications)
	if not ply._OldModel then
		ply._OldModel = ply:GetModel()
	end
	timer.Simple(1, function()
		ply:SetModel(self.Model)
		ply:SetBodygroup(1, modifications.group or 0)
		ply:SetBodygroup(2, modifications.group or 0)
		ply:SetBodygroup(3, modifications.group or 0)
	end)	                                          
end

function ITEM:OnHolster(ply)
	if ply._OldModel then
		ply:SetModel(ply._OldModel)
	end
end

function ITEM:Modify(modifications)
	Derma_Query("Choose Bodygroup", "", 
			"Outfit 1 No mask", function()
				modifications.group = 0 
				PS:SendModifications(self.ID, modifications) 
			end,
			"Outfit 1 Gasmask", function() 
				modifications.group = 1 
				PS:SendModifications(self.ID, modifications)
			end,
			"Outfit 2 No mask", function()
				modifications.group = 2
				PS:SendModifications(self.ID, modifications) 
			end,
			"Outfit 2 Gasmask", function() 
				modifications.group = 5
				PS:SendModifications(self.ID, modifications)
			end)
			print("modify")
	
end

function ITEM:OnModify(ply, modifications)
   self:OnHolster(ply)
   self:OnEquip(ply, modifications)
end

This allows me to use shirt 1, pants 1, hat 1 in one model, or shirt 2, pants 2 and hat 2 etc but not shirt 1, pants 2, hat 3 and so on. Anyone have any idea what I could do to make that possible?

Bodygroups are unique to each model, a hat bodygroup on one model might have ID of 1, and ID of 4 on another model, or not exist at all on third. You can preview the bodygroups and their ids with Easy Entity Inspector tool on workshop or the context menu in sandbox.

Now, as for your problem, you’ll need to use as many variables, as many bodygroup IDs you want to change. In your case 3, so you’ll need 3 variables.

You COULD do this with one variable using bitflags, in your case, but the mode bodygroups you have, the more bits you gotta use, and the amount of bits you can use is not infinite.

What bitflag essentially is, is base2 representation of a decimal integer.

dec 10 = bin 1010 ( 4 bits )

You could use 2 bits for each bodygroup ( 2 bits can hold 4 values: 0, 1, 2, 3 ) so your group variable will be in binary:
000000 for no bodygroups
010000 for first bodygroup set to 1
010100 for first and second bodygroup set to 1
100100 for first set to 2 and second to 1
etc

You’ll need to understand bitwise operations and use the bit.* library functions for this.

[editline]18th October 2014[/editline]

I know my explanation might be shit, but I gave the idea, now you need to take it and use it. You have two options, which to choose is for you to decide, if you have any further questions, ask away.