HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /*
  2. Damage displayer by Lulu the hero(M_Lajos@hotmail.com)
  3.  
  4. A more detailed damage displayer then advanced bullet damage(abd)
  5.  
  6. Colors are being displayed around the cursor accordingly:
  7.   yellow - friendly fire
  8.   red - damage taken
  9.   blue - inflicted harm
  10.   green - self harm
  11.   white - objects( eg. bomb explosion or fire )
  12.  
  13. Version history:
  14.   1.4 - fixed team indication in cstrike
  15.   1.3 - removed team coloring to make plugin applyable to mods other then cs
  16.   turned back to switches to increase sourcecode's readability
  17.   1.22 - removed some variables to reduce resource usage
  18.   1.21 - added team specific colors( T = red, CT = blue, OTHER = magenta ) in both harm and damage
  19.   1.2 - turned switches into ?: statements and clearing out a few variables this way
  20.   1.11 - more optimalization and extracting datas, restructuring if cases, turning them to switches
  21.   1.1 - optimazed code, added friendly fire coloring in damage, plus damage HARM non players
  22.   1.0 - started project: indicating friendly fire(yellow), normal fire(blue) and damage(red)
  23.  
  24. Future developements:
  25.   - Indicating damage done on/recieve from objects, such as breakable things or monstermod monsters.
  26.  
  27. Topic link:
  28.   http://forums.alliedmods.net/showthread.php?t=134181
  29. */
  30.  
  31. //comment this line out if you aren't using this plugin in cstrike or czero
  32. #define FOR_CSTRIKE
  33.  
  34. #include <amxmodx>
  35.  
  36. #if defined FOR_CSTRIKE
  37. #include <cstrike>
  38. #define get_team(%1) cs_get_user_team(%1)
  39. #else
  40. #define get_team(%1) get_user_team(%1)
  41. #endif
  42.  
  43. #define NOT_PLAYER_TEAM_ID -1
  44.  
  45. // r , g , b
  46. #define COLOR_ATTACK_TEAMMATE { 127,127, 0 }
  47. #define COLOR_ATTACK_ENEMY { 0, 0,127 }
  48.  
  49. #define COLOR_DAMAGE_TEAMMATE { 127,127, 0 }
  50. #define COLOR_DAMAGE_ENEMY { 127, 0, 0 }
  51. #define COLOR_DAMAGE_OBJECT { 127,127,127 }
  52. #define COLOR_DAMAGE_SELF { 0,127, 0 }
  53.  
  54. #define DAMAGE_ENEMY 0
  55. #define DAMAGE_TEAMMATE 1
  56. #define DAMAGE_OBJECT 2
  57. #define DAMAGE_SELF 3
  58.  
  59. new attack_hud, damage_hud;
  60.  
  61. public plugin_init(){
  62. register_plugin( "Damage displayer", "1.4", "Lulu the hero" );
  63.  
  64. //hook a damage event
  65. register_event( "Damage", "damage_event", "b", "2!0" );
  66.  
  67. attack_hud = CreateHudSyncObj();
  68. damage_hud = CreateHudSyncObj();
  69. }
  70.  
  71. public damage_event(victim){
  72. static damage, attacker, attacker_team, victim_team, is_attacker_player, color[3], damage_type;
  73.  
  74. //if victim is not a player then return
  75. if(!is_user_connected(victim)) return PLUGIN_CONTINUE;
  76.  
  77. //if no damage then return
  78. damage = read_data(2);
  79. if(!damage) return PLUGIN_CONTINUE;
  80.  
  81. //get the attacker
  82. attacker = get_user_attacker(victim);
  83. is_attacker_player = is_user_connected(attacker);
  84.  
  85. //if attacker is not a player, then mark that
  86. //this way, if an entity hurts the player, then we can still indicate that
  87. attacker_team = is_attacker_player ? (_:get_team(attacker)) : NOT_PLAYER_TEAM_ID;
  88.  
  89. //precache the victim's team
  90. victim_team = _:get_team(victim);
  91.  
  92. //displaying inflicted damage to attacker
  93. if(!is_user_bot(attacker) && is_attacker_player && attacker != victim){
  94. //get the nature of the damage
  95. damage_type = victim_team == attacker_team ? DAMAGE_TEAMMATE : DAMAGE_ENEMY;
  96. //set the color according to damage type
  97. switch(damage_type){
  98. case DAMAGE_TEAMMATE : color = COLOR_ATTACK_TEAMMATE;
  99. case DAMAGE_ENEMY : color = COLOR_ATTACK_ENEMY;
  100. }
  101. set_hudmessage( color[0], color[1], color[2], -1.0, 0.55, 0, 2.0, 2.0, 0.1, 1.0, -1 );
  102. ShowSyncHudMsg( attacker, attack_hud, "%d", damage);
  103. }
  104.  
  105. //displaying damage to victim
  106. if(!is_user_bot(victim)){
  107. //get the nature of the damage
  108. damage_type = attacker == victim ? DAMAGE_SELF : victim_team == attacker_team ? DAMAGE_TEAMMATE : attacker_team == NOT_PLAYER_TEAM_ID ? DAMAGE_OBJECT : DAMAGE_ENEMY;
  109. //set the color according to damage type
  110. switch(damage_type){
  111. case DAMAGE_TEAMMATE : color = COLOR_DAMAGE_TEAMMATE;
  112. case DAMAGE_ENEMY : color = COLOR_DAMAGE_ENEMY;
  113. case DAMAGE_OBJECT : color = COLOR_DAMAGE_OBJECT;
  114. case DAMAGE_SELF : color = COLOR_DAMAGE_SELF;
  115. }
  116. set_hudmessage( color[0], color[1], color[2], 0.45, -1.0, 0, 2.0, 2.0, 0.1, 1.0, -1 );
  117. ShowSyncHudMsg( victim, damage_hud, "%d", damage );
  118. }
  119.  
  120. return PLUGIN_HANDLED;
  121. }
  122.