SA-MP Forums Archive
Kills Deaths 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: Kills Deaths Ratio (/showthread.php?tid=313572)



Kills Deaths Ratio - geerdinho8 - 26.01.2012

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?


Re: Kills Deaths Ratio - Konstantinos - 26.01.2012

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



Re: Kills Deaths Ratio - geerdinho8 - 26.01.2012

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?


Re: Kills Deaths Ratio - Konstantinos - 26.01.2012

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



Re: Kills Deaths Ratio - geerdinho8 - 26.01.2012

Are you sure, because it aint working?


Re: Kills Deaths Ratio - Konstantinos - 26.01.2012

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


Re: Kills Deaths Ratio - Vince - 26.01.2012

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



Re: Kills Deaths Ratio - MP2 - 26.01.2012

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.


Re: Kills Deaths Ratio - geerdinho8 - 26.01.2012

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;
    }



Re: Kills Deaths Ratio - [XST]O_x - 26.01.2012

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