Advertisement
eeli

Untitled

Sep 24th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. #include "settings.h"
  2. #include "hitmarkers.h"
  3.  
  4. bool Config::Visuals::HitMarkers::Enable = true;
  5. float Config::Visuals::HitMarkers::ExpireTime = 0.5f;
  6. float Config::Visuals::HitMarkers::MarkerSize = 12.f;
  7. float Config::Visuals::HitMarkers::TravelDistance = 24.f;
  8.  
  9. DamageListener::DamageListener()
  10. {
  11. if (!Interfaces::GameEventManager->AddListener(this, "player_hurt", false))
  12. Utilities::Error("Unable to add player_hurt listener.");
  13. else
  14. Utilities::Log("GameEvent player_hurt registered successfully.");
  15. }
  16.  
  17. DamageListener::~DamageListener()
  18. {
  19. Interfaces::GameEventManager->RemoveListener(this);
  20. }
  21.  
  22. void DamageListener::FireGameEvent(IGameEvent* event)
  23. {
  24. if (!strcmp(event->GetName(), "player_hurt"))
  25. if (Interfaces::Engine->GetPlayerForUserID(event->GetInt("attacker")) == Interfaces::Engine->GetLocalPlayer())
  26. {
  27. HitMarker_t temp = { Interfaces::globalVars->curtime + Config::Visuals::HitMarkers::ExpireTime, event->GetInt("dmg_health") };
  28.  
  29. if (temp.damage > 0 && temp.damage < 100)
  30. HitMarkers.push_back(temp);
  31. }
  32. }
  33.  
  34. int DamageListener::GetEventDebugID(void)
  35. {
  36. return EVENT_DEBUG_ID_INIT;
  37. }
  38.  
  39. void DamageListener::PaintTraverse()
  40. {
  41. static int width = 0;
  42. static int height = 0;
  43. if (height == 0 || width == 0)
  44. Interfaces::Engine->GetScreenSize(width, height);
  45.  
  46. float alpha = 0.f;
  47.  
  48. for (size_t i = 0; i < HitMarkers.size(); i++)
  49. {
  50. float timeDiff = HitMarkers[i].expireTime - Interfaces::Globals->curtime;
  51.  
  52. if (timeDiff < 0.f)
  53. {
  54. HitMarkers.erase(HitMarkers.begin() + i);
  55. continue;
  56. }
  57.  
  58. int moveDist = (int)Config::Visuals::HitMarkers::TravelDistance;
  59.  
  60. float ratio = 1.f - (timeDiff / Config::Visuals::HitMarkers::ExpireTime);
  61. alpha = (timeDiff / Config::Visuals::HitMarkers::ExpireTime) * 2.f;
  62. Render::Text(width / 2 + 6 + ratio * moveDist / 2, height / 2 + 6 + ratio * moveDist, oldColors::FOOTSTEPS_TEAM.CustomAlpha(alpha), Render::Fonts::tahoma16, std::to_string(HitMarkers[i].damage).c_str());
  63. }
  64.  
  65. if (HitMarkers.size() > 0)
  66. {
  67. int lineSize = (int)Config::Visuals::HitMarkers::MarkerSize;
  68. Render::Line(width / 2 - lineSize / 2, height / 2 - lineSize / 2, width / 2 + lineSize / 2, height / 2 + lineSize / 2, oldColors::WHITE40.CustomAlpha(alpha));
  69. Render::Line(width / 2 + lineSize / 2, height / 2 - lineSize / 2, width / 2 - lineSize / 2, height / 2 + lineSize / 2, oldColors::WHITE40.CustomAlpha(alpha));
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement