2D Target Box ESP for SA:MP

jx455

Member
Joined
Feb 4, 2017
Messages
9
Reaction score
1
Hello, I think this will be an interesting release because most box ESPs for SA:MP are just 2D boxes. Here is a code for 2D target boxes:

Code:
void renderPlayerBoxes()
{
	traceLastFunc("renderPlayerBoxes()");

	if ( gta_menu_active() )
		return;

	if ( cheat_state->_generic.cheat_panic_enabled )
		return;

	// don't run during certain samp events
	if ( g_dwSAMP_Addr && g_SAMP )
	{
		if (
			// Scoreboard open?
			(GetAsyncKeyState(VK_TAB) < 0 && set.d3dtext_score)
			|| g_Scoreboard->iIsEnabled
			// F10 key down?
			|| GetAsyncKeyState(VK_F10) < 0
			)
			return;
	}

	// don't run if the CGameSA doesn't exist
	if ( !pGameInterface )
		return;

	// don't run if we don't exist
	if ( isBadPtr_GTA_pPed(pPedSelf) )
		return;

	for ( int i = 0; i < SAMP_MAX_PLAYERS; i++ )
	{
		if ( g_Players->iIsListed[i] != 1 )
			continue;

		if ( i == g_Players->sLocalPlayerID )
			continue;

		actor_info *info = getGTAPedFromSAMPPlayerID(i);
		if ( info == NULL )
			continue;

		CPed *pPed = pGame->GetPools()->GetPed((DWORD*)info);
		if ( pPed == nullptr )
			continue;

		// Get head and foot position
		CVector vHead, vFoot;
		pPed->GetBonePosition((eBone)BONE_HEAD, &vHead);
		pPed->GetBonePosition((eBone)BONE_LEFTFOOT, &vFoot);

		D3DXVECTOR3 headPos { vHead.fX, vHead.fY, vHead.fZ }, footPos { vFoot.fX, vFoot.fY, vFoot.fZ };
		D3DXVECTOR3 headScreenPos, footScreenPos;

		// Get head and foot position on screen
		CalcScreenCoors(&headPos, &headScreenPos);
		CalcScreenCoors(&footPos, &footScreenPos);

		// check if the iter is culled or not
		if (headScreenPos.z < 1.f || footScreenPos.z < 1.f)
			continue;

		// Calculate x, y, height, width, etc.
		float tmp = pow((headScreenPos.x - footScreenPos.x), 2);
		float tmp2 = pow((headScreenPos.y - footScreenPos.y), 2);
		
    	        float height = (sqrt(tmp + tmp2)) * 1.2f;
		float width = height / 2.0f;

		D3DCOLOR boxColor = D3DCOLOR_XRGB(255, 255, 255);
		// D3DCOLOR boxColor = samp_color_get(i, 0xDD000000);

		// Simple 2D Box
		// render->D3DBoxBorder(headScreenPos.x - (width / 2.0f), headScreenPos.y - (height / 8.0f), width, height, boxColor, 0);
		
		// Delete everything below if you just want a simple 2D box
		float x = headScreenPos.x - (width / 142.0f);
		float y = headScreenPos.y + (height / 8.0f) * 3.0f;
		float w = width;
		float h = height;

		x -= (w / 2);
		y -= (h / 2);

		int le = w / 4;
		if (le > (h / 4))
			le = (h / 4);

		render->D3DLine(x, y, x + le, y, boxColor);
		render->D3DLine(x, y, x, y + le, boxColor);
		render->D3DLine(x + w, y, x + w - le, y, boxColor);
		render->D3DLine(x + w, y, x + w, y + le, boxColor);
		render->D3DLine(x, y + h, x, y + h - le, boxColor);
		render->D3DLine(x, y + h, x + le, y + h, boxColor);
		render->D3DLine(x + w, y + h, x + w - le, y + h, boxColor);
		render->D3DLine(x + w, y + h, x + w, y + h - le, boxColor);
	}
}

I feel the math to calculate the width and height is a bit complicated and unnecessary  but w/e it works well.

MJpcJzS.jpg
 

_=Gigant=_

Well-known member
Joined
Mar 21, 2017
Messages
353
Reaction score
16
jx455 said:
Hello, I think this will be an interesting release because most box ESPs for SA:MP are just 2D boxes. Here is a code for 2D target boxes:
nice, just add 
// don't run if the CGameSA doesn't exist
if (!pGameInterface)
return;

// don't run if we don't exist
if (isBadPtr_GTA_pPed(pPedSelf))
return;
to avoid crash :3
 
Top