• Log in or sign up for an account here: https://www.sythe.org/login

New hiscores code.

Flaming Idiots

Active Member
Joined
Dec 22, 2005
Sythe Gold
0
Messages
235
Age
36
Location
Alberta Canada
New hiscores code.
Recently, Jagex released a new hiscores page made for parsing. This is a code I made to parse it, but make it easily re-usable for hiscores, skill calculators and other things.

Usage:
Code:
        '' Lookup a player
        Dim Player As New PlayerStats("Player Name")

        '' Get a specific skill information
        Dim Attack As Skill = Player(Skills.Attack)

        '' Get experience to Lvl 99 attack.
        Dim Exp As Integer = Attack.ExperienceToLevel(99)
Example with a Console application:
Code:
Module Module1

    Sub Main()
        Console.Write("Player Name: ")
        Dim Player As New PlayerStats(Console.ReadLine)
        Console.WriteLine(Player.PlayerName & "'s Combat : ~" & Player.CombatLevel)
        If Player(Skills.Attack).OnHiscores Then
            Console.WriteLine("Attack Level     :{0}", Player(Skills.Attack).Level)
            Console.WriteLine("Experience       :{0:0,0}", Player(Skills.Attack).Experience)
            Console.WriteLine("Rank             :{0:0,0}", Player(Skills.Attack).Rank)
            Console.WriteLine("Exp To Next Lvl  :{0:0,0}", Player(Skills.Attack).ExperienceToNextLevel)
        Else
            Console.WriteLine("Attack is not listed.")
        End If
        Console.ReadKey()
    End Sub

End Module
Code:
Code:
''' <summary>
''' A class which contains RuneScape account information.
''' </summary>
Public NotInheritable Class PlayerStats
    Inherits MarshalByRefObject

    Private Shared WebClient As New Net.WebClient
    Private Shared Function DownloadString(ByVal Url As String) As String
        Try
            Return WebClient.DownloadString(Url)
        Catch ex As Exception
            Return ex.Message
        End Try
    End Function

    ''' <summary>
    ''' Looks up the player and lists all skills.
    ''' </summary>
    Public Sub New(ByVal PlayerName As String)
        Me._Playername = PlayerName
        Dim Html As String = DownloadString("[URL]http://hiscore.runescape.com/index_lite.ws?player=[/URL]" & PlayerName)
        _Stats = New List(Of Skill)
        If Html.Contains("(404)") Then Return
        Dim CurrentStat As Skills = 0
        For Each Line As String In Html.Split(vbNewLine.ToCharArray, StringSplitOptions.RemoveEmptyEntries)
            If CurrentStat > Skills.Summoning Then Continue For
            Dim Skill As New Skill(CurrentStat, Line)
            If Skill.Rank <> -1 Then _Stats.Add(Skill)
            CurrentStat += 1
        Next
    End Sub

    Private _Playername As String
    ''' <summary>
    ''' The name of the player.
    ''' </summary>
    Public ReadOnly Property PlayerName() As String
        Get
            Return _Playername
        End Get
    End Property

    Private _Stats As List(Of Skill)
    ''' <summary>
    ''' A readonly collection of all the players stats.
    ''' </summary>
    Public ReadOnly Property Stats() As Collections.ObjectModel.ReadOnlyCollection(Of Skill)
        Get
            Return New Collections.ObjectModel.ReadOnlyCollection(Of Skill)(_Stats)
        End Get
    End Property

    ''' <summary>
    ''' Whether the player is listed on the hiscores or not.
    ''' </summary>
    Public ReadOnly Property IsOnHiscores() As Boolean
        Get
            Return _Stats.Count > 0
        End Get
    End Property

    ''' <summary>
    ''' Returns the skill information of the selected skill.
    ''' </summary>
    Default Public ReadOnly Property Stat(ByVal Skill As Skills) As Skill
        Get
            For Each I As Skill In _Stats
                If I.Skill = Skill Then Return I
            Next
            Return New Skill(Skill, -1, 1, 0)
        End Get
    End Property

    ''' <summary>
    ''' Returns the level of the selected skill.
    ''' </summary>
    Public ReadOnly Property Level(ByVal Skill As Skills) As Integer
        Get
            For Each I As Skill In _Stats
                If I.Skill = Skill Then Return I.Level
            Next
            If Skill = Skills.Hitpoints Then Return 10 Else Return 1
        End Get
    End Property

    ''' <summary>
    ''' Returns the rank of the selected skill.
    ''' </summary>
    Public ReadOnly Property Rank(ByVal Skill As Skills) As Integer
        Get
            For Each I As Skill In _Stats
                If I.Skill = Skill Then Return I.Level
            Next
            Return -1
        End Get
    End Property

    ''' <summary>
    ''' Returns the experience of the selected skill.
    ''' </summary>
    Public ReadOnly Property Experience(ByVal Skill As Skills) As Integer
        Get
            For Each I As Skill In _Stats
                If I.Skill = Skill Then Return I.Level
            Next
            Return 0
        End Get
    End Property

    ''' <summary>
    ''' Returns the players approximate combat level from supplied information.
    ''' </summary>
    Public ReadOnly Property CombatLevel() As Integer
        Get
            Try
                If Not IsOnHiscores Then Return 3
                Dim Base As Double = 0
                Base += (Level(Skills.Defence) + Level(Skills.Hitpoints)) * 100
                Base += (Level(Skills.Prayer) - (Level(Skills.Prayer) Mod 2)) * 50
                Base += (Level(Skills.Summoning) - (Level(Skills.Summoning) Mod 2)) * 50
                Base /= 400
                Dim MeleeClass As Double = 0
                MeleeClass += (Level(Skills.Attack) + Level(Skills.Strength)) * 130
                MeleeClass /= 400
                Dim RangeClass As Double = 0
                RangeClass += (Level(Skills.Ranged) * 195) - (Level(Skills.Ranged) Mod 2) * 65
                RangeClass /= 400
                Dim MagicClass As Double = 0
                MagicClass += (Level(Skills.Magic) * 195) - (Level(Skills.Magic) Mod 2) * 65
                MagicClass /= 400
                Dim Sort As Double() = {MeleeClass, RangeClass, MagicClass}
                Array.Sort(Sort)
                Select Case Sort(2)
                    Case MeleeClass : Return (Sort(2) + Base)
                    Case RangeClass : Return (Sort(2) + Base)
                    Case MagicClass : Return (Sort(2) + Base)
                    Case Else : Return 3
                End Select
            Catch ex As Exception
                Return 3
            End Try
        End Get
    End Property

    Public Overrides Function ToString() As String
        Dim Builder As New System.Text.StringBuilder
        Builder.AppendLine("Name = " & Me.PlayerName)
        For Each I As Skill In _Stats
