Need help with kill/death ratio
#1

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.
Reply
#2

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]));
Reply
#3

try to use for ratio %f fiki574 is right use that
Reply
#4

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]));
Reply
#5

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]
Reply
#6

Konstantinos i didnt understand what you wanna say ?
Reply
#7

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]));
Reply
#8

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
Reply
#9

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


Forum Jump:


Users browsing this thread: 1 Guest(s)