Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2012
646
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1.  
  2.  
  3. void DrawESP( CEntity *player, CEntity *localPlayer )
  4. {
  5. static Vector duckOffset = Vector( 0.f, 0.f, 53.5f ); // VEC_DUCK_HULL_MAX
  6. static Vector standOffset = Vector( 0.f, 0.f, 72.f ); // VEC_HULL_MAX
  7.  
  8. Vector origin;
  9. if ( !g_Drawing.WorldToScreen( player->GetAbsOrigin(), origin ) )
  10. {
  11. return;
  12. }
  13.  
  14.  
  15. Vector offset = ( player->GetFlags() & FL_DUCKING ) ? duckOffset : standOffset;
  16. Vector max = ( player->GetAbsOrigin() + offset );
  17.  
  18.  
  19. Vector top;
  20. if ( !g_Drawing.WorldToScreen( max, top ) )
  21. {
  22. return;
  23. }
  24.  
  25.  
  26. float len = 0.f;
  27. int fontIndex = 0;
  28.  
  29. if ( localPlayer )
  30. {
  31. len = ( max - localPlayer->GetEyePosition() ).Length();
  32. fontIndex = GetFontIndexByDistance( len );
  33. }
  34.  
  35.  
  36. Color colour = GameResources()->GetTeamColor( player->GetTeamNum() );
  37.  
  38. // box esp
  39. // inversed delta calc because it's screen coords, and they start from top left corner
  40. float boxHeight = ( origin.y - top.y );
  41. float boxHalfWidth = ( boxHeight * .25f );
  42.  
  43. // ghett0 fix so box has same width when crouching and when standing
  44. // 72 / 53.5 = 1.345794392523364
  45. if ( player->GetFlags() & FL_DUCKING )
  46. {
  47. boxHalfWidth *= 1.345794392523364f;
  48. }
  49.  
  50. Vector box( ( top.x - boxHalfWidth ), top.y, 0.f );
  51.  
  52.  
  53. static int layers = 3;
  54. // outline
  55. g_Drawing.DrawOutlinedRect( ( box.x - 1 ), ( box.y - 1 ), ( ( boxHalfWidth * 2 ) + 2 ), ( boxHeight + 2 ), Color( 0, 0, 0, 255 ) );
  56. g_Drawing.DrawOutlinedRect( ( box.x + 1 ), ( box.y + 1 ), ( ( boxHalfWidth * 2 ) - 2 ), ( boxHeight - 2 ), Color( 0, 0, 0, 255 ) );
  57.  
  58. // actual coloured box
  59. g_Drawing.DrawOutlinedRect( box.x, box.y, ( boxHalfWidth * 2 ), boxHeight, colour );
  60.  
  61.  
  62. {
  63. // health
  64. float health = player->GetHealth();
  65.  
  66. if ( health > 0 )
  67. {
  68. int scale = ( health * 2.55f );
  69.  
  70. Color patch( 0, 0, 0, 255 );
  71.  
  72. if ( health > 100 )
  73. {
  74. patch.SetColor( 255, 255, 255, 255 );
  75. }
  76.  
  77.  
  78. // outline
  79. g_Drawing.DrawOutlinedRect( ( ( top.x - boxHalfWidth ) - 6 ), ( top.y - 1 ), 4, ( boxHeight + 2 ), Color( 0, 0, 0, 255 ) );
  80.  
  81. // green bar
  82. g_Drawing.DrawFilledRect( ( ( top.x - boxHalfWidth ) - 5 ), top.y, 2, boxHeight, Color( ( 255 - scale ), scale, 0, 255 ) );
  83.  
  84. // black patch to make the bar appear to grow upwards, couldn't draw an inversed bar cause of unkwn reasons
  85. g_Drawing.DrawFilledRect( ( ( top.x - boxHalfWidth ) - 5 ), top.y, 2, ( ( 100 - health ) * ( boxHeight / 100 ) ), Color( 0, 0, 0, 255 ) );
  86. }
  87. }
  88.  
  89. {
  90. // armor
  91. float armor = min( player->GetArmorValue(), 100 );
  92.  
  93. if ( armor > 0 )
  94. {
  95. int scale = ( armor * 2.55f );
  96.  
  97. Color patch( 85, 85, 85, 255 );
  98.  
  99. if ( player->HasHelmet() )
  100. {
  101. patch.SetColor( 0, 0, 0, 255 );
  102. }
  103.  
  104.  
  105. // outline
  106. g_Drawing.DrawOutlinedRect( ( ( top.x - boxHalfWidth ) - ( 6 + 6 ) ), ( top.y - 1 ), 4, ( boxHeight + 2 ), patch );
  107.  
  108. // green bar
  109. g_Drawing.DrawFilledRect( ( ( top.x - boxHalfWidth ) - ( 5 + 6 ) ), top.y, 2, boxHeight, Color( scale, scale, scale, 255 ) );
  110.  
  111. // black patch to make the bar appear to grow upwards, couldn't draw an inversed bar cause of unkwn reasons
  112. g_Drawing.DrawFilledRect( ( ( top.x - boxHalfWidth ) - ( 5 + 6 ) ), top.y, 2, ( ( 100 - armor ) * ( boxHeight / 100 ) ), patch );
  113. }
  114. }
  115.  
  116.  
  117. // go to right side of box
  118. top.x += ( boxHalfWidth + 5 );
  119. top.y -= 4;
  120.  
  121.  
  122. // name
  123. g_Drawing.DrawString( false, fontIndex, top.x, top.y, colour, "%s", GameResources()->GetPlayerName( player->GetIndex() ) );
  124.  
  125. top.y += ( ( 16 - GetFontIndexByDistance( len ) ) + 1 ); // newline: 16 - font index = height, +1 is for a space in between
  126.  
  127.  
  128. // weapon
  129. CWeapon *weapon = player->GetWeapon();
  130.  
  131. if ( weapon )
  132. {
  133. int id = weapon->GetID();
  134. const char *tmp = CWeaponInfo::GetWeaponAlias( id );
  135.  
  136. // convert to uppercase
  137. char weaponName[0xFF];
  138. strcpy( weaponName, tmp );
  139.  
  140. char *c = weaponName;
  141.  
  142. while ( *c )
  143. {
  144. *c = toupper( *c );
  145. ++c;
  146. }
  147.  
  148.  
  149. g_Drawing.DrawString( false, fontIndex, top.x, top.y, colour, "%s", weaponName );
  150.  
  151. top.y += ( ( 16 - GetFontIndexByDistance( len ) ) + 1 ); // newline: 16 - font index = height, +1 is for a space in between
  152. }
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement