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=456576)



K/D Ratio - Slepur - 06.08.2013

Hey, I'm trying to add a K/D ratio into /stats but for some reason it's not updating the ratio from the default 0.

Код:
CMD:stats(playerid, params[])
{
	new wstring[238];
	pInfo[playerid][pKD] = pInfo[playerid][pKills] /= pInfo[playerid][pDeaths];
	new kd = pInfo[playerid][pKD];
	new kills = pInfo[playerid][pKills];
	new deaths = pInfo[playerid][pDeaths];

	format(wstring, sizeof(wstring), "Kills:[%d] Deaths:[%d] K/D:[%d]",kills,deaths,kd);
	SendClientMessage(playerid,COLOR_WHITE, wstring);
	return 1;
}



Re: K/D Ratio - Konstantinos - 06.08.2013

pawn Код:
new
    Float: kd = floatdiv( pInfo[playerid][pKills], pInfo[playerid][pDeaths] )
;

// --

format(wstring, sizeof(wstring), "Kills:[%d] Deaths:[%d] K/D:[%.2f]",kills,deaths,kd);
It's Float, not an integer.


Re: K/D Ratio - Vince - 06.08.2013

Make sure you aren't dividing by zero.


Re: K/D Ratio - arjanforgames - 06.08.2013

Your kd ratio is kills divided by deaths so, like Vince says, if you have 0 deaths you are dividing your kills with 0 so it won't work.