Best Bone

Posts 1–5 of 5 · Page 1 of 1
Best Bone
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;
}
Thanks for sharing dude
This is what I do for my legit aim bot, posting because some people might find it useful.

Code:
int CLegitAim::GetClosestBone(C_CSPlayer* Entity)
{
	int AimBone = -1;
	float BestDist = AimFOV; // your FoV setting

	matrix3x4_t matrix[MAXSTUDIOBONES];

	if (!Entity->SetupBones(matrix, MAXSTUDIOBONES, BONE_USED_BY_HITBOX, Interfaces::Engine()->GetLastTimeStamp()))
		return -1;

	const model_t* pModel = Entity->GetModel();

	if (!pModel)
		return -1;

	studiohdr_t* pStudioModel = Interfaces::ModelInfo()->GetStudioModel(pModel);

	if (!pStudioModel)
		return -1;

	mstudiohitboxset_t* set = pStudioModel->pHitboxSet(Entity->GetHitboxSet());

	if (!set)
		return -1;

	std::vector<int> Hitboxes;

	if (AimHead) // Aim at head? If yes, we add head hitbox to our hitboxes list.
		Hitboxes.emplace_back(HITBOX_HEAD);

	if (AimNeck)
	{
		Hitboxes.emplace_back(HITBOX_NECK);
		Hitboxes.emplace_back(HITBOX_LOWER_NECK);
	}

	if (AimChest)
	{
		Hitboxes.emplace_back(HITBOX_CHEST);
		Hitboxes.emplace_back(HITBOX_UPPER_CHEST);
	}

	if (AimBody)
	{
		Hitboxes.emplace_back(HITBOX_PELVIS);
		Hitboxes.emplace_back(HITBOX_BODY);
		Hitboxes.emplace_back(HITBOX_THORAX);
	}

	for (auto Hitbox : Hitboxes)
	{
		mstudiobbox_t* box = set->pHitbox(Hitbox);

		if (!box)
			continue;

		Vector EyePos = G::pLocal->GetEyePos();
		Vector BonePos = Vector(matrix[box->bone][0][3], matrix[box->bone][1][3], matrix[box->bone][2][3]);

		if (!Utils::IsEntityVisible(Entity, EyePos, BonePos)) // simple ray trace check to the middle of the bone, you can do your own as well.
			continue;

                // you can find the function LineGoesThroughSmoke if you search.
		if (!G::O.Aim.Legit.TargetPlayersInSmoke && Utils::LineGoesThroughSmoke(EyePos, BonePos))
			continue;

		float FOV = GetFOVDist(ViewAngles, EyePos, BonePos); // your FOV check function

		if (FOV <= BestDist)
		{
			BestDist = FOV;
			AimBone = box->bone;
		}
	}

	return AimBone;
}
You can make the whole function as bool if you like, but I prefer it to return an integer.

Credits:
supercraft360 - original code.
everyone else who showed me examples of better sorting methods.
Quote Originally Posted by 4773n0x View Post
This is what I do for my legit aim bot, posting because some people might find it useful.

Code:
int CLegitAim::GetClosestBone(C_CSPlayer* Entity)
{
	int AimBone = -1;
	float BestDist = AimFOV; // your FoV setting

	matrix3x4_t matrix[MAXSTUDIOBONES];

	if (!Entity->SetupBones(matrix, MAXSTUDIOBONES, BONE_USED_BY_HITBOX, Interfaces::Engine()->GetLastTimeStamp()))
		return -1;

	const model_t* pModel = Entity->GetModel();

	if (!pModel)
		return -1;

	studiohdr_t* pStudioModel = Interfaces::ModelInfo()->GetStudioModel(pModel);

	if (!pStudioModel)
		return -1;

	mstudiohitboxset_t* set = pStudioModel->pHitboxSet(Entity->GetHitboxSet());

	if (!set)
		return -1;

	std::vector<int> Hitboxes;

	if (AimHead) // Aim at head? If yes, we add head hitbox to our hitboxes list.
		Hitboxes.emplace_back(HITBOX_HEAD);

	if (AimNeck)
	{
		Hitboxes.emplace_back(HITBOX_NECK);
		Hitboxes.emplace_back(HITBOX_LOWER_NECK);
	}

	if (AimChest)
	{
		Hitboxes.emplace_back(HITBOX_CHEST);
		Hitboxes.emplace_back(HITBOX_UPPER_CHEST);
	}

	if (AimBody)
	{
		Hitboxes.emplace_back(HITBOX_PELVIS);
		Hitboxes.emplace_back(HITBOX_BODY);
		Hitboxes.emplace_back(HITBOX_THORAX);
	}

	for (auto Hitbox : Hitboxes)
	{
		mstudiobbox_t* box = set->pHitbox(Hitbox);

		if (!box)
			continue;

		Vector EyePos = G::pLocal->GetEyePos();
		Vector BonePos = Vector(matrix[box->bone][0][3], matrix[box->bone][1][3], matrix[box->bone][2][3]);

		if (!Utils::IsEntityVisible(Entity, EyePos, BonePos)) // simple ray trace check to the middle of the bone, you can do your own as well.
			continue;

                // you can find the function LineGoesThroughSmoke if you search.
		if (!G::O.Aim.Legit.TargetPlayersInSmoke && Utils::LineGoesThroughSmoke(EyePos, BonePos))
			continue;

		float FOV = GetFOVDist(ViewAngles, EyePos, BonePos); // your FOV check function

		if (FOV <= BestDist)
		{
			BestDist = FOV;
			AimBone = box->bone;
		}
	}

	return AimBone;
}
You can make the whole function as bool if you like, but I prefer it to return an integer.

Credits:
supercraft360 - original code.
everyone else who showed me examples of better sorting methods.
ur welcome
Posts 1–5 of 5 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us