How to check user's KD?
Hello, could anyone help in this?
I tried with the following: Code:
public kd_check(id){Run time error 11: divide [0] bounty.sma::kd_check (line 43) |
Re: How to check user's KD?
Check that the frag is >0 before dividing.
|
Re: How to check user's KD?
Deaths > 0*
Dividing zero is fine, dividing by zero is not. Also, you need to use %f, not %i because the result will most likely be a floating point number, not an integer. |
Re: How to check user's KD?
Both get_user_frags() and get_user_deaths() return integers so the result will be an integer (see "integer division" e.g. 10/3 = 3, 5/10 = 0, etc.). To get a proper value for the KDR, you need to first convert them to floating point values with float() and then use %f in your format string.
Note: Do the 0 deaths check before converting to a float (i.e. store the deaths in a variable first so you don't need to call it twice). |
Re: How to check user's KD?
Thank you all for the answer, now I got this:
Code:
if(get_user_frags(id) > 0){And im not sure with this, may you show me how you thought? Quote:
|
Re: How to check user's KD?
1 / 1 = 1, 1 / 0 = ?
|
Re: How to check user's KD?
Code:
|
Re: How to check user's KD?
Thank you all, it's all fine. :crab:
But usually K/D counts even if user has 0 deaths. So may anyone have an idea about: if a user has 0 deaths, make the value to 1, but not the get_user_deaths, because it would just give the player +1 death in the scoreboard? |
Re: How to check user's KD?
if(iDeaths) print your regular message
else print 1 ? |
Re: How to check user's KD?
PHP Code:
also their method works fine the only problem it won't print in chat if the user has a 0 deaths. |
| All times are GMT -4. The time now is 14:12. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.