AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Math problems (https://forums.alliedmods.net/showthread.php?t=194387)

Liverwiz 08-27-2012 20:11

Math problems
 
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.

fysiks 08-27-2012 20:51

Re: Math problems
 
When LEVEL_INCREMENT is 32 then LevelOffset is positive. When LEVEL_INCREMENT is 37 then LevelOffset is negative. However, LevelOffset doesn't make any sense to me (my brain started to hurt when trying to figure it out lol).

This is how I would expect something like this to work based on this comment:

PHP Code:

#define LEVEL_INCREMENT 37    // Frags per level (after the defined levels 0-5) 

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)

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
    {
#if defined MAXLEVEL
        
return clamp((frags LVL5)/LEVEL_INCREMENT 60MAXLEVEL)
#else
        
return (frags LVL5)/LEVEL_INCREMENT 6
#endif
    
}
    return -
1



Liverwiz 08-27-2012 21:04

Re: Math problems
 
The LevelOffset was supposed to pretty much be an easy way for the - LEVEL5 and + 6 in the calculations. But i guess it was just me being stupid.....

Yeah....that makes more sense, guess i was stuck on that one idea.

Will test and report back. (not that i expect issues)
Thanks.


All times are GMT -4. The time now is 05:48.

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