Builder.AppendLine(String.Format("{0} = Lvl: {1} Exp: {2} Rank: {3}", I.Skill.ToString, I.Level, I.Experience, I.Rank))
        Next
        Return Builder.ToString.Trim(vbNewLine.ToCharArray)
    End Function

End Class

Public Class Skill

    Friend Sub New(ByVal Skill As Skills, ByVal Rank As Integer, ByVal Level As Integer, ByVal Experience As Integer)
        _Skill = Skill : _Rank = Rank : _Level = Level : _Experience = Experience
    End Sub
    Friend Sub New(ByVal Skill As Skills, ByVal Data As String)
        Dim Sl As String() = Data.Split(",")
        _Skill = Skill : _Rank = Val(Sl(0)) : _Level = Val(Sl(1)) : _Experience = Val(Sl(2))
    End Sub

    Private _Experience As Integer
    Public ReadOnly Property Experience() As Integer
        Get
            Return _Experience
        End Get
    End Property
    Private _Level As Integer
    Public ReadOnly Property Level() As Integer
        Get
            Return _Level
        End Get
    End Property
    Private _Rank As Integer
    Public ReadOnly Property Rank() As Integer
        Get
            Return _Rank
        End Get
    End Property
    Private _Skill As Skills
    Public ReadOnly Property Skill() As Skills
        Get
            Return _Skill
        End Get
    End Property
    Public ReadOnly Property ExperienceToLevel(ByVal level As SByte) As Integer
        Get
            If level <= Me.Level Then Return 0
            If level > 99 Then Return 0
            Return GetLevelExperience(level) - Experience
        End Get
    End Property
    Public ReadOnly Property ExperienceToNextLevel() As Integer
        Get
            If Level >= 99 Then Return 0
            Return GetLevelExperience(Level + 1) - Experience
        End Get
    End Property
    Public ReadOnly Property OnHiscores() As Boolean
        Get
            Return Rank <> -1
        End Get
    End Property
    Public Shared Function GetLevelExperience(ByVal Level As Integer) As Long
        Dim Output As Double = 0
        For L As Double = 1 To Level - 1
            Output += Int(L + 300 * (2 ^ (L / 7)))
        Next
        Return Math.Floor(Output / 4)
    End Function

    Public Shared Operator =(ByVal Left As Skill, ByVal Right As Skill) As Boolean
        Return (Left.Skill = Right.Skill) AndAlso (Left.Rank = Right.Experience)
    End Operator
    Public Shared Operator <>(ByVal Left As Skill, ByVal Right As Skill) As Boolean
        Return Not Left = Right
    End Operator

