Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Release Show K/D Ratio
#1
This plugin shows a player's K/D under the minimap. It also provides an example on how to use HudElementTypes.Value and how to show a HudElement to a single entity.

Example how it will look like:
[Image: A2A302E3CF2ABC3E08C48074B7DF738BDA8DB4D0]

If the K/D is < 1 the text will be red, else it's green (as in the screenshot).

Thanks to @"jaydi", @Cyanide and GT.Under for testing.

Source code:
CSHARP Code
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Addon;
  5.  
  6. namespace KDRatio
  7. {
  8. public class Class1 : CPlugin
  9. {
  10. //Store ClientNum and HudElementNum in dictionary
  11. Dictionary<int, int> Client_HudElem = new Dictionary<int, int>();
  12.  
  13. public override void OnServerLoad()
  14. {
  15. ServerPrint("\n K/D Ratio Plugin loaded \n Author: zxz0O0 \n Thanks to Nukem, Jariz and Pozzuh\n");
  16. ServerPrint(" youtube.com/zxz0O0 \n itsmods.com\n");
  17. }
  18.  
  19. public override void OnPlayerConnect(ServerClient Client)
  20. {
  21. int HudElemNum = CreateKDHud(Client.ClientNum);
  22. //Add client and it's kd hudelement to the list
  23. if (Client_HudElem.ContainsKey(Client.ClientNum))
  24. Client_HudElem[Client.ClientNum] = HudElemNum;
  25. else
  26. Client_HudElem.Add(Client.ClientNum, HudElemNum);
  27. }
  28.  
  29. public override void OnPlayerDisconnect(ServerClient Client)
  30. {
  31. if(Client_HudElem.ContainsKey(Client.ClientNum))
  32. {
  33. //Get client's k/d hudelement
  34. HudElem kd = GetHudElement(Client_HudElem[Client.ClientNum]);
  35. //Setting hudelement's type to None 'deletes' it AFAIK
  36. kd.Type = HudElementTypes.None;
  37. //Remove entry from Dictionary
  38. Client_HudElem.Remove(Client.ClientNum);
  39. }
  40. }
  41.  
  42. public override int OnPlayerDamaged(ServerClient Attacker, ServerClient Victim, string Weapon, int Damage)
  43. {
  44. //If kill
  45. if (Damage >= Victim.Other.Health)
  46. {
  47. //Update victim's value
  48. if (Client_HudElem.ContainsKey(Victim.ClientNum))
  49. {
  50. HudElem victim = GetHudElement(Client_HudElem[Victim.ClientNum]);
  51. //victim.Value = (float)Victim.Stats.Kills / (Victim.Stats.Deaths + 1);
  52. victim.Value = (float)Math.Round((double)Victim.Stats.Kills / (Victim.Stats.Deaths + 1), 2);
  53. if (victim.Value < 1)
  54. {
  55. //Make it red
  56. victim.Color.R = 255;
  57. victim.Color.G = 0;
  58. victim.Color.B = 0;
  59. }
  60. else
  61. {
  62. //Make green
  63. victim.Color.R = 0;
  64. victim.Color.G = 255;
  65. victim.Color.B = 0;
  66. }
  67. }
  68.  
  69. //Don't do it when victim is attacker
  70. if (Victim.ClientNum != Attacker.ClientNum)
  71. {
  72. //Update attacker's value
  73. if (Client_HudElem.ContainsKey(Attacker.ClientNum))
  74. {
  75. HudElem attacker = GetHudElement(Client_HudElem[Attacker.ClientNum]);
  76. //Don't divide by zero :O
  77. if (Attacker.Stats.Deaths == 0)
  78. attacker.Value = Attacker.Stats.Kills + 1;
  79. else
  80. attacker.Value = (float)(Math.Round((double)(Attacker.Stats.Kills + 1) / Attacker.Stats.Deaths, 2));
  81.  
  82. if (attacker.Value < 1)
  83. {
  84. //Make it red
  85. attacker.Color.R = 255;
  86. attacker.Color.G = 0;
  87. attacker.Color.B = 0;
  88. }
  89. else
  90. {
  91. //Make green
  92. attacker.Color.R = 0;
  93. attacker.Color.G = 255;
  94. attacker.Color.B = 0;
  95. }
  96. }
  97. }
  98. }
  99. return Damage;
  100. }
  101.  
  102. private int CreateKDHud(int ClientNum)
  103. {
  104. //Create a simply 'empty' HudElement
  105. HudElem hud = CreateNewHudElem();
  106. //Make the HudElement Value
  107. hud.Type = HudElementTypes.Value;
  108. //Show the HudElement only to the Client
  109. hud.ShowToEnt = ClientNum;
  110. //HudElement hides when player is in menu
  111. hud.HideInMenu = true;
  112. //Set font and fontscale, default is the best looking in my opinion
  113. hud.Font = HudElementFonts.Default;
  114. hud.FontScale = 1.6f;
  115. /* The origin is relative from this point. I did not find out yet how the point type works correctly
  116.   * Just try a bit yourself and find the perfect point
  117.   * You can also let this value 0 then the 'start point' will be right to the radar */
  118. hud.PointType = 81;
  119. //Set the relative origin
  120. hud.OriginY = 70f;
  121. hud.OriginX = 10f;
  122. //Set the label to the HudElement
  123. hud.SetLabel("K/D Ratio: ");
  124. hud.Value = 0f;
  125. return hud.HudElementNum;
  126. }
  127. }
  128. }


