Mirage Source

Free ORPG making software.
It is currently Tue Jun 04, 2024 10:26 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Server Loop Help
PostPosted: Fri Oct 24, 2008 11:49 am 
Offline
Regular

Joined: Wed Jan 16, 2008 8:50 pm
Posts: 60
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: (click to show)
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.


Top
 Profile  
 
 Post subject: Re: Server Loop Help
PostPosted: Fri Oct 24, 2008 1:56 pm 
Offline
Pro
User avatar

Joined: Tue Nov 13, 2007 2:42 pm
Posts: 509
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?


Top
 Profile  
 
 Post subject: Re: Server Loop Help
PostPosted: Fri Oct 24, 2008 2:08 pm 
Offline
Regular

Joined: Wed Jan 16, 2008 8:50 pm
Posts: 60
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group