Raised This Month: $ Target: $400
 0% 

Hud message float


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bladell
Senior Member
Join Date: Jun 2012
Old 09-02-2013 , 14:47   Hud message float
Reply With Quote #1

PHP Code:
new gPcvarPercentNum
gPcvarPercentNum 
register_cvar("vip_percentadd""1.5")
ShowSyncHudMsg(players[i], hudsync"You are VIP!^nXp rate: %f x"get_pcvar_num(gPcvarPercentNum)) 
Problem: It show on screen
Code:
You are VIP!
Xp rate: 1.4999999 x
Or if vip_percentadd = 2.0
Code:
You are VIP!
Xp rate: 2.0000000 x
How can I fix this?I want to show 1,5 or 2.0 or any value that I set on that cvar.Not a big number with a lot of 00000000000.
Advices?
Bladell is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 09-02-2013 , 14:51   Re: Hud message float
Reply With Quote #2

Best advice would be to post in the appropriate amx mod x section.
__________________
11530 is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 09-02-2013 , 15:10   Re: Hud message float
Reply With Quote #3

%.1f
Mitchell is offline
Bladell
Senior Member
Join Date: Jun 2012
Old 09-02-2013 , 15:39   Re: Hud message float
Reply With Quote #4

Sorry, wrong section...
I don't understand Mitchell
Bladell is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 09-02-2013 , 15:54   Re: Hud message float
Reply With Quote #5

Quote:
Originally Posted by Bladell View Post
Sorry, wrong section...
I don't understand Mitchell
He's saying that instead of %f use %.1f as documented on the Advanced Formatting section of the Format Class Functions wiki page.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 09-02-2013 , 17:10   Re: Hud message float
Reply With Quote #6

Does AMX follow all the same format specifiers as SourceMod? It might follow the same as C's printf but I've never bothered looking into AMX too much.
__________________
11530 is offline
Bladell
Senior Member
Join Date: Jun 2012
Old 09-03-2013 , 04:43   Re: Hud message float
Reply With Quote #7

Works now, thanks.
But if the value is 1.5 he show me 1.4...other adices please?
Bladell is offline
MasterOfTheXP
Veteran Member
Join Date: Aug 2011
Location: Cloudbank
Old 09-03-2013 , 06:58   Re: Hud message float
Reply With Quote #8

Considering that (apparently) a value of 1.5 was being shown as 1.4999999, perhaps try something like 1.5000001 with %.1f?
__________________
Plugins / My Steam / TF2 Sandbox (plugin beta testing!)
MasterOfTheXP is offline
Bladell
Senior Member
Join Date: Jun 2012
Old 09-03-2013 , 11:23   Re: Hud message float
Reply With Quote #9

I can't use a number like this as multiplier...I have to work with this every day.
Bladell is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 09-03-2013 , 13:07   Re: Hud message float
Reply With Quote #10

Yes, unfortunately Format truncates it rather than rounds.

There's no good way to round a Float to a specific number of decimal places, other than to multiply the value by 10 times the number of decimal places you want, round it, then divide it by the same number you multiplied it by.

In SourceMod, that'd be

PHP Code:
RoundFloat(GetConVarFloat(gPcvarPercentNum) * 10) / 10 
I don't know the AMXModX equivalent...

Also, why hasn't a mod moved this to the AMXModX board yet?
__________________
Not currently working on SourceMod plugin development.
Powerlord 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 18:51.


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