End Class

Public Enum Skills
    Overall
    Attack
    Defence
    Strength
    Hitpoints
    Ranged
    Prayer
    Magic
    Cooking
    Woodcutting
    Fletching
    Fishing
    Firemaking
    Crafting
    Smithing
    Mining
    Herblore
    Agility
    Thieving
    Slayer
    Farming
    Runecraft
    Construction
    Hunter
    Summoning
End Enum
 
New hiscores code.
Awesome Flaming Idiots with another success, think you could teach me how to parse :$
 
New hiscores code.
Awesome Flaming Idiots with another success, think you could teach me how to parse :$
Parsing is damn easy ;)

Assuming you know how to use

A ) A WebClient control
B ) The InStr(), Mid(), And/Or Split() function(s).

Good job. You always take a strong approach to things with Object Orientation. Excellent to say the least ;)
 
New hiscores code.
The code is great. Apart from if its a console aplication I get an error:
Index was outside the bounds of the array
on
Code:
        _Skill = Skill : _Rank = Val(Sl(0)) : _Level = Val(Sl(1)) : _Experience = Val(Sl(2))
Also I tried writing it into a form, but i'm having trouble trying to write it to datagrids and so on.
Im sure it's jsut my lack of knowledge.
 
New hiscores code.
its great, works on console now. Just really mish to try and right to datagridview. Not sure how to go about it.
 
New hiscores code.
I am new to visual basic 2008.. yeah a noob and I do not get where to place this code. Sorry about this because im a HUGE noob on this lol. Where do I put the code and what do I need? Do i put the code in a button and what things do I need on my form.... Help Apreciated.
 
New hiscores code.
You may just want to use the hiscores control I posted. It would be a lot easier that way.

If you don't want to use it, here is a code for a hiscores thing.
You will need a button called HSSearch, a TextBox named NameBox, a Panel called HSSkills, and to put the hiscores code in the first post in its own file.
Code:
    Private Sub HSSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HSSearch.Click
        Dim Player = New PlayerStats(Me.NameBox.Text)
        Me.HSSkills.Controls.Clear()
        Dim Table As New TableLayoutPanel()
        Table.ColumnCount = 4
        Table.RowCount = Player.Stats.Count + 1
        Dim CreateLabel = Function(Text As String) New Label() With {.Text = Text, .AutoSize = True, .Anchor = AnchorStyles.Left Or AnchorStyles.Top}
        Table.Controls.AddRange(New Control() {CreateLabel("Skill"), CreateLabel("Level"), CreateLabel("Experience"), CreateLabel("Rank")})
        For Each I In Player.Stats
            Table.Controls.AddRange(New Control() {CreateLabel(I.Skill.ToString), CreateLabel(I.Level), CreateLabel(I.Experience.ToString("0,0")), CreateLabel(I.Rank.ToString("0,0").TrimStart("0"c))})
        Next
        Table.ColumnStyles.Add(New ColumnStyle(SizeType.AutoSize))
        Table.ColumnStyles.Add(New ColumnStyle(SizeType.AutoSize))
        Table.ColumnStyles.Add(New ColumnStyle(SizeType.AutoSize))
        Table.ColumnStyles.Add(New ColumnStyle(SizeType.AutoSize))
        Me.HSSkills.Controls.Add(Table)
        Table.Dock = DockStyle.Fill
    End Sub
 
New hiscores code.
Parsing is damn easy ;)

Assuming you know how to use

A ) A WebClient control
B ) The InStr(), Mid(), And/Or Split() function(s).

Thanks for the help, I'm starting to understand how to parse!
 
