Hello, guys i want to share with u my method of finding the nearest bone to the crosshair.
Code:
void bonesort(float arrayforsort[])
{
int i, j;
int buffer;
for (i = 0; i < 8; i++) {
for (j = 8 - 1; j > i; j--) {
if (arrayforsort[j - 1]>arrayforsort[j]) {
buffer = arrayforsort[j - 1];
arrayforsort[j - 1] = arrayforsort[j];
arrayforsort[j] = buffer;
}
}
}
}
Vector Best(int target)
{
Vector MyAnglePosition, HeadAngle, StomachAngle, NeckAngle, ChestAngle, LLegAngle, RLegAngle, LFAngle, RFAngle;
MyAnglePosition = Player.AnglePosition + Player.Position;
CalcAngle(MyAnglePosition, EntityList[target].HeadPosition, HeadAngle);
CalcAngle(MyAnglePosition, EntityList[target].StomachPosition, StomachAngle);
CalcAngle(MyAnglePosition, EntityList[target].NeckPosition, NeckAngle);
CalcAngle(MyAnglePosition, EntityList[target].ChestPosition, ChestAngle);
CalcAngle(MyAnglePosition, EntityList[target].LeftLegPosition, LLegAngle);
CalcAngle(MyAnglePosition, EntityList[target].RightLegPosition, RLegAngle);
CalcAngle(MyAnglePosition, EntityList[target].LeftFootPosition, LFAngle);
CalcAngle(MyAnglePosition, EntityList[target].RightFootPosition, RFAngle);
Vector HeadDelta, StomachDelta, NeckDelta, ChestDelta, LLegDelta, RLegDelta, LFDelta, RFDelta;
HeadDelta = HeadAngle - Player.CurrentViewAngles;
StomachDelta = StomachAngle - Player.CurrentViewAngles;
NeckDelta = NeckAngle - Player.CurrentViewAngles;
ChestDelta = ChestAngle - Player.CurrentViewAngles;
LLegDelta = LLegAngle - Player.CurrentViewAngles;
RLegDelta = RLegAngle - Player.CurrentViewAngles;
LFDelta = LFAngle - Player.CurrentViewAngles;
RFDelta = RFAngle - Player.CurrentViewAngles;
float Head_fov, Stomach_fov, Neck_fov, Chest_fov, LLeg_fov, RLeg_fov, LF_fov, RF_fov;
Head_fov = sqrt(powf(HeadDelta.x, 2) + powf(HeadDelta.y, 2));
Stomach_fov = sqrt(powf(StomachDelta.x, 2) + powf(StomachDelta.y, 2));
Neck_fov = sqrt(powf(NeckDelta.x, 2) + powf(NeckDelta.y, 2));
Chest_fov = sqrt(powf(ChestDelta.x, 2) + powf(ChestDelta.y, 2));
LLeg_fov = sqrt(powf(LLegDelta.x, 2) + powf(LLegDelta.y, 2));
RLeg_fov = sqrt(powf(RLegDelta.x, 2) + powf(RLegDelta.y, 2));
LF_fov = sqrt(powf(LFDelta.x, 2) + powf(LFDelta.y, 2));
RF_fov = sqrt(powf(RFDelta.x, 2) + powf(RFDelta.y, 2));
const int size = 8;
float massive[size] = { Head_fov, Stomach_fov, Neck_fov, Chest_fov, LLeg_fov, RLeg_fov, LF_fov, RF_fov };
bonesort(massive);
if (massive[0] == Head_fov)
return HeadAngle;
if (massive[0] == Stomach_fov)
return StomachAngle;
if (massive[0] == Neck_fov)
return NeckAngle;
if (massive[0] == Chest_fov)
return ChestAngle;
if (massive[0] == LLeg_fov)
return LLegAngle;
if (massive[0] == RLeg_fov)
return RLegAngle;
if (massive[0] == LF_fov)
return LFAngle;
if (massive[0] == RF_fov)
return RFAngle;
}