Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Shop Items in stock...
#1
I've been screwing around for about thirty minutes, and this is what I managed. I haven't gotten to test it, but can you guy see anything that needs to be added/taken from it?

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
            
            '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
            
            '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
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)