SA-MP Forums Archive
K/D ratio - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: K/D ratio (/showthread.php?tid=284583)



K/D ratio - MP2 - 19.09.2011

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?


Re: K/D ratio - [L3th4l] - 19.09.2011

I'm also joining this question.


Re: K/D ratio - =WoR=Varth - 19.09.2011

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



Re: K/D ratio - skullmuncher1337 - 19.09.2011

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]


Re: K/D ratio - MP2 - 19.09.2011

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


Re: K/D ratio - skullmuncher1337 - 19.09.2011

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.


Re: K/D ratio - =WoR=Varth - 19.09.2011

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;



Re: K/D ratio - skullmuncher1337 - 19.09.2011

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


Re: K/D ratio - =WoR=Varth - 19.09.2011

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


Re: K/D ratio - MP2 - 19.09.2011

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