Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Shop Items in stock...
#16
I can't seem to edit shops now either. I get a RTE 9 on
Code:
GetItem = CLng(Parse(n + 2))

In HandleEditShop

Heres my edit shop:
Code:
' ::::::::::::::::::::::
' :: Edit shop packet ::
' ::::::::::::::::::::::
Sub HandleEditShop(ByRef Parse() As String)
Dim n As Long
Dim i As Long
Dim ShopNum As Long
Dim GiveItem As Long
Dim GiveValue As Long
Dim GetItem As Long
Dim GetValue As Long
Dim Stocked As Long
Dim Increase As Long
Dim Decrease As Long

     ShopNum = CLng(Parse(1))
    
     ' Update the shop
     Shop(ShopNum).Name = Parse(2)
     Shop(ShopNum).JoinSay = Parse(3)
     Shop(ShopNum).LeaveSay = Parse(4)
     Shop(ShopNum).FixesItems = CByte(Parse(5))
    
     n = 6
     For i = 1 To MAX_TRADES
        
         GiveItem = CLng(Parse(n))
         GiveValue = CLng(Parse(n + 1))
         GetItem = CLng(Parse(n + 2))
         GetValue = CLng(Parse(n + 3))
         Stocked = CLng(Parse(n + 4))
        
         Shop(ShopNum).TradeItem(i).GiveItem = GiveItem
         Shop(ShopNum).TradeItem(i).GiveValue = GiveValue
         Shop(ShopNum).TradeItem(i).GetItem = GetItem
         Shop(ShopNum).TradeItem(i).GetValue = GetValue
         Shop(ShopNum).TradeItem(i).Stocked = Stocked
         Shop(ShopNum).TradeItem(i).DemandIncrease = Increase
         Shop(ShopNum).TradeItem(i).DemandDecrease = Decrease
        
         n = n + 5
     Next
    
     ' Initialize the shop editor
     Call ShopEditorInit
    
End Sub

Code:
Public Sub SendSaveShop(ByVal ShopNum As Long)
Dim Packet As String
Dim i As Long

    With Shop(ShopNum)
        Packet = CSaveShop & SEP_CHAR & ShopNum & SEP_CHAR & Trim$(.Name) & SEP_CHAR & Trim$(.JoinSay) & SEP_CHAR & Trim$(.LeaveSay) & SEP_CHAR & .FixesItems
    End With
    
    For i = 1 To MAX_TRADES
        With Shop(ShopNum).TradeItem(i)
            Packet = Packet & SEP_CHAR & .GiveItem & SEP_CHAR & .GiveValue & SEP_CHAR & .GetItem & SEP_CHAR & .GetValue & SEP_CHAR & .Stocked & SEP_CHAR & .DemandIncrease & SEP_CHAR & .DemandDecrease
        End With
    Next
    
    Packet = Packet & END_CHAR
    Call SendData(Packet)
End Sub

Code:
' ::::::::::::::::::
' :: Trade packet ::
' ::::::::::::::::::
Sub HandleTrade(ByRef Parse() As String)
Dim n As Long
Dim i As Long
Dim ShopNum As Long
Dim GiveItem As Long
Dim GiveValue As Long
Dim GetItem As Long
Dim GetValue As Long
Dim Stocked As Long
Dim Increase As Long
Dim Decrease As Long

     ShopNum = CLng(Parse(1))
    
     If CByte(Parse(2)) = 1 Then
         frmTrade.lblFixItem.Visible = True
     Else
         frmTrade.lblFixItem.Visible = False
     End If
    
     n = 3
    
     For i = 1 To MAX_TRADES
         GiveItem = CLng(Parse(n))
         GiveValue = CLng(Parse(n + 1))
         GetItem = CLng(Parse(n + 2))
         GetValue = CLng(Parse(n + 3))
         Stocked = CLng(Parse(n + 4))
         Increase = CLng(Parse(n + 5))
         Decrease = CLng(Parse(n + 6))
        
         If GiveItem > 0 Then
             If GetItem > 0 Then
                 frmTrade.lstTrade.AddItem "Give " & Trim$(Shop(ShopNum).Name) & " " & GiveValue & " " & Trim$(Item(GiveItem).Name) & " for " & Trim$(Item(GetItem).Name & "(" & Stocked & ")")
             End If
         End If
         n = n + 7
     Next
    
     If frmTrade.lstTrade.ListCount > 0 Then
         frmTrade.lstTrade.ListIndex = 0
     End If
     frmTrade.Show vbModal
