Jump to content

Python OSRS Combat Level Function


Recommended Posts

I have a nice spaghetti code program I did as a project for my Linux class.

The main code is a bash script.

I'm using perl to check if the player name is valid (not really important).

I'm using bash to get the osrs hiscores.

I'm using awk to put the combat stats into a file.

I'm using python to read the combat stats file and calculate the combat level.
Then this information gets passed to other python functions to calculate what rank I should assign my clanmates.

import math

def combat_level(stats):
    #1.	Take your Prayer level and divide it by two and round down 
    base = math.trunc(stats[5]/2)
    #2.	Add this to your Hitpoints and Defence levels and divide the result by 4.
    base = (base+stats[3]+stats[1])/4
    #3. Add your Strength and Attack levels together and multiply by 0.325.
    melee = (stats[2]+stats[0])*0.325
    #Add this to your base combat level and you should have your melee combat level.
    #4.	If your Magic or Ranged level is exceptionally higher than your Attack and Strength,
    #carry on - in the calculation noted below Magic is used, 
    #but if your Ranged is exceptionally higher, use that instead in all cases
    higher = stats[6]
    if (higher < stats[4]):
        higher = stats[4]
    if (higher > stats[0]+14 and higher > stats[2]+14):
    #5. Divide your Magic level by 2 and round down, and then add your Magic level again to this 
        magic = math.trunc(higher/2)+higher
    #6. Multiply this by 0.325 and add the result to your base combat level calculated above, 
    #and you should have your magic combat level
        magic = magic*0.325
        return math.trunc(base+magic)
         return math.trunc(base+melee)


stats = []
    f = open("osrs/temp")
    for line in f:
        line = line.rstrip("\n")


Anyway, I just wanted to ask if anyone knows what the wiki means by

"If your Magic or Ranged level is exceptionally higher than your Attack and Strength"?

I just did +14, but I'm not sure if this is correct.


Link to comment
Share on other sites

It's not as simple as +14 I think it's closer to if magic or range is higher than str+atk combined


Not 100% sure if HP is calculated along with Def either. Remember the splash mage pures that had 99 magic and 10hp? They were only like mid 20s if memory serves




Anyone who likes tacos is incapable of logic.

Anyone who likes logic is incapable of tacos.


PSA: SaqPrets is an Estonian Dude

Steam: NippleBeardTM

Origin: Brand_New_iPwn

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.