Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Trading error subscript out of range?


Justin Knight
 Share

Recommended Posts

I'm getting a subscript out of range error in handletradeitem. Does anyone have any idea why?
The error is at "TempPlayer(TempPlayer(index).InTrade).AcceptTrade = False" I have it pointed out in the code below. The index =6, Intrade=0, but acceptTrade is out of range.

```
Sub HandleTradeItem(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)

   Dim Buffer As clsBuffer
   Dim invSlot As Long
   Dim amount As Long
   Dim EmptySlot As Long
   Dim itemnum As Long
   Dim i As Long

   Set Buffer = New clsBuffer
   Buffer.WriteBytes Data()

   invSlot = Buffer.ReadLong
   amount = Buffer.ReadLong

   Set Buffer = Nothing

   If invSlot <= 0 Or invSlot > MAX_INV Then Exit Sub

   itemnum = GetPlayerInvItemNum(index, invSlot)
   If itemnum <= 0 Or itemnum > MAX_ITEMS Then Exit Sub

   ' make sure they have the amount they offer
   If amount < 0 Or amount > GetPlayerInvItemValue(index, invSlot) Then
       Exit Sub
   End If

   If Item(itemnum).Type = ITEM_TYPE_CURRENCY Then
       ' check if already offering same currency item
       For i = 1 To MAX_INV
           If TempPlayer(index).TradeOffer(i).Num = invSlot Then
               ' add amount
               TempPlayer(index).TradeOffer(i).Value = TempPlayer(index).TradeOffer(i).Value + amount
               ' clamp to limits
               If TempPlayer(index).TradeOffer(i).Value > GetPlayerInvItemValue(index, invSlot) Then
                   TempPlayer(index).TradeOffer(i).Value = GetPlayerInvItemValue(index, invSlot)
               End If
               ' cancel any trade agreement
               TempPlayer(index).AcceptTrade = False
               TempPlayer(TempPlayer(index).InTrade).AcceptTrade = False

               SendTradeStatus index, 0
               SendTradeStatus TempPlayer(index).InTrade, 0

               SendTradeUpdate index, 0
               SendTradeUpdate TempPlayer(index).InTrade, 1
               ' exit early
               Exit Sub
           End If
       Next
   Else
       ' make sure they're not already offering it
       For i = 1 To MAX_INV
           If TempPlayer(index).TradeOffer(i).Num = invSlot Then
               PlayerMsg index, "You've already offered this item.", BrightRed
               Exit Sub
           End If
       Next
   End If

   ' not already offering - find earliest empty slot
   For i = 1 To MAX_INV
       If TempPlayer(index).TradeOffer(i).Num = 0 Then
           EmptySlot = i
           Exit For
       End If
   Next
   TempPlayer(index).TradeOffer(EmptySlot).Num = invSlot
   TempPlayer(index).TradeOffer(EmptySlot).Value = amount

   ' cancel any trade agreement and send new data
   TempPlayer(index).AcceptTrade = False
   'trade error
   >>>>>>>>>>>>>>>>>>>TempPlayer(TempPlayer(index).InTrade).AcceptTrade = False<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

   SendTradeStatus index, 0
   SendTradeStatus TempPlayer(index).InTrade, 0

   SendTradeUpdate index, 0
   SendTradeUpdate TempPlayer(index).InTrade, 1
End Sub
```
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...