End Sub

Server

Code:
' ::::::::::::::::::::::
' :: Save shop packet ::
' ::::::::::::::::::::::
Sub HandleSaveShop(ByVal Index As Long, ByRef Parse() As String)
Dim ShopNum As Long
Dim N As Long
Dim i As Long

    ' Prevent hacking
    If GetPlayerAccess(Index) < ADMIN_DEVELOPER Then
        Call HackingAttempt(Index, "Admin Cloning")
        Exit Sub
    End If
    
    ShopNum = CLng(Parse(1))
    
    ' Prevent hacking
    If ShopNum < 0 Or ShopNum > MAX_SHOPS Then
        Call HackingAttempt(Index, "Invalid Shop Index")
        Exit Sub
    End If
    
    ' Update the shop
    Shop(ShopNum).Name = Parse(2)
    Shop(ShopNum).JoinSay = Parse(3)
    Shop(ShopNum).LeaveSay = Parse(4)
    Shop(ShopNum).FixesItems = CByte(Parse(5))
    
    N = 6
    For i = 1 To MAX_TRADES
        Shop(ShopNum).TradeItem(i).GiveItem = CLng(Parse(N))
        Shop(ShopNum).TradeItem(i).GiveValue = CLng(Parse(N + 1))
        Shop(ShopNum).TradeItem(i).GetItem = CLng(Parse(N + 2))
        Shop(ShopNum).TradeItem(i).GetValue = CLng(Parse(N + 3))
        Shop(ShopNum).TradeItem(i).Stocked = CLng(Parse(N + 4))
        Shop(ShopNum).TradeItem(i).DemandIncrease = CLng(Parse(N + 5))
        Shop(ShopNum).TradeItem(i).DemandDecrease = CLng(Parse(N + 6))
        
        N = N + 7
    Next
    
    ' Save it
    Call SendUpdateShopToAll(ShopNum)
    Call SaveShop(ShopNum)
    Call AddLog(GetPlayerName(Index) & " saving shop #" & ShopNum & ".", ADMIN_LOG)
End Sub

Code:
' ::::::::::::::::::::::::::
' :: Trade request packet ::
' ::::::::::::::::::::::::::
Sub HandleTradeRequest(ByVal Index As Long, _
                       ByRef Parse() As String)
    Dim N As Long
    Dim i As Long
    Dim x As Long
    Dim z As Long
    ' Trade num
    N = CLng(Parse(1))
  
    ' Prevent hacking
    If (N  MAX_TRADES) Then
        Call HackingAttempt(Index, "Trade Request Modification")
        Exit Sub
    End If
  
    ' Index for shop
    i = Map(GetPlayerMap(Index)).Shop
  
    ' Check if inv full
    x = FindOpenInvSlot(Index, Shop(i).TradeItem(N).GetItem)
  
    'If the Demand Increase and Decrease = 0 Then the stock = 10
    '(This is so that, an item that hasn't ever been bought, will be in stock)
    If Shop(i).TradeItem(N).DemandIncrease = 0 And Shop(i).TradeItem(N).DemandDecrease = 0 Then
        Shop(i).TradeItem(N).Stocked = 10
    End If
  
    If x = 0 Then
        Call PlayerMsg(Index, "Trade unsuccessful, inventory full.", BrightRed)
        Exit Sub
    End If

    'Check to see if they have on in stock
    If Shop(i).TradeItem(N).Stocked > 0 Then

        ' Check if they have the item
        If HasItem(Index, Shop(i).TradeItem(N).GiveItem) >= Shop(i).TradeItem(N).GiveValue Then
            Call TakeItem(Index, Shop(i).TradeItem(N).GiveItem, Shop(i).TradeItem(N).GiveValue)
            Call GiveItem(Index, Shop(i).TradeItem(N).GetItem, Shop(i).TradeItem(N).GetValue)
            Call PlayerMsg(Index, "The trade was successful!", Yellow)
            'Minus one from stock
            Shop(i).TradeItem(N).Stocked = Shop(i).TradeItem(N).Stocked - 1
            'Add moar demand
            Shop(i).TradeItem(N).DemandIncrease = Shop(i).TradeItem(N).DemandIncrease + 0.1
          
