AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How Can I calculate percentage to next rank ( based on frags) ) (https://forums.alliedmods.net/showthread.php?t=206792)

danonix 01-26-2013 04:35

How Can I calculate percentage to next rank ( based on frags) )
 
Hello guys, how can I calculate percentage of my rank? I mean that, so if I have got 3 frags of 29 how can I calculate percent? Something like that. How it should look if its possible? Can you send me a tip? Thanks

Code:

public xp(id)
{
    static stats[8]
    if ( stats[0] >= 0 && stats[0] < 29)
    exp == stats[0]/29
    set_hudmessage(255, 0, 0, -1.0, 0.01)
    show_hudmessage(id, "Your XP: %d", exp);
   
    else if (stats[0] > 29 && stats[0] < 40)
    exp1 == stats[0]/40
    set_hudmessage(255, 0, 0, -1.0, 0.01)
    show_hudmessage(id, "Your XP: %d", exp1)
   
}


Sylwester 01-26-2013 04:44

Re: How Can I calculate percentage to next rank ( based on frags) )
 
PHP Code:

percent 100 * ( your_total_frags current_rank_frags ) / ( next_rank_frags current_rank_frags 


danonix 01-26-2013 04:55

Re: How Can I calculate percentage to next rank ( based on frags) )
 
So it should look, or it's wrong? And how to get next_rank_frags?

PHP Code:

    static stats[8]
    if ( 
stats[0] >= && stats[0] < 29)
    
exp == 100 * ( static[0] - get_user_frags(id)) / ( ?????? - get_user_frags(id)) 
    
set_hudmessage(25500, -1.00.01)
    
show_hudmessage(id"Your XP: %d"exp); 


Sylwester 01-26-2013 06:06

Re: How Can I calculate percentage to next rank ( based on frags) )
 
You got it wrong. In this case current_rank_frags is 0, next_rank_frags is 29, so you can reduce the formula to:
PHP Code:

exp 100 stats[0] / 29 

But there are other problems:
- you forgot to use brackets { }
- using if(...) else ... to check rank is wrong. You should store kills required for each rank in an array and use loop to calculate rank (check this: https://forums.alliedmods.net/showth...82#post1672682)

danonix 01-26-2013 08:07

Re: How Can I calculate percentage to next rank ( based on frags) )
 
Uhh, I got it, so next rank ( from 29 to 40 ) should be

PHP Code:

exp 100 * ( static[0] - 29 ) / ( 40 - static[0]) 

?? But if static[0] = 29, then it goes 100* 0 / 40 - 29 // Did I understood something wrong?

Thank you Sylwester

Cheers

michal123 01-26-2013 08:19

Re: How Can I calculate percentage to next rank ( based on frags) )
 
Show full code, and we will think ;)

danonix 01-26-2013 08:21

Re: How Can I calculate percentage to next rank ( based on frags) )
 
PHP Code:

public rank(param[])
{
    static 
stats[8], body[8], rankposrankmax    
    
new id param[0]
    new 
ranga[30]
    if ( 
stats[0] >= && stats[0] <= 29)
        
format(ranga,29,"Lamus")
    else if ( 
stats[0] >= 30 && stats[0] <= 59)
        
format(ranga,29,"Poczatkujacy")
    else if ( 
stats[0] >= 60 && stats[0] <= 119)
        
format(ranga,29,"Wiesniak")
    else if ( 
stats[0] >= 120 && stats[0] <= 209)
        
format(ranga,29,"Sierota")
    else if ( 
stats[0] >= 210 && stats[0] <= 324)
        
format(ranga,29,"Kox")


Thats how it looks.

Cheers

Sylwester 01-26-2013 15:28

Re: How Can I calculate percentage to next rank ( based on frags) )
 
You got it wrong again.
PHP Code:

exp 100 * ( stats[0] - 29 ) / ( 40 29 



All times are GMT -4. The time now is 20:30.

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