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



K/D Ratio - spd_sahil - 08.11.2011

OKay so heres my script for the K/D ratio. and it doesnt seem to be working u might wanna take a look

pawn Код:
new playerkill[256];
new playerdeath[256];
new Float:KD;
pawn Код:
OnPlayerConnect(playerid)
{
    playerkill[playerid] = 0;
    playerdeath[playerid] = 0;
}
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
        SendDeathMessage(killerid, playerid, reason);
        playerkill[killerid]++;
        playerdeath[playerid]++;

        KD = floatdiv(playerkill[killerid],playerdeath[killerid]);
        new string[32];
        format(string,32, "%.2f",KD);
        TextDrawSetString(Textdraw3[killerid],string);

        KD = floatdiv(playerkill[playerid],playerdeath[playerid]);
        format(string,32, "%.2f",KD);
        TextDrawSetString(Textdraw3[killerid],string);
   
        return 1;
}
the KD doesnt increase at all.. its always 0.00


Re: K/D Ratio - Stigg - 08.11.2011

EDIT: Nevermind.


Re: K/D Ratio - spd_sahil - 08.11.2011

but how will that make a difference ?


Re: K/D Ratio - SmiT - 08.11.2011

Try to make a check if killerid isn't equal to invalid player id -

pawn Код:
public OnPlayerDeath( playerid, killerid, reason )
{
    new
        string[ 32 ];
       
    if ( killerid != INVALID_PLAYER_ID )
    {
        SendDeathMessage( killerid, playerid, reason );
        playerkill[ killerid ] ++;
        KD = floatdiv( playerkill[ killerid ], playerdeath[ killerid ] );
        format( string, 32, "%.2f", KD );
        TextDrawSetString( Textdraw3[ killerid ], string );
    }
    playerdeath[ playerid ] ++;
    KD = floatdiv( playerkill[ playerid ], playerdeath[ playerid ] );
    format( string, 32, "%.2f", KD );
    TextDrawSetString( Textdraw3[ playerid ], string ); /* Replaced killerid with playerid */
    return 1;
}



Re: K/D Ratio - Stigg - 08.11.2011

EDIT: Nevermind.


Re: K/D Ratio - spd_sahil - 08.11.2011

Quote:
Originally Posted by Stigg
Посмотреть сообщение
Output = %0.2f
not that , making the variable inside OnPlayerDeath rather than a solid variable..

and @SMiT ill try that now.. but doesnt seem too different


Re: K/D Ratio - Stigg - 08.11.2011

Quote:
Originally Posted by spd_sahil
Посмотреть сообщение
not that , making the variable inside OnPlayerDeath rather than a solid variable..

and @SMiT ill try that now.. but doesnt seem too different
My mistake, read it wrong.


Re: K/D Ratio - [03]Garsino - 08.11.2011

Make sure none of the variables equals 0. You cannot divide by 0.

Just add an extra check to see if it they equal 0. If kills equals 18 and deaths equals 0 make it show 18.00, etc..


Re: K/D Ratio - spd_sahil - 08.11.2011

The script should work before i work on that ^^


Re: K/D Ratio - [03]Garsino - 08.11.2011

Quote:
Originally Posted by spd_sahil
Посмотреть сообщение
The script should work before i work on that ^^
I hope you realise that is one of the reasons why it's not working?

You cannot divide something by 0 (a.k.a. NOTHING)!