AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Question about percentage calculation. (https://forums.alliedmods.net/showthread.php?t=184651)

<VeCo> 05-07-2012 10:42

Question about percentage calculation.
 
Hello, I want to make a HUD message which looks like that:

>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<

I have 2 variables, but I can't think of how exactly I can do it to show the percent of each variable (depending on the sum of them).
I have tried different ways buy I couldn't do it exactly as I want.

When they have the same value, then it should be 50%-50% and the HUD should look like the one above.

When they are 75%-50% the HUD should look like:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<

When they are 100%-0% it should be:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

99%-1%:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><

And so on...

The HUD must be always 40 characters.
The variables are integer numbers.

How exactly can I do this?

Exolent[jNr] 05-07-2012 10:59

Re: Question about percentage calculation.
 
You can do this:

Code:
GetHudBar(percent, output[], output_len, size = 40) {     new left_len = size * percent / 100;         new p;     while(p < output_len && p < left_len) {         output[p++] = '>';     }         while(p < output_len && p < size) {         output[p++] = '<';     }         output[p] = EOS;         return p; }

Usage:
Code:
new bar[41]; // 40 characters + 0 terminator GetHudBar(50, bar, charsmax(bar)); // should produce // >>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<

<VeCo> 05-07-2012 11:50

Re: Question about percentage calculation.
 
Thank you! :)
I also had a problem with the percent calculation, but I solved it...


All times are GMT -4. The time now is 00:28.

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