'            Select Case Shop(i).TradeItem(N).DemandIncrease
'
'                Case 1
'
'                    Shop(i).TradeItem(N).Stocked = Shop(i).TradeItem(N).Stocked + 5
'
'                Case 5
'                    Shop(i).TradeItem(N).Stocked = Shop(i).TradeItem(N).Stocked + 10
'
'                Case 10
'                    Shop(i).TradeItem(N).Stocked = Shop(i).TradeItem(N).Stocked + 20
'            End Select
'
'            'It's in high demand, lets give a stock increase of five.
'            'If Shop(i).TradeItem(n).DemandIncrease > 1 Then
'            '    'Add five more to the current stock
'            '    Shop(i).TradeItem(n).Stocked = Shop(i).TradeItem(n).Stocked + 5
'            'End If
'            Select Case Shop(i).TradeItem(N).DemandDecrease
'
'                Case 1
'
'                    Shop(i).TradeItem(N).Stocked = Shop(i).TradeItem(N).Stocked - 5
'
'                Case 5
'                    Shop(i).TradeItem(N).Stocked = Shop(i).TradeItem(N).Stocked - 10
'
'                Case 10
'                    Shop(i).TradeItem(N).Stocked = Shop(i).TradeItem(N).Stocked = 0
'            End Select

            'No one buys it, why keep a high stock?
            'If Shop(i).TradeItem(n).DemandDecrease >= 1 Then
            '    Shop(i).TradeItem(n).Stocked = Shop(i).TradeItem(n).Stocked - 5
            'End If

        Else
            Call PlayerMsg(Index, "Trade unsuccessful.", BrightRed)
        End If

    Else
        Call PlayerMsg(Index, "This item is not in stock, at the moment!", BrightRed)
    End If

End Sub

Code:
Private Sub UpdateShopStocks()
    Dim i As Long
    Dim N As Long

    For i = 1 To MAX_SHOPS
        For N = 1 To 8

            'Handle what to do if the demand increases
            Select Case Shop(i).TradeItem(N).DemandIncrease
          
                Case 1
                    'add the stock by five.
                    Shop(i).TradeItem(N).Stocked = Shop(i).TradeItem(N).Stocked + 5
              
                Case 5
                    'add the stock by ten.
                    Shop(i).TradeItem(N).Stocked = Shop(i).TradeItem(N).Stocked + 10
                  
                Case 10
                    'add the stock by twenty
                    Shop(i).TradeItem(N).Stocked = Shop(i).TradeItem(N).Stocked + 20
            End Select
          
            'It's in high demand, lets give a stock increase of five.
            'If Shop(i).TradeItem(n).DemandIncrease > 1 Then
            '    'Add five more to the current stock
            '    Shop(i).TradeItem(n).Stocked = Shop(i).TradeItem(n).Stocked + 5
            'End If
          
            'Handle what to do if the demand decreases
            Select Case Shop(i).TradeItem(N).DemandDecrease
          
                Case 1
                    'minus the stock by five.
                    Shop(i).TradeItem(N).Stocked = Shop(i).TradeItem(N).Stocked - 5
              
                Case 5
                    'minus the stock by 10
                    Shop(i).TradeItem(N).Stocked = Shop(i).TradeItem(N).Stocked - 10

                Case 10
                    'NO stock at all
                    Shop(i).TradeItem(N).Stocked = Shop(i).TradeItem(N).Stocked = 0
            End Select

            'No one buys it, why keep a high stock?
            'If Shop(i).TradeItem(n).DemandDecrease >= 1 Then
            '    Shop(i).TradeItem(n).Stocked = Shop(i).TradeItem(n).Stocked - 5
            'End If
        Next
    Next

End Sub

Code:
If Tick > LastUpdateShopStocks Then
            UpdateShopStocks
            LastUpdateShopStocks = GetTickCount + 600000
        End If
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)