Advertisement
eeli

Untitled

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