AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [solved]how to? (https://forums.alliedmods.net/showthread.php?t=157175)

jc980 05-17-2011 12:35

[solved]how to?
 
how do I make an integer into a percent?

example i want the value of "zp44_xp[id] = 128796" to turn into percent?

and the value of its max xp before leveling up is "max_xp = 140000"

so how can i do it.

and its shows in HUD Message

[Level: 14000] [Experience: 75%]

anyone?

Nyuszy 05-17-2011 12:53

Re: [help]how to?
 
PHP Code:

new exp zp44_xp[id] / max_xp 100
client_print
(idprint_center"Experience: %i%"exp


Exolent[jNr] 05-17-2011 12:59

Re: [help]how to?
 
Quote:

Originally Posted by Nyuszy (Post 1471066)
PHP Code:

new exp zp44_xp[id] / max_xp 100
client_print
(idprint_center"Experience: %i%"exp


1. You should multiply 100 first, otherwise it will be a truncated decimal always resulting in 0.
2. To show a percent sign in a format, you need to use a double percent sign.

PHP Code:

new exp zp44_xp[id] * 100 max_xp
client_print
(idprint_center"Experience: %i%%"exp


jc980 05-17-2011 13:00

Re: [help]how to?
 
Quote:

Originally Posted by Nyuszy (Post 1471066)
PHP Code:

new exp zp44_xp[id] / max_xp 100
client_print
(idprint_center"Experience: %i%"exp


yehey! thank you! topic solved.

@exolent

does "%i^%" work too?

and do i have to make a floatround?

fysiks 05-17-2011 19:54

Re: [help]how to?
 
Quote:

Originally Posted by jc980 (Post 1471076)
yehey! thank you! topic solved.

@exolent

does "%i^%" work too?

and do i have to make a floatround?

0. Only Exolent's code will work correctly.
1. Try it and find out.
2. With Exolent's code, it effectively rounds for you automatically (rounds to floor)


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

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