Quote:
Originally Posted by Touch
Hello
I need to calculate the ratio player.
But there are problems with the script.
If I did not kill anybody or himself is not dead, then the script in console an error.
But if, as I had killed himself died a few times, then my ratio = 0.00000.
PHP Code:
new userkills = GetClientFrags(client); new userdeaths = GetClientDeaths(client); new Float:ratio; ratio = userkills / userdeaths;
Why is my ratio 0.0000?
Thx!
|
Simple. as you know, in math the denominator can't be '0'
so the error shows up. (you should make special script for that case
just like)
PHP Code:
if(userdeahts == 0)
{
ratio = xx (u can do something u want. I mean just substitute u want)
}
else if(userdeaths > 0)
{
ratio = float(userkills)/float(userdeath) or FloatDiv(float(userkill)/float(userdealth))
}
and if u want to divide float with float
It would be more better to use
Quote:
/**
* Divides the dividend by the divisor.
*
* @param dividend First value.
* @param divisor Second value.
* @return dividend/divisor.
*/
native Float:FloatDiv(Float:dividend, Float:divisor);
|
but if u want to round the float, just use
Quote:
RoundToNearest(Float:value)
|
one more thing which is strange is that the ratio.
I think ratio should be under 100%.
I mean...
ratio = userkill / (userdeath+userkill)