Raised This Month: $ Target: $400
 0% 

Math problems


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 08-27-2012 , 20:11   Math problems
Reply With Quote #1

Ok.....so this was working fine up until i raised my LEVEL_INCREMENT
@ an increment of 32 it works wonderfully, but when i bring it up to a 37 it goes haywire.

I'm trying to have a level system that you can specify the points (i call frags) of the first 5 levels. then after that it gets calculated. I'm not sure what is broken but can someone take a look at it? It seems my basic math is kind of rusty.....

Here is the code that i have. Defined lvl 0-5, LEVEL_INCREMENT, and then the offset. Should be self explanatory.
PHP Code:
    // Upper boundry for level (inclusive)
    // Feel free to edit these values if you don't like the level structure
#define LVL0 5        // Regular knife  RandomFloat(15, 75
#define LVL1 25        // Brass knucks      RandomFloat(100, 150
#define LVL2 57        // Run faster
#define LVL3 100    // Jump Higher    gravity(0.55) ->set by LOW_GRAVITY define
#define LVL4 125    // Stronger hit w/ BK
#define LVL5 180    // Extra powers
#define MAXLEVEL 350    // Maximum level a player can reach (comment to disable)
#define LEVEL_INCREMENT 37    // Frags per level (after the defined levels 0-5)

    // Offset to determine how off Level 5 is from norm LEVEL_INCREMENT
    //     ********DO NOT EDIT BELOW THIS LINE!*********
const LevelOffset LVL5 - (LEVEL_INCREMENT 5)

stock getLevel(id)    // RETURNS: -1 if off or error
{
    
// returns the level of the player, based on their frags
    
if(get_pcvar_num(frags_pcvar) == || !is_user_connected(id))
        return -
1
        
    
static fragsFloat:f_calc
    frags 
gi_playerFrags[id]
    
    if(
frags <= LVL0)
        return 
0
    
else if(frags <= LVL1)
        return 
1
    
else if(frags <= LVL2)
        return 
2
    
else if(frags <= LVL3)
        return 
3
    
else if(frags <= LVL4)
        return 
4
    
else if(frags <= LVL5)
        return 
5
    
else
    {    
//LevelOffset = LVL5 - (LEVEL_INCREMENT*5)
        
f_calc =  floatdiv((frags LevelOffset), LEVEL_INCREMENT)
    
#if defined MAXLEVEL  
        
return clamp(floatround(f_calcfloatround_ceil), 0MAXLEVEL)
    
#else
        
return floatround(calcfloatround_ceil)
    
#endif 
    
}
    return -
1

I'm thinking its within the LevelOffset calculations....but i really don't know.
I know that floatround_ceil is the wrong way to go for most calculations, but it seemed to be going low even when i calculate @ LEVEL_INCREMENT 36 (what a lvl 5 would normally be)
Its just blowing my life...

Thanks in advance.
__________________
What an elegant solution to a problem that doesn't need solving....

Last edited by Liverwiz; 08-27-2012 at 20:14.
Liverwiz is offline
 



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 05:48.


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