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:
Code:
using System; using System.Collections.Generic; using System.Text; using Addon; namespace KDRatio { public class Class1 : CPlugin { //Store ClientNum and HudElementNum in dictionary Dictionary<int, int> Client_HudElem = new Dictionary<int, int>(); public override void OnServerLoad() { ServerPrint("\n K/D Ratio Plugin loaded \n Author: zxz0O0 \n Thanks to Nukem, Jariz and Pozzuh\n"); ServerPrint(" youtube.com/zxz0O0 \n itsmods.com\n"); } public override void OnPlayerConnect(ServerClient Client) { int HudElemNum = CreateKDHud(Client.ClientNum); //Add client and it's kd hudelement to the list if (Client_HudElem.ContainsKey(Client.ClientNum)) Client_HudElem[Client.ClientNum] = HudElemNum; else Client_HudElem.Add(Client.ClientNum, HudElemNum); } public override void OnPlayerDisconnect(ServerClient Client) { if(Client_HudElem.ContainsKey(Client.ClientNum)) { //Get client's k/d hudelement HudElem kd = GetHudElement(Client_HudElem[Client.ClientNum]); //Setting hudelement's type to None 'deletes' it AFAIK kd.Type = HudElementTypes.None; //Remove entry from Dictionary Client_HudElem.Remove(Client.ClientNum); } } public override int OnPlayerDamaged(ServerClient Attacker, ServerClient Victim, string Weapon, int Damage) { //If kill if (Damage >= Victim.Other.Health) { //Update victim's value if (Client_HudElem.ContainsKey(Victim.ClientNum)) { HudElem victim = GetHudElement(Client_HudElem[Victim.ClientNum]); //victim.Value = (float)Victim.Stats.Kills / (Victim.Stats.Deaths + 1); victim.Value = (float)Math.Round((double)Victim.Stats.Kills / (Victim.Stats.Deaths + 1), 2); if (victim.Value < 1) { //Make it red victim.Color.R = 255; victim.Color.G = 0; victim.Color.B = 0; } else { //Make green victim.Color.R = 0; victim.Color.G = 255; victim.Color.B = 0; } } //Don't do it when victim is attacker if (Victim.ClientNum != Attacker.ClientNum) { //Update attacker's value if (Client_HudElem.ContainsKey(Attacker.ClientNum)) { HudElem attacker = GetHudElement(Client_HudElem[Attacker.ClientNum]); //Don't divide by zero :O if (Attacker.Stats.Deaths == 0) attacker.Value = Attacker.Stats.Kills + 1; else attacker.Value = (float)(Math.Round((double)(Attacker.Stats.Kills + 1) / Attacker.Stats.Deaths, 2)); if (attacker.Value < 1) { //Make it red attacker.Color.R = 255; attacker.Color.G = 0; attacker.Color.B = 0; } else { //Make green attacker.Color.R = 0; attacker.Color.G = 255; attacker.Color.B = 0; } } } } return Damage; } private int CreateKDHud(int ClientNum) { //Create a simply 'empty' HudElement HudElem hud = CreateNewHudElem(); //Make the HudElement Value hud.Type = HudElementTypes.Value; //Show the HudElement only to the Client hud.ShowToEnt = ClientNum; //HudElement hides when player is in menu hud.HideInMenu = true; //Set font and fontscale, default is the best looking in my opinion hud.Font = HudElementFonts.Default; hud.FontScale = 1.6f; /* The origin is relative from this point. I did not find out yet how the point type works correctly * Just try a bit yourself and find the perfect point * You can also let this value 0 then the 'start point' will be right to the radar */ hud.PointType = 81; //Set the relative origin hud.OriginY = 70f; hud.OriginX = 10f; //Set the label to the HudElement hud.SetLabel("K/D Ratio: "); hud.Value = 0f; return hud.HudElementNum; } } }


Attached Files
.zip   KDRatio.zip (Size: 2.62 KB / Downloads: 333)
[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 6,298 09-29-2013, 19:46
Last Post: Nekochan
  [News] Show your wallpaper. Nekochan 6 6,980 07-10-2013, 19:02
Last Post: House
Rainbow [News] Show your awesome mobile device. Nekochan 34 20,864 05-29-2013, 14:59
Last Post: Arteq
Rainbow [News] Show your awesome face Arteq 2 4,049 05-23-2013, 06:11
Last Post: OrangePL
Rainbow Show your mobile device's wallpaper Nekochan 23 16,966 04-05-2013, 18:12
Last Post: SuperNovaAO
  Show your awesome wallpaper V2 JariZ 81 56,051 04-05-2013, 18:10
Last Post: SuperNovaAO
  [Request] !shop hud to show player with highest points hillbilly 3 4,514 02-21-2013, 16:46
Last Post: hillbilly
  [Release] Show Admins abidullah 7 8,015 02-17-2013, 02:28
Last Post: supernuke
  [Release] Show player health on HUD [Z00MBY] Alex 18 17,052 02-03-2013, 00:48
Last Post: JariZ
  [Request] what the code for show orgin pap12322221112 1 2,826 09-21-2012, 09:27
Last Post: d0h!

Forum Jump:


Users browsing this thread:
1 Guest(s)

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