Junior Member
|
05-18-2023
, 01:48
Re: Some pev_body information
|
#38
|
Quote:
Originally Posted by okbede_123
Hello. I have a question. If i have more if groupbody like hat_id, example backpack_id. So if i want a model player have hat id and backpack id so what is recipe it is?
|
Each bodygroup have a base param that tell the engine from where it starts (to use for the " pev->body" var).
So, let's say you have a model with 3 bodygroups, like:
Spoiler
PHP Code:
bodygroup 1 { bodypart 1 bodypart 2 bodypart 3 bodypart 4 bodypart 5 }
bodygroup 2 { bodypart 1 bodypart 2 bodypart 3 }
bodygroup 3 { bodypart 1 bodypart 2 bodypart 3 bodypart 4 bodypart 5 bodypart 6 bodypart 7 }
They will be ' stacked' (game-engine will interpreter they) something like this:
• "bodygroup 1" base is always '1' (formally, first bodygroup-base is always '1' *)
• all others bodygroups will calculate they base from where the former bodygroup-ends.
*:I DONT KNOW IF when $body directive is parsed, if they is declared before any bodygroup, the will have this base-param to '1' and later, bodygroups are calculated......I would have to check, anyway.
So, let's do it we manually to see:
Spoiler
PHP Code:
bodygroup 1 { base: 1 bodyparts: 5 each bodypart-index is = index - 1
bodypart 1 = 0 bodypart 2 = 1 bodypart 3 = 2 bodypart 4 = 3 bodypart 5 = 4 }
bodygroup 2 { base: later bodygroup-base * later bodygroup-models base: 5 (later bodygroup have 5 bodyparts and base was 1 = 5*1) bodyparts: 3 each bodypart-index is = index * (this bodypart-base) bodypart 1 = 0 * 5 = 0 bodypart 2 = 1 * 5 = 5 bodypart 3 = 2 * 5 = 10 }
bodygroup 2 { base: 15 (later bodygroup have 3 bodyparts and base was 5 = 3*5) bodyparts: 7 each bodypart-index is = index * (this bodypart-base) bodypart 1 = 0 * 15 = 0 bodypart 2 = 1 * 15 = 15 bodypart 3 = 2 * 15 = 30 }
Now, imagine you want set the current bodygroups (with they bodyparts):
- bodygroup-1 + bodypart-5
- bodygroup-2 + bodypart-2
- bodygroup-3 + bodypart-5
The, value for pev-body will be = 4 + 5 + 60 = 69.
Obviously you need to see the model's bodygroups with a model-editor (like HLMV) to know the base for each group and then you can calculate this value.
On the other hand, I've make this stock to do the job more easily (port of SetBodyGroup from HLSDK):
Spoiler
PHP Code:
stock bool:SetBodyGroup(const iEntity, const iGroup, const iPart) { new bool:bResult; static szModel[64]; pev(iEntity, pev_model, szModel, charsmax(szModel)); new iModelPtr = fopen(szModel, "rb"); if (!iModelPtr) goto Result; new iBodyPartsCount = iGroup; new iBodyPartNumModels; new iBodyPartBase; Model_GetBodyPartInfo(iModelPtr, iBodyPartsCount, iBodyPartNumModels, iBodyPartBase); if (iGroup > iBodyPartsCount) goto Result; if (iPart >= iBodyPartNumModels) goto Result; new iBody; new iCurrent; iBody = pev(iEntity, pev_body); iCurrent = (iBody / iBodyPartBase) % iBodyPartNumModels; iBody = iBody - (iCurrent * iBodyPartBase) + (iPart * iBodyPartBase); set_pev(iEntity, pev_body, iBody); bResult = true Result: { fclose(iModelPtr); return bResult; } }
Model_GetBodyPartInfo(const pmodel, &numbodyparts, &nummodels, &base) { if (!pmodel) return; new group = numbodyparts; new bodypartindex; const studiohdr_s_numbodyparts = 204 // studiohdr_t->numbodyparts offset (from start); const mstudiobodyparts_s_nummodels = 64; // mstudiobodyparts_t->nummodels offset (from start) const mstudiobodyparts_s_size = 76; // mstudiobodyparts_t size (64char x 1byte + 3int * 4byte) fseek(pmodel, studiohdr_s_numbodyparts, SEEK_SET); fread(pmodel, numbodyparts, BLOCK_INT); fread(pmodel, bodypartindex, BLOCK_INT); bodypartindex += (group * mstudiobodyparts_s_size) + mstudiobodyparts_s_nummodels; fseek(pmodel, bodypartindex, SEEK_SET); fread(pmodel, nummodels, BLOCK_INT); fread(pmodel, base, BLOCK_INT); }
SetBodygroup ( HLSDK)
Code:
void SetBodygroup( void *pmodel, entvars_t *pev, int iGroup, int iValue )
{
studiohdr_t *pstudiohdr;
pstudiohdr = (studiohdr_t *)pmodel;
if (! pstudiohdr)
return;
if (iGroup > pstudiohdr->numbodyparts)
return;
mstudiobodyparts_t *pbodypart = (mstudiobodyparts_t *)((byte *)pstudiohdr + pstudiohdr->bodypartindex) + iGroup;
if (iValue >= pbodypart->nummodels)
return;
int iCurrent = (pev->body / pbodypart->base) % pbodypart->nummodels;
pev->body = (pev->body - (iCurrent * pbodypart->base) + (iValue * pbodypart->base));
}
You can use it like this:
PHP Code:
new entity // suppose entity is a 'hat' entity and his model has 3 bodygroups SetBodyGroup(entity, 2, 5) // sets bodygroups 3 (from 0 to 2) and bodypart 6 (from 0 to 5)
Finally, i've upload a modified version of the model used on this thread, so you can check for yourself
Last edited by SVC; 05-18-2023 at 11:40.
|
|