Skip to content
View in the app

A better way to browse. Learn more.

Tip.It Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Python OSRS Combat Level Function

Featured Replies

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)
    else:
         return math.trunc(base+melee)

...

stats = []
try:
    f = open("osrs/temp")
    for line in f:
        line = line.rstrip("\n")
        stats.append(int(line))
finally:
    f.close()
combat=combat_level(stats)

...

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.

 

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

Quote

 

Quote

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

  • 6 years later...
  • Author

I forgot I had posted this, but here is the updated cmb.py if anyone wants to build something like this:

#!/usr/bin/python3

import math

def combat_level(stats):
    #1.	Take your Prayer level and divide it by two and round down
    base = math.floor(stats[6]/2)
    #2.	Add this to your Hitpoints and Defence levels and divide the result by 4.
    base = (base+stats[4]+stats[2])/4
    #3. Add your Strength and Attack levels together and multiply by 0.325.
    #Add this to your base combat level and you should have your melee combat level.
    melee = (stats[3]+stats[1])*0.325
    range = (math.floor(3*stats[5]/2))*0.325
    magic = (math.floor(3*stats[7]/2))*0.325
    #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
    highest = melee
    if (highest < range):
        highest = range
    if (highest < magic):
        highest = magic
    #5. Divide your Magic level by 2 and round down, and then add your Magic level again to this
    #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
    return math.floor(base+highest)

def print_result(cmb):
    with open("osrs/temp", "a") as myfile:
        myfile.write(str(cmb)+"\n")

#Get Stats
stats = []
try:
    f = open("osrs/temp")
    for line in f:
        line = line.rstrip("\n")
        stats.append(int(line))
finally:
    f.close()
combat=combat_level(stats)
print_result(combat)

 

Create an account or sign in to comment

Important Information

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.