Hey first time posting, bashing my brains out as its currently 3:39am for me and I just wanted to fix this before heading off for the night but I can't seem to wrap my head around it.
So I am trying to make a swep that sets your body group value.
For example if a model has a category for "hats" which is the first bodygroup (id 0), this "hats" category has 3 options.
I want this swep to rotate through them going from "hats" 0, 1, 2, 3. The number should increase each left click / primary attack.
But from what I can tell, once I set the body group then get the body group, the get body group isnt what I previously set it to.
Output from when I used it in-game:
Before Changes: (5, 0)
Set to: (5, 1)
Before Changes: (5, 1)
Set to: (5, 2)
Before Changes: (5, 1)
Set to: (5, 2)
This shows it working initially, setting the bodygroup value (of bodygroup 5) from 0 to 1,
but then when it says it sets the bodygroup value to 2, the next time I left click, it hasn't actually
changed the value to (5, 2) it is still on (5, 1).
Whereas I want it to go to (5, 2) then if 2 is the max value for the bodygroup, reset it back to 0 and rinse and repeat.
Any help is appreciated.
The code:
SWEP.SelectedBodyGroup = 0
function SWEP:PrimaryAttack()
if (CLIENT) then return end
selectedBody = self.SelectedBodyGroup
currentBodyValue = self.Owner:GetBodygroup(selectedBody)
maxBodyValue = self.Owner:GetBodygroupCount(selectedBody)
self.Owner:PrintMessage(HUD_PRINTTALK, "Before Changes: ("..selectedBody..", "..(currentBodyValue)..")")
if((currentBodyValue + 1) > maxBodyValue) then
self.Owner:SetBodygroup(selectedBody, 0)
self.Owner:PrintMessage(HUD_PRINTTALK, "Set to: ("..selectedBody..", 0)")
else
self.Owner:SetBodygroup(selectedBody, currentBodyValue + 1)
self.Owner:PrintMessage(HUD_PRINTTALK, "Set to: ("..selectedBody..", "..(currentBodyValue + 1)..")")
end
self.Owner:SetModel(self.Owner:GetModel())
self:SetNextPrimaryFire( CurTime() + 0.5)
end
function SWEP:SecondaryAttack()
max = table.Count(self.Owner:GetBodyGroups())
current = self.SelectedBodyGroup
if ((current + 1) > max) then current = 0 else current = current + 1 end
self.SelectedBodyGroup = current
self.Owner:PrintMessage(HUD_PRINTTALK, current.." / "..max)
end
Sorry, you need to Log In to post a reply to this thread.