Float (Problem)
#1

Hello,

Run time error 11: "Devide by zero"
I've managed to find the problem in my script which leads to these lines;
Код:
	new Float:kr;
	kr = (g_playerdata[pid][KILLS]/g_playerdata[pid][DEATHS]);
	format(string, sizeof(string), "{EBD113}(Kills/Deaths) {FFFFFF}Kills -> %i .. Drive-by kills - > %i .. Deaths -> %i .. Suicides -> %i .. Ratio -> %.2fm", g_playerdata[pid][KILLS], g_playerdata[pid][DBKILLS], g_playerdata[pid][DEATHS], g_playerdata[pid][SUICIDES],kr);
	SendPlayerInfo(playerid, string);
The Ratio -> %.2fm code tends to appear as an 'unknown command' ?
I have used new Float:kr; but doesn't work.

Any suggestions would be appreciated. Thanks
Reply
#2

Try to print the KR.
I dont know but, change:

%.2fm

to

%.2f

without the 'm'
Reply
#3

You must check if deaths are not equal to 0, if death is 0, you must not divide.
Reply
#4

Okay, I see.
Reply
#5

pawn Код:
new Float:kr;
//______________
if(g_playerdata[pid][DEATHS] == 0)
    format(string, sizeof(string), "{EBD113}(Kills/Deaths) {FFFFFF}Kills -> %i .. Drive-by kills - > %i .. Deaths -> %i .. Suicides -> %i .. Ratio -> N/A", g_playerdata[pid][KILLS], g_playerdata[pid][DBKILLS], g_playerdata[pid][DEATHS], g_playerdata[pid][SUICIDES]);
else
{
kr = (g_playerdata[pid][KILLS]/g_playerdata[pid][DEATHS]);
    format(string, sizeof(string), "{EBD113}(Kills/Deaths) {FFFFFF}Kills -> %i .. Drive-by kills - > %i .. Deaths -> %i .. Suicides -> %i .. Ratio -> %.2fm", g_playerdata[pid][KILLS], g_playerdata[pid][DBKILLS], g_playerdata[pid][DEATHS], g_playerdata[pid][SUICIDES],kr);
}
   
//______________
   
    SendPlayerInfo(playerid, string);
Reply
#6

Thank you, your code works fine.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)