AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Hud message float (https://forums.alliedmods.net/showthread.php?t=225268)

Bladell 09-02-2013 14:47

Hud message float
 
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?

11530 09-02-2013 14:51

Re: Hud message float
 
Best advice would be to post in the appropriate amx mod x section.

Mitchell 09-02-2013 15:10

Re: Hud message float
 
%.1f

Bladell 09-02-2013 15:39

Re: Hud message float
 
Sorry, wrong section...
I don't understand Mitchell

Powerlord 09-02-2013 15:54

Re: Hud message float
 
Quote:

Originally Posted by Bladell (Post 2027213)
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.

11530 09-02-2013 17:10

Re: Hud message float
 
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.

Bladell 09-03-2013 04:43

Re: Hud message float
 
Works now, thanks.
But if the value is 1.5 he show me 1.4...other adices please?

MasterOfTheXP 09-03-2013 06:58

Re: Hud message float
 
Considering that (apparently) a value of 1.5 was being shown as 1.4999999, perhaps try something like 1.5000001 with %.1f?

Bladell 09-03-2013 11:23

Re: Hud message float
 
I can't use a number like this as multiplier...I have to work with this every day.

Powerlord 09-03-2013 13:07

Re: Hud message float
 
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?


All times are GMT -4. The time now is 18:51.

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