Attached Files
.zip   KDRatio.zip (Size: 2.62 KB / Downloads: 292)
[Image: azuw.jpg]
Reply

#2
1.33 is n00bie Troll
Reply

#3
Hey @zxz0O0 are u german?
[Image: ctoc.jpg]
Reply

#4
(07-13-2012, 15:22)Tomsen1410 Wrote: Hey @zxz0O0 are u german?

Swedish who speaks german.
Reply

#5
(07-13-2012, 17:21)surtek Wrote:
(07-13-2012, 15:22)Tomsen1410 Wrote: Hey @zxz0O0 are u german?

Swedish who speaks german.
Swiss
[Image: lQDUjba.jpg]
Reply

#6
(07-13-2012, 15:19)Yamato Wrote: 1.33 is n00bie Troll

It's better than the average, so no, it's not noobie.

Also back on topic, everyone.
Reply

#7
Great little plugin there ZXZ0O0, I really enjoyed testing, even if my ping was 500 lol. Fantastic little tool.
Reply

#8
Also note that if you use a string to display numbers and change the string too often your server will crash eventually, with this method (HudElementTypes.Value) it will not crash.

(GSC coders will know)
[Image: azuw.jpg]
Reply

#9
Also an idea to show actual skill: Points per minute.
Reply

#10
Thanks nice plugin!
And thx for the Hud example Wink
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  [Release] CS addon for MW2(Sounds,show damage) Fl0w_.JACKDAN 1 4,691 09-29-2013, 19:46
Last Post: Nekochan
  [News] Show your wallpaper. Nekochan 6 4,693 07-10-2013, 19:02
Last Post: House
Rainbow [News] Show your awesome mobile device. Nekochan 34 13,999 05-29-2013, 14:59
Last Post: Arteq
Rainbow [News] Show your awesome face Arteq 2 2,781 05-23-2013, 06:11
Last Post: OrangePL
Rainbow Show your mobile device's wallpaper Nekochan 23 11,996 04-05-2013, 18:12
Last Post: SuperNovaAO
  Show your awesome wallpaper V2 JariZ 81 41,070 04-05-2013, 18:10
Last Post: SuperNovaAO
  [Request] !shop hud to show player with highest points hillbilly 3 3,260 02-21-2013, 16:46
Last Post: hillbilly
  [Release] Show Admins abidullah 7 6,295 02-17-2013, 02:28
Last Post: supernuke
  [Release] Show player health on HUD [Z00MBY] Alex 18 13,407 02-03-2013, 00:48
Last Post: JariZ
  [Request] what the code for show orgin pap12322221112 1 1,966 09-21-2012, 09:27
Last Post: d0h!

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2024 Melroy van den Berg.