Raised This Month: $32 Target: $400
 8% 

Dividing the numbers in sourcemod


Post New Thread Reply   
 
Thread Tools Display Modes
Master53
Veteran Member
Join Date: Dec 2009
Old 08-31-2010 , 09:02   Re: Dividing the numbers in sourcemod
Reply With Quote #11

hum
Code:
RoundFloat

          Syntax: stock RoundFloat(Float:value) 

Usage:  value            Floating point value to round.Notes: Rounds a floating point number using the "round to nearest" algorithm.                           

Return: The value rounded to the nearest integer.
__________________
Master(d)



Master53 is offline
Lord Canistra
Senior Member
Join Date: Mar 2009
Location: Tallinn, Estonia
Old 08-31-2010 , 09:03   Re: Dividing the numbers in sourcemod
Reply With Quote #12

>if userdeaths is 0, your script will
Oh my, just noticed division by zero ftw!

iirc RoundToNearest will return rounded integer. I assume Touch needs to shorten number count past comma.
In this case, you can reduce it in this way:
PHP Code:
PrintToChatAll("%.2f"ratio); 
, where 2 is count of numbers past comma. In example given above, it would turn 2.000000 into 2.00 . Adjust this to your liking, also, you can use this formatting method in most print/format functions.
__________________
Lord Canistra is offline
dirka_dirka
Veteran Member
Join Date: Nov 2009
Old 08-31-2010 , 09:49   Re: Dividing the numbers in sourcemod
Reply With Quote #13

master53 as usual is way off. you dont want ratio to be an integer. use what lord canistra said to trim the decimals when viewing.

also..
PHP Code:
Float:ratio = ( (userdeaths == 0) ? 0.0 FloatDivfloat(userkills), float(userdeaths) ) );
PrintToChatAll("ratio = %.1f"ratio);  // ratio = 2.0 
dirka_dirka is offline
Samantha
SourceMod Donor
Join Date: Feb 2010
Location: Madagascar
Old 08-31-2010 , 10:29   Re: Dividing the numbers in sourcemod
Reply With Quote #14

Code:
new userkills = GetClientFrags(client);
new userdeaths = GetClientDeaths(client);
new ratio;
ratio = RoundToCeil(userkills / userdeaths);  
__________________
"I give sopport and knolage in making extractions"
"MASTER(D) - dun0: are you mocing me?" -Master the grate

Plugins
Godmode Until Attack | No Block Team Filter
Extensions
Rcon Hooks
Samantha is offline
FaTony
Veteran Member
Join Date: Aug 2008
Old 08-31-2010 , 13:57   Re: Dividing the numbers in sourcemod
Reply With Quote #15

Quote:
Originally Posted by Lord Canistra View Post
Frags & deaths are integer, not float.
Try
PHP Code:
ratio = (float)(userkills) / (float)(userdeaths
What the hell? C-style casts in SourcePawn?

Also, all those guys trying to round float to integer, while ratio clearly should be float, suck at programming.

dirka_dirka is the best.
FaTony is offline
Lord Canistra
Senior Member
Join Date: Mar 2009
Location: Tallinn, Estonia
Old 08-31-2010 , 14:07   Re: Dividing the numbers in sourcemod
Reply With Quote #16

Is it wrong? Won't the code work?
__________________
Lord Canistra is offline
FaTony
Veteran Member
Join Date: Aug 2008
Old 08-31-2010 , 14:15   Re: Dividing the numbers in sourcemod
Reply With Quote #17

I have never seen (float)(...) in Pawn, only in C/C++. Pawn does "casts" using Float:... However, it is not needed here at all. The only correct would be float(...). Haven't tested (float)(...) at all.
FaTony is offline
Predailien12
Senior Member
Join Date: Feb 2010
Location: Your as* hol*
Old 09-01-2010 , 06:06   Re: Dividing the numbers in sourcemod
Reply With Quote #18

Quote:
Originally Posted by Touch View Post
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 wantI 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)

Last edited by Predailien12; 09-01-2010 at 06:15.
Predailien12 is offline
Death [GER]
Senior Member
Join Date: Mar 2010
Old 09-01-2010 , 06:54   Re: Dividing the numbers in sourcemod
Reply With Quote #19

1. If you have more kills than Deaths, your Ratio will be over 100%

2.
PHP Code:
stock GetClientKillDeathRatio(Client)
{
    new 
Deaths GetClientDeaths(Client);
    if(!
Deaths) return 0.0;
        else return 
float(GetClientFrags(Client))/float(Deaths);
}

new 
Float:Ratio GetClientKillDeathRatio(Client); 
Cant test this because I'm at work atm.. But should work

Last edited by Death [GER]; 09-01-2010 at 06:59.
Death [GER] is offline
Monkeys
Veteran Member
Join Date: Jan 2010
Old 09-01-2010 , 07:49   Re: Dividing the numbers in sourcemod
Reply With Quote #20

Your script won't work, Death.
if (!Death) will run when Death is not 0, meaning it returns 0.0 for everything but 0, and when it's 0, it'll try to divide by it. Not good.

Additionally, you're returning Floats where an Integer is expected. Change your expected return type.



And a good script has been posted ages ago by dirka_dirka.
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Monkeys is offline
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 03:35.


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