SA-MP Forums Archive
Need help with kill/death 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: Need help with kill/death ratio (/showthread.php?tid=494957)



Need help with kill/death ratio - barts - 15.02.2014

PHP код:
format(stringsizeof(string), "Kills: [%d] - Deaths: [%d] - K/D Ratio: [%d] "PlayerInfo[playerid][Kills], PlayerInfo[playerid][Deaths], PlayerInfo[playerid][Kills]/PlayerInfo[playerid][Deaths]); 
This is my /stats cmd
When i test it all works. but K/D ratio always stay at 0, help me please.


Re: Need help with kill/death ratio - fiki574 - 15.02.2014

pawn Код:
format(string, sizeof(string), "Kills: [%d] - Deaths: [%d] - K/D Ratio: [%f] ", PlayerInfo[playerid][Kills], PlayerInfo[playerid][Deaths], floatround(PlayerInfo[playerid][Kills]/PlayerInfo[playerid][Deaths]));



Re: Need help with kill/death ratio - MBilal - 15.02.2014

try to use for ratio %f fiki574 is right use that


Re: Need help with kill/death ratio - Threshold - 15.02.2014

Quote:
Originally Posted by fiki574
Посмотреть сообщение
pawn Код:
format(string, sizeof(string), "Kills: [%d] - Deaths: [%d] - K/D Ratio: [%f] ", PlayerInfo[playerid][Kills], PlayerInfo[playerid][Deaths], floatround(PlayerInfo[playerid][Kills]/PlayerInfo[playerid][Deaths]));
The usage of 'floatround' would convert that back into an integer. So the results might come out a little weird with that code.

pawn Код:
format(string, sizeof(string), "Kills: [%d] - Deaths: [%d] - K/D Ratio: [%.2f] ", PlayerInfo[playerid][Kills], PlayerInfo[playerid][Deaths], (PlayerInfo[playerid][Kills] / PlayerInfo[playerid][Deaths]));



Re: Need help with kill/death ratio - Konstantinos - 15.02.2014

A run time error about diving with 0 will be caused if deaths are 0. Use this for the ratio:
pawn Код:
floatdiv(PlayerInfo[playerid][Kills], PlayerInfo[playerid][Deaths])
And use placeholder:
pawn Код:
K/D Ratio: [%.2f]
instead of:
pawn Код:
K/D Ratio: [%d]



Re: Need help with kill/death ratio - barts - 15.02.2014

Konstantinos i didnt understand what you wanna say ?


Re: Need help with kill/death ratio - Konstantinos - 15.02.2014

pawn Код:
format(string, sizeof(string), "Kills: [%d] - Deaths: [%d] - K/D Ratio: [%.2f] ", PlayerInfo[playerid][Kills], PlayerInfo[playerid][Deaths], floatdiv(PlayerInfo[playerid][Kills], PlayerInfo[playerid][Deaths]));



Re: Need help with kill/death ratio - ReD_HunTeR - 15.02.2014

he mean this i think
pawn Код:
format(string, sizeof(string), "Kills: [%d] - Deaths: [%d] - K/D Ratio: [%.2f] ", PlayerInfo[playerid][Kills], PlayerInfo[playerid][Deaths], floatdiv(PlayerInfo[playerid][Kills], PlayerInfo[playerid][Deaths]));
Edit: too late


Re: Need help with kill/death ratio - barts - 15.02.2014

Thanks to Konstantinos and BlackBomb, it is working now.+REP fo you guys