K/D ratio
#1

This is the code I have at the moment:

pawn Код:
new Float:kd =  float(kills)/float(deaths); // Arrays, but replaced with variables to make it simpler
But if I have no kills and no deaths, it says 'NAN' - how do I make it say 0.0?
Reply
#2

I'm also joining this question.
Reply
#3

pawn Код:
if(kills == 0 && deaths == 0) kd = 0;
Reply
#4

pawn Код:
new Float:ratio=floatdiv(gPlayerData[playerid][E_PLAYER_KILLS], gPlayerData[playerid][E_PLAYER_DEATHS]);
format(string, sizeof(string), "Kill/Death Ratio: %.2f", ratio);
SendClientMessage(playerid, COLOR_LIGHTGREEN, string);
replace gPlayerData[playerid][E_PLAYER_KILLS] with your player kills variable
same for gPlayerData[playerid][E_PLAYER_DEATHS]
Reply
#5

new Float:kd = floatdiv(playerstat[playerid][PSTAT_KILLS], playerstat[playerid][PSTAT_DEATHS]);

It's still 'NAN' when I have no kills/deaths, and if I get 1 kill (with still no deaths) it says on 0. I have to die for it to work.

Help :x
Reply
#6

Wow I have used this code for a while and I never noticed that. Sorry I don't know how to fix it.

I guess you just need a minimum of 1 kill and 1 death.
Reply
#7

Quote:
Originally Posted by MP2
Посмотреть сообщение
new Float:kd = floatdiv(playerstat[playerid][PSTAT_KILLS], playerstat[playerid][PSTAT_DEATHS]);

It's still 'NAN' when I have no kills/deaths, and if I get 1 kill (with still no deaths) it says on 0. I have to die for it to work.

Help
Have you tried mine?
Quote:
Originally Posted by =WoR=Varth
Посмотреть сообщение
pawn Код:
if(kills == 0 && deaths == 0) kd = 0;
Reply
#8

Umm yours makes NO sense. How is it supposed to be implemented?
Reply
#9

pawn Код:
new Float:kd;
if(kills == 0 && deaths == 0) kd = 0.0;
else kd = float(kills)/float(deaths);
.............................
Reply
#10

I did this:

pawn Код:
new deaths = playerstat[playerid][PSTAT_DEATHS];
if(!deaths) deaths = 1;
new Float:kd =  floatdiv(playerstat[playerid][PSTAT_KILLS], deaths);
and it works.

Thanks kc
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)