Combat formula change error

I wanted to change my combat formula to be the exact same as Runescape 2s combat formula. It gives me RTE 9 subscript out of range though. Any idea what i might be doing wrong? Any feedback is appreciated. Thank you very much.

Edit: This error happens when i hit somebody. Both with and without weapon equipped.

RTE 9 means exactly what it says. A value is outside of its range. When the error happens, hover over each value and see which one is causing the RTE.

I know what could be causing the error. If the player doesn’t have a weapon, the WeaponNum is 0 which is outside the range of the Item types (1 to MAX_ITEMS)

That is exactly what is causing the error here. Could you paste that piece of code into a code tag so we can correct it?

RTE 9 means exactly what it says. A value is outside of its range. When the error happens, hover over each value and see which one is causing the RTE.

I know what could be causing the error. If the player doesn’t have a weapon, the WeaponNum is 0 which is outside the range of the Item types (1 to MAX_ITEMS)

This happens both when i have a weapon on and not.

That is exactly what is causing the error here. Could you paste that piece of code into a code tag so we can correct it?

Sure  😛

Function GetPlayerDamage(ByVal index As Long) As Long
    Dim WeaponNum As Long

    ' Check for subscript out of range
    If IsPlaying(index) = False Or index < 1 Or index > Player_HighIndex Then Exit Function

    If GetPlayerEquipment(index, Equipment.Weapon) > 0 Then
        If Not GetPlayerEquipmentDur(index, GetPlayerEquipment(index, Equipment.Weapon)) = 0 Or Item(GetPlayerEquipment(index, Equipment.Weapon)).Indestructable = 1 Then
            WeaponNum = GetPlayerEquipment(index, Equipment.Weapon)
            GetPlayerDamage = 1
            'Max = 5 + STRLVL * (STRBONUS + 64) / 64
            '* Item(WeaponNum).Data2
            Exit Function
        End If
    End If

     GetPlayerDamage = 5 + (GetPlayerStat(index, Strength) * (Item(WeaponNum).Data2 + 64) / 64)
End Function

The last line before End Function is the highlighted one.

The returning statement is dependant on the WeaponNum being bigger than 0. Change it to this.


Function GetPlayerDamage(ByVal index As Long) As Long
    Dim WeaponNum As Long

    ' Check for subscript out of range
    If IsPlaying(index) = False Or index < 1 Or index > Player_HighIndex Then Exit Function

    If GetPlayerEquipment(index, Equipment.Weapon) > 0 Then
        If Not GetPlayerEquipmentDur(index, GetPlayerEquipment(index, Equipment.Weapon)) = 0 Or Item(GetPlayerEquipment(index, Equipment.Weapon)).Indestructable = 1 Then
            WeaponNum = GetPlayerEquipment(index, Equipment.Weapon)
            GetPlayerDamage = 5 + (GetPlayerStat(index, Strength) * (Item(WeaponNum).Data2 + 64) / 64)
            ' GetPlayerDamage = 1 No idea why this is here.
            'Max = 5 + STRLVL * (STRBONUS + 64) / 64
            '* Item(WeaponNum).Data2
            Exit Function
        End If
    End If

     GetPlayerDamage = 5 + (GetPlayerStat(index, Strength) / 64)
End Function

The returning statement is dependant on the WeaponNum being bigger than 0. Change it to this.


Function GetPlayerDamage(ByVal index As Long) As Long
    Dim WeaponNum As Long
    
    ' Check for subscript out of range
    If IsPlaying(index) = False Or index < 1 Or index > Player_HighIndex Then Exit Function
    
    If GetPlayerEquipment(index, Equipment.Weapon) > 0 Then
        If Not GetPlayerEquipmentDur(index, GetPlayerEquipment(index, Equipment.Weapon)) = 0 Or Item(GetPlayerEquipment(index, Equipment.Weapon)).Indestructable = 1 Then
            WeaponNum = GetPlayerEquipment(index, Equipment.Weapon)
            GetPlayerDamage = 5 + (GetPlayerStat(index, Strength) * (Item(WeaponNum).Data2 + 64) / 64)
            ' GetPlayerDamage = 1 No idea why this is here.
            'Max = 5 + STRLVL * (STRBONUS + 64) / 64
            '* Item(WeaponNum).Data2
            Exit Function
        End If
    End If
    
     GetPlayerDamage = 5 + (GetPlayerStat(index, Strength) / 64)
End Function

Item.WeaponNum.Data

is that the Vital number set on the weapon in the equipment editor? If not, what is the code to make it set to multiply by weapon vital?

Log in to reply