New hiscores code.
Thank you very much
but you messed one small thing up
Replace
Code:
    Runecraft
    Construction
    Hunter
    Summoning
End Enum
with
Code:
    Runecraft
    Hunter
    Construction
    Summoning
End Enum
Although Construction came first, hunter is listed first in the new parse page.
So if you switch those around, it will fix the hunter-construction mix up.
Now, this is an awesome code, thanks alot for it!
I made a highscore lookup lol:
Code:
Public Class HS
    Private Sub TextBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Click
        If TextBox1.Text = "Username" Then
            TextBox1.Enabled = True
            TextBox1.Text = ""
        End If
    End Sub
    Public Function j()
        If TextBox1.Text = "" Or TextBox1.Text = "Username" Then
            Text = ":: Highscore Lookup :: NO USERNAME ENTERED ::"
        Else
            Dim Player As New PlayerStats(TextBox1.Text)
            Dim S1 As Skill = Player(Skills.Overall)
            Dim S2 As Skill = Player(Skills.Agility)
            Dim S3 As Skill = Player(Skills.Attack)
            Dim S4 As Skill = Player(Skills.Construction)
            Dim S5 As Skill = Player(Skills.Cooking)
            Dim S6 As Skill = Player(Skills.Crafting)
            Dim S7 As Skill = Player(Skills.Defence)
            Dim S8 As Skill = Player(Skills.Farming)
            Dim S9 As Skill = Player(Skills.Firemaking)
            Dim S10 As Skill = Player(Skills.Fishing)
            Dim S11 As Skill = Player(Skills.Fletching)
            Dim S12 As Skill = Player(Skills.Herblore)
            Dim S13 As Skill = Player(Skills.Hitpoints)
            Dim S14 As Skill = Player(Skills.Hunter)
            Dim S15 As Skill = Player(Skills.Magic)
            Dim S16 As Skill = Player(Skills.Mining)
            Dim S17 As Skill = Player(Skills.Prayer)
            Dim S18 As Skill = Player(Skills.Ranged)
            Dim S19 As Skill = Player(Skills.Runecraft)
            Dim S20 As Skill = Player(Skills.Slayer)
            Dim S21 As Skill = Player(Skills.Smithing)
            Dim S22 As Skill = Player(Skills.Strength)
            Dim S23 As Skill = Player(Skills.Summoning)
            Dim S24 As Skill = Player(Skills.Thieving)
            Dim S25 As Skill = Player(Skills.Woodcutting)
            Dim E21 As Integer = S21.Level
            Dim E22 As Integer = S22.Level
            Dim E23 As Integer = S23.Level
            Dim E24 As Integer = S24.Level
            Dim E25 As Integer = S25.Level
            Dim E20 As Integer = S20.Level
            Dim E19 As Integer = S19.Level
            Dim E18 As Integer = S18.Level
            Dim E17 As Integer = S17.Level
            Dim E16 As Integer = S16.Level
            Dim E15 As Integer = S15.Level
            Dim E14 As Integer = S14.Level
            Dim E13 As Integer = S13.Level
            Dim E12 As Integer = S12.Level
            Dim E9 As Integer = S9.Level
            Dim E10 As Integer = S10.Level
            Dim E11 As Integer = S11.Level
            Dim E8 As Integer = S8.Level
            Dim E7 As Integer = S7.Level
            Dim E6 As Integer = S6.Level
            Dim E5 As Integer = S5.Level
            Dim E4 As Integer = S4.Level
            Dim E3 As Integer = S3.Level
            Dim E1 As Integer = S1.Level
            Dim E2 As Integer = S2.Level
            Label54.Text = E2
            Label55.Text = E1
            Label53.Text = E3
            Label52.Text = E4
            Label51.Text = E5
            Label50.Text = E6
            Label49.Text = E7
            Label48.Text = E8
            Label45.Text = E11
            Label46.Text = E10
            Label47.Text = E9
            Label44.Text = E12
            Label43.Text = E13
            Label42.Text = E14
            Label41.Text = E15
            Label40.Text = E16
            Label39.Text = E17
            Label38.Text = E18
            Label37.Text = E19
            Label36.Text = E20
            Label33.Text = E23
            Label32.Text = E24
            Label31.Text = E25
            Label35.Text = E21
            Label34.Text = E22
            Dim ka1 As Integer = S1.Experience
            Dim ka2 As Integer = S2.Experience
            Dim ka3 As Integer = S3.Experience
            Dim ka4 As Integer = S4.Experience
            Dim ka5 As Integer = S5.Experience
            Dim ka6 As Integer = S6.Experience
            Dim ka7 As Integer = S7.Experience
            Dim ka8 As Integer = S8.Experience
            Dim ka9 As Integer = S9.Experience
            Dim ka10 As Integer = S10.Experience
            Dim ka11 As Integer = S11.Experience
            Dim ka12 As Integer = S12.Experience
            Dim ka13 As Integer = S13.Experience
            Dim ka14 As Integer = S14.Experience
            Dim ka15 As Integer = S15.Experience
            Dim ka16 As Integer = S16.Experience
            Dim ka17 As Integer = S17.Experience
            Dim ka18 As Integer = S18.Experience
            Dim ka19 As Integer = S19.Experience
            Dim ka20 As Integer = S20.Experience
            Dim ka21 As Integer = S21.Experience
            Dim ka22 As Integer = S22.Experience
            Dim ka23 As Integer = S23.Experience
            Dim ka24 As Integer = S24.Experience
            Dim ka25 As Integer = S25.Experience

            Dim kav1 As Integer = S1.Rank
            Dim kav2 As Integer = S2.Rank
            Dim kav3 As Integer = S3.Rank
            Dim kav4 As Integer = S4.Rank
            Dim kav5 As Integer = S5.Rank
            Dim kav6 As Integer = S6.Rank
            Dim kav7 As Integer = S7.Rank
            Dim kav8 As Integer = S8.Rank
            Dim kav9 As Integer = S9.Rank
            Dim kav10 As Integer = S10.Rank
            Dim kav11 As Integer = S11.Rank
            Dim kav12 As Integer = S12.Rank
            Dim kav13 As Integer = S13.Rank
            Dim kav14 As Integer = S14.Rank
            Dim kav15 As Integer = S15.Rank
            Dim kav16 As Integer = S16.Rank
            Dim kav17 As Integer = S17.Rank
            Dim kav18 As Integer = S18.Rank
            Dim kav19 As Integer = S19.Rank
            Dim kav20 As Integer = S20.Rank
            Dim kav21 As Integer = S21.Rank
            Dim kav22 As Integer = S22.Rank
            Dim kav23 As Integer = S23.Rank
            Dim kav24 As Integer = S24.Rank
            Dim kav25 As Integer = S25.Rank
            Label78.Text = ka2
            Label79.Text = ka1
            Label77.Text = ka3
            Label76.Text = ka4
            Label75.Text = ka5
            Label74.Text = ka6
            Label73.Text = ka7
            Label72.Text = ka8
            Label69.Text = ka11
            Label70.Text = ka10
            Label71.Text = ka9
            Label68.Text = ka12
            Label67.Text = ka13
            Label66.Text = ka14
            Label65.Text = ka15
            Label64.Text = ka16
            Label63.Text = ka17
            Label62.Text = ka18
            Label61.Text = ka19
            Label60.Text = ka20
            Label57.Text = ka23
            Label56.Text = ka24
            Label1.Text = ka25
            Label59.Text = ka21
            Label58.Text = ka22
            Label104.Text = kav1
            Label103.Text = kav2
            Label102.Text = kav3
            Label101.Text = kav4
            Label100.Text = kav5
            Label99.Text = kav6
            Label98.Text = kav7
            Label97.Text = kav8
            Label96.Text = kav9
            Label95.Text = kav10
            Label94.Text = kav11
            Label93.Text = kav12
            Label92.Text = kav13
            Label91.Text = kav14
            Label90.Text = kav15
            Label89.Text = kav16
            Label88.Text = kav17
            Label87.Text = kav18
            Label86.Text = kav19
            Label85.Text = kav20
            Label84.Text = kav21
            Label83.Text = kav22
            Label82.Text = kav23
            Label81.Text = kav24
            Label80.Text = kav25
            Text = ":: Highscore Lookup :: " + TextBox1.Text + " ::"
        End If
    End Function
    Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
        If e.KeyCode = Keys.Enter Then
            j()
        End If
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        j()
    End Sub
End Class


Insane coder, keep up the good work!
 
Runescape Gamblingrunescape gambling
Back
Top