Raised This Month: $51 Target: $400
 12% 

How to check user's KD?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dexon
Member
Join Date: Aug 2019
Old 12-16-2020 , 16:37   How to check user's KD?
Reply With Quote #1

Hello, could anyone help in this?
I tried with the following:

Code:
public kd_check(id){
    ColorChat(id, "!tYour KD: !g%i", (get_user_frags(id)/get_user_deaths(id)))
}
Log:
Run time error 11: divide
[0] bounty.sma::kd_check (line 43)

Last edited by Dexon; 12-16-2020 at 16:38.
Dexon is offline
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 12-16-2020 , 17:10   Re: How to check user's KD?
Reply With Quote #2

Check that the frag is >0 before dividing.
__________________


Quote:
Originally Posted by fysiks View Post
Please stop trying to help. You appear to just be posting random stuff. Wait until you actually understand more about AMX Mod X and how the game works.
https://iceeedr.com.br/
iceeedr is offline
Send a message via Skype™ to iceeedr
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 12-16-2020 , 17:39   Re: How to check user's KD?
Reply With Quote #3

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.
__________________

Last edited by OciXCrom; 12-16-2020 at 17:40.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-16-2020 , 23:12   Re: How to check user's KD?
Reply With Quote #4

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).
__________________

Last edited by fysiks; 12-16-2020 at 23:13.
fysiks is offline
Dexon
Member
Join Date: Aug 2019
Old 12-17-2020 , 04:44   Re: How to check user's KD?
Reply With Quote #5

Thank you all for the answer, now I got this:
Code:
if(get_user_frags(id) > 0){
    ColorChat(id, "!tKD-d: !g%f", get_user_frags(id)/get_user_deaths(id))
}
But it shows the same error. :/

And im not sure with this, may you show me how you thought?
Quote:
you need to first convert them to floating point values with float()
Dexon is offline
+ARUKARI-
AlliedModders Donor
Join Date: Jul 2004
Location: Japan
Old 12-17-2020 , 04:50   Re: How to check user's KD?
Reply With Quote #6

1 / 1 = 1, 1 / 0 = ?
__________________
GitHub
SteamWishlist

六四天安門事件
+ARUKARI- is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 12-17-2020 , 07:39   Re: How to check user's KD?
Reply With Quote #7

Code:
new iDeaths = get_user_deaths(id) if(iDeaths) {     ColorChat(id, "!tKD-d: !g%f", float(get_user_frags(id)) / float(get_user_deaths(id))) }
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Dexon
Member
Join Date: Aug 2019
Old 12-17-2020 , 16:19   Re: How to check user's KD?
Reply With Quote #8

Thank you all, it's all fine.

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?

Last edited by Dexon; 12-17-2020 at 16:20.
Dexon is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 12-17-2020 , 17:31   Re: How to check user's KD?
Reply With Quote #9

if(iDeaths) print your regular message
else print 1

?
__________________

Last edited by OciXCrom; 12-17-2020 at 17:32.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Natsheh
Veteran Member
Join Date: Sep 2012
Old 12-17-2020 , 20:50   Re: How to check user's KD?
Reply With Quote #10

PHP Code:
public kd_check(id){
    
ColorChat(id"!tYour KD: !g%.2f", ( get_user_fragsid ) / floatmaxget_user_deathsid ), ) ) ) )

here you go.

also their method works fine the only problem it won't print in chat if the user has a 0 deaths.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 12-17-2020 at 21:03.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:30.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode