Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Server Loop Help
#1
Ok, I'm not quite sure how to do this. I know what I WANT to do, I just haven't figured out how. So I'm trying to make a code in the server loop that every 10 seconds looks at all the players online, and updates a stat I created for them. I'm working on a fishing system, and I'm coding it up one piece at a time, to get all the error straight before hand.

[spoiler]So I found this in the ServerLoop
Code:
If Tick > LastUpdatePlayerVitals Then
            UpdatePlayerVitals
            LastUpdatePlayerVitals = GetTickCount + 5000
        End If

And added under it

Code:
If Tick > LastUpdatePlayerFishing Then
            UpdatePlayerFishing
            LastUpdatePlayerFishing = GetTickCount + 10000
        End If

This, code, Like the updateplayervitals, runs every so often. After that I added a sub down near the bottom

Code:
Private Sub UpdatePlayerFishing()
Dim i As Long, fishness As Byte

    For i = 1 To MAX_PLAYERS
        If IsPlaying(i) Then
            fishness = Int(GetPlayerStat(index, Stats.canfish))
                If fishness >= 1 then
                      Call SetPlayerStat(index, Stats.canfish, GetPlayerStat(index, Stats.canfish) - fishness)
                Else
                End If
        End If
    Next i
End Sub

I got an run time error 9, subscript out of range, upon hitting that 10 second mark on the code
Code:
Public Function GetPlayerStat(ByVal index As Long, ByVal Stat As Stats) As Long
    GetPlayerStat = Player(index).Char(TempPlayer(index).CharNum).Stat(Stat)
End Function

I'm figuring this has something to do with the specific player index, but I can't think of a way to make this work. Can anyone help out? Thank you.[/spoiler]
Reply
#2
First thing i see is
Code:
fishness As Byte

Why is that a byte when GetPlayerStat returns a long?

Code:
fishness = Int(GetPlayerStat(index, Stats.canfish))
Where are you getting this 'index' from?

Code:
Call SetPlayerStat(index, Stats.canfish, GetPlayerStat(index, Stats.canfish) - fishness)
index again?
Reply
#3
I'm not sure about the index, I was trying to find a way to do it, and as far as I can tell, the code throughout the server side always pops up similar to
Code:
Int(GetPlayerStat(Index, Stats.defense)

I tried removing the index (forget the error code I got for that), and i tried putting in I instead of index (not sure why I tried that, some stupid part of my mind slipped out when I tried that one I guess). I figured the error involved the index.

I got the second part of the code
Code:
Call SetPlayerStat(index, Stats.canfish, GetPlayerStat(index, Stats.canfish) - fishness)
from the stat update part of the server, and it worked when I created another sub that was called when a player used an item. I try to understand everything I add, but alot of it I do not understand, I just know what works and what doesn't work.

Edit*** I got it working. It may have been a problem with dimming it as a byte (I'm not sure) but the final working code was

Code:
Private Sub UpdatePlayerFishing()
Dim i As Long, fishness As Long

    For i = 1 To MAX_PLAYERS
        If IsPlaying(i) Then
        fishness = GetPlayerStat(i, Stats.canfish)
            If fishness >= 1 Then
                Call SetPlayerStat(i, Stats.canfish, GetPlayerStat(i, Stats.canfish) - fishness)
            Else
            End If
        End If
    Next i
End Sub

Thanks for your help Dugor.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)