Kills Deaths Ratio
#1

pawn Код:
format(Msg, sizeof(Msg), ""COL_PINK"Kills: "COL_GREY"[%d]\n"COL_PINK""COL_PINK"Deaths: "COL_GREY"[%d] \n"COL_PINK""COL_PINK"Ratio: "COL_GREY"[%f] \n"COL_PINK""COL_PINK"Score: "COL_GREY"[%d]\n"COL_PINK"Money: "COL_GREY"[$ %d]\n"COL_PINK"Adminlevel: "COL_GREY"[%d]\n"COL_PINK"", pInfo[playerid][Kills], pInfo[playerid][Deaths], (Float:pInfo[playerid][Deaths] / pInfo[playerid][Kills]),GetPlayerScore(playerid),GetPlayerMoney(playerid), pInfo[playerid][Admin]);

Look at the Ratio [%f] and the (FloatInfo[playerid][Deaths] / pInfo[playerid][Kills])

I thought this would work but it doesn't can anybody help me?
Reply
#2

It's kills by deaths
pawn Код:
new
    Msg[ 5 ], Float:Ratio = pInfo[playerid][Kills]/FloatInfo[playerid][Deaths];
   
format( Msg, sizeof( Msg ), "Ratio: %f", Ratio );
Reply
#3

Now using this:

pawn Код:
if( strcmp( "/ratio", cmdtext, true, 6 ) == 0 ) {
        new
        Msg[ 200 ], Float:Ratio = pInfo[playerid][Kills]/pInfo[playerid][Deaths];
        format( Msg, sizeof( Msg ), ""COL_PINK"Ratio: "COL_GREY"%f", Ratio );
        ShowPlayerDialog(playerid, 555, DIALOG_STYLE_MSGBOX, ""COL_ORANGE"Ratio", Msg,"Ok","");

        return 1;
    }
But when i do /ratio it shows 3.0000 but it supposed to be 3.724 or something like that, any way to fix?
Reply
#4

Then replace
pawn Код:
%f
To
pawn Код:
%.3f
Reply
#5

Are you sure, because it aint working?
Reply
#6

the %.3f means for example the float is 3.724984, it will show the 3 first Chars after the dot( . ) Like: 3.724
Reply
#7

Integer divided by integer will still give integer, it's simple as that. Try it like:
pawn Код:
new Float:ratio = (float(kills) / float(deaths));
Reply
#8

Also, I had a bad experience with this:

If deaths is 0, it always ended up returning 'NaN' for me. I had to check that if deaths were 0, set them to 1.
Reply
#9

Quote:
Originally Posted by Vince
Посмотреть сообщение
Integer divided by integer will still give integer, it's simple as that. Try it like:
pawn Код:
new Float:ratio = (float(kills) / float(deaths));

Can you be more specific?"

I now have this but it still aint working:

pawn Код:
if( strcmp( "/ratio", cmdtext, true, 6 ) == 0 ) {
        new
        Msg[ 200 ], Float:Ratio = (pInfo[playerid][Kills]/pInfo[playerid][Deaths]);
        format( Msg, sizeof( Msg ), ""COL_PINK"Ratio: "COL_GREY"%.3f", Ratio );
        ShowPlayerDialog(playerid, 555, DIALOG_STYLE_MSGBOX, ""COL_ORANGE"Ratio", Msg,"Ok","");

        return 1;
    }
Reply
#10

In your case then:
pawn Код:
new Float:Ratio = (float(pInfo[playerid][Kills])/float(pInfo[playerid][Deaths]));
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)