Raised This Month: $ Target: $400
 0% 

How Can I calculate percentage to next rank ( based on frags) )


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
danonix
Senior Member
Join Date: Dec 2012
Old 01-26-2013 , 04:35   How Can I calculate percentage to next rank ( based on frags) )
Reply With Quote #1

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)
    
}

Last edited by danonix; 01-26-2013 at 04:35.
danonix is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 01-26-2013 , 04:44   Re: How Can I calculate percentage to next rank ( based on frags) )
Reply With Quote #2

PHP Code:
percent 100 * ( your_total_frags current_rank_frags ) / ( next_rank_frags current_rank_frags 
__________________
Impossible is Nothing

Last edited by Sylwester; 01-26-2013 at 04:45.
Sylwester is offline
danonix
Senior Member
Join Date: Dec 2012
Old 01-26-2013 , 04:55   Re: How Can I calculate percentage to next rank ( based on frags) )
Reply With Quote #3

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); 

Last edited by danonix; 01-26-2013 at 04:56.
danonix is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 01-26-2013 , 06:06   Re: How Can I calculate percentage to next rank ( based on frags) )
Reply With Quote #4

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)
__________________
Impossible is Nothing

Last edited by Sylwester; 01-26-2013 at 06:08.
Sylwester is offline
danonix
Senior Member
Join Date: Dec 2012
Old 01-26-2013 , 08:07   Re: How Can I calculate percentage to next rank ( based on frags) )
Reply With Quote #5

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

Last edited by danonix; 01-26-2013 at 08:35.
danonix is offline
michal123
Junior Member
Join Date: Feb 2011
Location: Poland
Old 01-26-2013 , 08:19   Re: How Can I calculate percentage to next rank ( based on frags) )
Reply With Quote #6

Show full code, and we will think ;)
michal123 is offline
danonix
Senior Member
Join Date: Dec 2012
Old 01-26-2013 , 08:21   Re: How Can I calculate percentage to next rank ( based on frags) )
Reply With Quote #7

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

Last edited by danonix; 01-26-2013 at 08:31.
danonix is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 01-26-2013 , 15:28   Re: How Can I calculate percentage to next rank ( based on frags) )
Reply With Quote #8

You got it wrong again.
PHP Code:
exp 100 * ( stats[0] - 29 ) / ( 40 29 
__________________
Impossible is Nothing
Sylwester is offline
Reply


Thread Tools
Display Modes

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 20:30.


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