K/D Ratio
#1

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

EDIT: Nevermind.
Reply
#3

but how will that make a difference ?
Reply
#4

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

EDIT: Nevermind.
Reply
#6

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

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

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

The script should work before i work on that ^^
Reply
#10

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)!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)