Getting hit bone on player_hurt
hi!
first of all sorry the title is a bit confusing just read the post and u will understand my problem thank u … i love u all
i’m attempting to do “world-hitmarkers”, where hitmarkers draw where you hit the player. A summary of how I’ve tried doing it is getting the hitgroup, grabbing a bone according to the hitgroup and setting the hitmarkers position, and then drawing it with w2s. and i mean, it works, but it looks like absolute ass.
hitgroups/bones are wrong, hitmarkers fall down with the model, etc. no es bueno
any possible solutions? this is pretty poopy in its current state tbh
struct hitmarker_t
{
bool initialized;
IClientEntity* player;
Vector position;
int hitgroup;
int bonetoset;
};
std::vector g_hitmarkers;
//in player_hurt listener
hitmarker_t p_hitmerks;
hitmerks.initialized = false;
hitmerks.player = event->GetInt("userid");
hitmerks.hitgroup = event->GetInt("hitgroup");
g_hitmarkers.push_back(hitmerks);
//in painttraverse
for (int i = 0; i < hitmarkers.size(); i++) {
//i set up bones w/ hitgroups in here its just 2 much code so i cba to put it in
//i also got a timer n shit but i cba to put it in here its unimportant
if (!g_hitmarkers[i].initialized) {
g_hitmarkers[i].position = g_hitmarkers[i].player->getbonepos(g_hitmarkers[i].bonetoset);
g_hitmarkers[i].initialized= true;
}
Vector screenpos;
if (r::w2s(g_hitmarkers[i].position, screenpos)) {
//draw hitmarker here
}
}
You can normally get the position of a hitgroup..
bool C_BasePlayer::GetHitgroupPos(int hitgroup, Vector &output)
{
const model_t *model = this->GetModel();
if(!model)
return false;
studiohdr_t *studioHdr = g_MdlInfo->GetStudiomodel(model);
if(!studioHdr)
return false;
matrix3x4_t matrix[MAXSTUDIOBONES];
if(!this->SetupBones(matrix, MAXSTUDIOBONES, BONE_USED_BY_HITBOX, 0))
return false;
mstudiohitboxset_t* set = studioHdr->pHitboxSet(this->GetHitboxSet());
mstudiobbox_t* box;
for (int i = 0; i < set->numhitboxes; i++)
{
box = set->pHitbox(i);
if (box->group == hitgroup)
break;
}
Vector min, max;
Math::VectorTransform(box->bbmin, matrix[box->bone], min);
Math::VectorTransform(box->bbmax, matrix[box->bone], max);
output = (min + max) * 0.5f;
return true;
}
|