Create KD Ratio

Hello…

I want to create a simple KD Ration counter for custom game but I got some problem.

I created this :

{
Set objective description(Event Player, Custom String(“KD : {0}”, Player Stats(Event Player, Kills) / Player Stats(Event Player, Deaths)), Visible for and strings);
}

It works well, IF you got at least 1 death already because it divides by 0 and so this gives 0…

Also I’d like to show “1” instead of “0” if kills and deaths are “0”

Thanks !

have you tried replacing

with
Player, Custom String(“KD : {1}”,
?

that… won’t do anything, it will just change the placeholder in the string

1 Like

sorry im not good with that kinda stuff, was just a thought lol

Add the bold text:
{
Set objective description(Event Player, Custom String(“KD : {0}”, Max(Player Stats(Event Player, Kills),1) / Max(Player Stats(Event Player, Deaths),1)), Visible for and strings);
}

4 Likes

Kinkku was faster and provided a shorter solution in the end, mine works with if-then-else value, the result is simliar, whenever the KD would become 0 it prints 1 instead of 0; here is my suggestion:

rule("Rule 1")
{
	event
	{
		Ongoing - Global;
	}

	conditions
	{
		(Is In Setup || Is Game In Progress) == True;
	}

	actions
	{
		Set Objective Description(Local Player, Custom String("KD-Ratio:{0}", Player Stat(Local Player, Eliminations) / Player Stat(
			Local Player, Deaths) == 0 ? Custom String("1") : Player Stat(Local Player, Eliminations) / Player Stat(Local Player, Deaths)),
			Visible To and String);
	}
}

Note there are different types of kill meassurements or records, so you can display different type of KDs, for example Solo Kills implies the player killed someone without assist crediting.

3 Likes