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

(EE 2.7) Allowing Trading of Stackables and Currency.


Richy420Rich
 Share

Recommended Posts

I have done this for Ambardia but since it's probably more of a global problem for game economies, I decided to release the fix. I recommend backing up your server and client sources before attempting this. It lacks security so it's best to have some type of anti-hack prevention as well.

It's pretty simple if you just follow these steps. Let's do the Client Side changes first.

Open frmplayertrade and view it's code. In Sub Command3_Click, replace the whole Sub with this;

```
Private Sub Command3_Click()
    Dim i As Long
    Dim n As Long
    Dim GoldAmount As Long

    i = PlayerInv1.ListIndex + 1

    If GetPlayerInvItemNum(MyIndex, i) > 0 And GetPlayerInvItemNum(MyIndex, i) <= MAX_ITEMS Then
        For n = 1 To MAX_PLAYER_TRADES
            If Trading(n).InvNum = i Then
                MsgBox "You can only trade that item once!"
                Exit Sub
            End If
            If Trading(n).InvNum <= 0 Then
            If Item(GetPlayerInvItemNum(MyIndex, i)).Bound = 1 Then
            Call AddText("This item is not able to be traded, it is probably a quest item or an event item.", 12)
            Exit Sub
            End If
                If Item(GetPlayerInvItemNum(MyIndex, i)).Type = ITEM_TYPE_CURRENCY Or Item(GetPlayerInvItemNum(MyIndex, i)).Stackable = 1 Then
            GoldAmount = Val(InputBox("How much " & Trim$(Item(GetPlayerInvItemNum(MyIndex, i)).Name) & "(" & GetPlayerInvItemValue(MyIndex, i) & ") would you like to trade?", "Trade " & Trim$(Item(GetPlayerInvItemNum(MyIndex, i)).Name), "", frmPlayerTrade.Left, frmPlayerTrade.Top))
            If IsNumeric(GoldAmount) Then
            If Int(GoldAmount) > Int(GetPlayerInvItemValue(MyIndex, i)) Then
            Call AddText("You don't have that amount to trade!", BRIGHTRED)
            Exit Sub
            End If
                        PlayerInv1.List(i - 1) = PlayerInv1.Text & " **"
                        Items1.List(n - 1) = n & ": " & Trim$(Item(GetPlayerInvItemNum(MyIndex, i)).Name) & " / " & GoldAmount & ""
                        Trading(n).InvNum = i
                        Trading(n).InvName = "" & Trim$(Item(GetPlayerInvItemNum(MyIndex, i)).Name) & ""
                        Trading(n).InvVal = "" & Int(GoldAmount) & ""
                Call SendData("updatetradeinv" & SEP_CHAR & n & SEP_CHAR & Trading(n).InvNum & SEP_CHAR & Trading(n).InvName & SEP_CHAR & GoldAmount & END_CHAR)
            Exit Sub
            Else
            Exit Sub
            End If
                Else
                    If GetPlayerWeaponSlot(MyIndex) = i Or GetPlayerArmorSlot(MyIndex) = i Or GetPlayerHelmetSlot(MyIndex) = i Or GetPlayerShieldSlot(MyIndex) = i Or GetPlayerLegsSlot(MyIndex) = i Or GetPlayerRingSlot(MyIndex) = i Or GetPlayerNecklaceSlot(MyIndex) = i Then
                        MsgBox "Cant trade worn items!"
                        Exit Sub
                    Else
                        PlayerInv1.List(i - 1) = PlayerInv1.Text & " **"
                        Items1.List(n - 1) = n & ": " & Trim$(Item(GetPlayerInvItemNum(MyIndex, i)).Name)
                        Trading(n).InvNum = i
                        Trading(n).InvName = Trim$(Item(GetPlayerInvItemNum(MyIndex, i)).Name)
                        Call SendData("updatetradeinv" & SEP_CHAR & n & SEP_CHAR & Trading(n).InvNum & SEP_CHAR & Trading(n).InvName & SEP_CHAR & 0 & END_CHAR)
                        Exit Sub
                    End If
                End If
            End If
        Next n
    End If
End Sub

```
While in frmPlayerTrade, look for Command4_Click and replace it with this;

```
Private Sub Command4_Click()
    Dim i As Long, n As Long
    i = Items1.ListIndex + 1

    If Trading(i).InvNum <= 0 Then
        MsgBox "No item to remove!"
        Exit Sub
    End If

    PlayerInv1.List(Trading(i).InvNum - 1) = Mid$(Trim$(PlayerInv1.List(Trading(i).InvNum - 1)), 1, Len(PlayerInv1.List(Trading(i).InvNum - 1)) - 3)
    Items1.List(i - 1) = n & ": "
    Trading(i).InvNum = 0
    Trading(i).InvName = vbNullString
    Trading(i).InvVal = 0
    Call SendData("updatetradeinv" & SEP_CHAR & i & SEP_CHAR & 0 & SEP_CHAR & vbNullString & SEP_CHAR & 0 & END_CHAR)
    Command1.ForeColor = &H80000012
End Sub

```
Now go to modTypes, look for;

```
Type PlayerTradeRec
    InvNum As Long
    InvName As String
End Type
```
Replace this with;

```
Type PlayerTradeRec
    InvNum As Long
    InvName As String
    InvVal As Long
End Type
```
Now go to modhandledata, look for;
```
    If casestring = "updatetradeitem" Then

```
Replace the whole code with;

```
    ' ::::::::::::::::::::::::::::::
    ' :: Stop trading with player ::
    ' ::::::::::::::::::::::::::::::
    If casestring = "updatetradeitem" Then
        n = Val(parse(1))

        Trading2(n).InvNum = Val(parse(2))
        Trading2(n).InvName = parse(3)
        Trading2(n).InvVal = Val(parse(4))

        If Trading2(n).InvNum <= 0 Then
            frmPlayerTrade.Items2.List(n - 1) = n & ": "
Exit Sub
End If

If Item(Trading2(n).InvNum).Type = ITEM_TYPE_CURRENCY Or Item(Trading2(n).InvNum).Stackable = 1 Then
          frmPlayerTrade.Items2.List(n - 1) = n & ": " & Trim$(Trading2(n).InvName) & " / " & Int(Trading2(n).InvVal) & ""
Else
          frmPlayerTrade.Items2.List(n - 1) = n & ": " & Trim$(Trading2(n).InvName) & ""
End If
Exit Sub
        End If

```

While still in modhandledata. Look for;

```
If casestring = "pptrading" Then

```
Replace the whole code with;

```
    If casestring = "pptrading" Then
        frmPlayerTrade.Items1.Clear
        frmPlayerTrade.Items2.Clear
        For i = 1 To MAX_PLAYER_TRADES
            Trading(i).InvNum = 0
            Trading(i).InvName = vbNullString
            Trading(i).InvVal = 0
            Trading2(i).InvNum = 0
            Trading2(i).InvName = vbNullString
            Trading2(i).InvVal = 0
            frmPlayerTrade.Items1.addItem i & ": "
            frmPlayerTrade.Items2.addItem i & ": "
        Next i

        frmPlayerTrade.Items1.ListIndex = 0

        Call UpdateTradeInventory
        frmPlayerTrade.Show vbModeless, frmMirage
        Exit Sub
    End If

```
While still in modhandledata, Right under that last code should be;

```
If casestring = "qtrade" Then
```
Replace that whole code with this;

```
    If casestring = "qtrade" Then
        For i = 1 To MAX_PLAYER_TRADES
            Trading(i).InvNum = 0
            Trading(i).InvName = vbNullString
            Trading(i).InvVal = 0
            Trading2(i).InvNum = 0
            Trading2(i).InvName = vbNullString
            Trading2(i).InvVal = 0
        Next i

        frmPlayerTrade.Command1.ForeColor = &H0&
        frmPlayerTrade.Command2.ForeColor = &H0&

        frmPlayerTrade.Visible = False
        Exit Sub
    End If

```
Now we go to the Server, first go into modhandledata and look for;

```
Case "updatetradeinv"
```
Replace that whole case with this;

```
        Case "updatetradeinv"
            Call Packet_UpdateTradeInventory(index, Val(Parse(1)), Val(Parse(2)), Parse(3), Val(Parse(4)))
            Exit Sub

```
Now scroll down into modhandledata, look for;

```
Packet_UpdateTradeInventory
```
Remove it and replace it with this;

```
Public Sub Packet_UpdateTradeInventory(ByVal index As Long, ByVal TradeIndex As Long, ByVal ItemNum As Long, ByVal ItemName As String, ByVal ItemValue As Long)
    Player(index).Trading(TradeIndex).InvNum = ItemNum
    Player(index).Trading(TradeIndex).InvName = Trim$(ItemName)
    Player(index).Trading(TradeIndex).InvVal = ItemValue

    If Player(index).Trading(TradeIndex).InvNum = 0 Then
        Player(index).TradeItemMax = Player(index).TradeItemMax - 1
        Player(index).TradeOk = 0
        Player(TradeIndex).TradeOk = 0

        Call SendDataTo(index, "trading" & SEP_CHAR & 0 & END_CHAR)
        Call SendDataTo(TradeIndex, "trading" & SEP_CHAR & 0 & END_CHAR)
    Else
        Player(index).TradeItemMax = Player(index).TradeItemMax + 1
    End If

    If Player(index).Trading(TradeIndex).InvNum > 0 Then
    Call SendDataTo(Player(index).TradePlayer, "updatetradeitem" & SEP_CHAR & TradeIndex & SEP_CHAR & Player(index).Trading(TradeIndex).InvNum & SEP_CHAR & Player(index).Trading(TradeIndex).InvName & SEP_CHAR & Player(index).Trading(TradeIndex).InvVal & END_CHAR)
    Else
    Call SendDataTo(Player(index).TradePlayer, "updatetradeitem" & SEP_CHAR & TradeIndex & SEP_CHAR & 0 & SEP_CHAR & vbNullString & SEP_CHAR & 0 & END_CHAR)
End If
End Sub

```
While still in modhandledata, look for;

```
Sub Packet_AcceptTrade
```
Replace that whole code with this;

```
Public Sub Packet_AcceptTrade(ByVal index As Long)
    Dim PlayerIndex As Long
    Dim I As Long

    PlayerIndex = Player(index).TradePlayer

    If PlayerIndex = 0 Then
        Call PlayerMsg(index, "You have not requested to trade with anyone.", PINK)
        Exit Sub
    End If

    If Player(PlayerIndex).TradePlayer <> index Then
        Call PlayerMsg(index, "Trade failed.", PINK)
        Exit Sub
    End If

    If GetPlayerMap(index) <> GetPlayerMap(PlayerIndex) Then
        Call PlayerMsg(index, "You must be on the same map to trade with " & GetPlayerName(PlayerIndex) & "!", PINK)
        Exit Sub
    End If

    Call PlayerMsg(index, "You are trading with " & GetPlayerName(PlayerIndex) & "!", PINK)
    Call PlayerMsg(PlayerIndex, GetPlayerName(index) & " accepted your trade request!", PINK)

    Call SendDataTo(index, "PPTRADING" & END_CHAR)
    Call SendDataTo(PlayerIndex, "PPTRADING" & END_CHAR)

    For I = 1 To MAX_PLAYER_TRADES
        Player(index).Trading(I).InvNum = 0
        Player(index).Trading(I).InvName = vbNullString
        Player(index).Trading(I).InvVal = 0

        Player(PlayerIndex).Trading(I).InvNum = 0
        Player(PlayerIndex).Trading(I).InvName = vbNullString
        Player(PlayerIndex).Trading(I).InvVal = 0
    Next I

    Player(index).InTrade = True
    Player(index).TradeItemMax = 0
    Player(index).TradeItemMax2 = 0

    Player(PlayerIndex).InTrade = True
    Player(PlayerIndex).TradeItemMax = 0
    Player(PlayerIndex).TradeItemMax2 = 0
End Sub
```
Still in modhandledata, look for;

```
Sub Packet_SwapItems
```
Remove the code and replace it with this;

```
Public Sub Packet_SwapItems(ByVal index As Long)
    Dim TradeIndex As Long
    Dim I As Long
    Dim X As Long
    TradeIndex = Player(index).TradePlayer

    If Player(index).TradeOk = 0 Then
        Player(index).TradeOk = 1
        Call SendDataTo(TradeIndex, "trading" & SEP_CHAR & 1 & END_CHAR)
    ElseIf Player(index).TradeOk = 1 Then
        Player(index).TradeOk = 0
        Call SendDataTo(TradeIndex, "trading" & SEP_CHAR & 0 & END_CHAR)
    End If

    If Player(index).TradeOk = 1 Then
        If Player(TradeIndex).TradeOk = 1 Then
            Player(index).TradeItemMax2 = 0
            Player(TradeIndex).TradeItemMax2 = 0

            For I = 1 To MAX_INV
                If Player(index).TradeItemMax = Player(index).TradeItemMax2 Then
                    Exit For
                End If

                If GetPlayerInvItemNum(TradeIndex, I) < 1 Then
                    Player(index).TradeItemMax2 = Player(index).TradeItemMax2 + 1
                End If
            Next I

            For I = 1 To MAX_INV
                If Player(TradeIndex).TradeItemMax = Player(TradeIndex).TradeItemMax2 Then
                    Exit For
                End If

                If GetPlayerInvItemNum(index, I) < 1 Then
                    Player(TradeIndex).TradeItemMax2 = Player(TradeIndex).TradeItemMax2 + 1
                End If
            Next I

            If Player(index).TradeItemMax2 = Player(index).TradeItemMax And Player(TradeIndex).TradeItemMax2 = Player(TradeIndex).TradeItemMax Then
                For I = 1 To MAX_PLAYER_TRADES
                    For X = 1 To MAX_INV
                        If GetPlayerInvItemNum(TradeIndex, X) < 1 Then
                            If Player(index).Trading(I).InvNum > 0 Then
                            If Item(GetPlayerInvItemNum(index, Player(index).Trading(I).InvNum)).Type = ITEM_TYPE_CURRENCY Or Item(GetPlayerInvItemNum(index, Player(index).Trading(I).InvNum)).Stackable = 1 Then
                            Call GiveItem(TradeIndex, GetPlayerInvItemNum(index, Player(index).Trading(I).InvNum), Player(index).Trading(I).InvVal)
                            Call TakeItem(index, GetPlayerInvItemNum(index, Player(index).Trading(I).InvNum), Player(index).Trading(I).InvVal)
                            Exit For
                            Else
                                Call GiveItem(TradeIndex, GetPlayerInvItemNum(index, Player(index).Trading(I).InvNum), 0)
                                Call TakeItem(index, GetPlayerInvItemNum(index, Player(index).Trading(I).InvNum), 0)
                                Exit For
                                End If
                            End If
                        End If
                    Next X
                Next I

                For I = 1 To MAX_PLAYER_TRADES
                    For X = 1 To MAX_INV
                        If GetPlayerInvItemNum(index, X) < 1 Then
                            If Player(TradeIndex).Trading(I).InvNum > 0 Then
                            If Item(GetPlayerInvItemNum(TradeIndex, Player(TradeIndex).Trading(I).InvNum)).Type = ITEM_TYPE_CURRENCY Or Item(GetPlayerInvItemNum(TradeIndex, Player(TradeIndex).Trading(I).InvNum)).Stackable = 1 Then
                            Call GiveItem(index, GetPlayerInvItemNum(TradeIndex, Player(TradeIndex).Trading(I).InvNum), Player(TradeIndex).Trading(I).InvVal)
                            Call TakeItem(TradeIndex, GetPlayerInvItemNum(TradeIndex, Player(TradeIndex).Trading(I).InvNum), Player(TradeIndex).Trading(I).InvVal)
                            Exit For
                            Else
                                Call GiveItem(index, GetPlayerInvItemNum(TradeIndex, Player(TradeIndex).Trading(I).InvNum), 0)
                                Call TakeItem(TradeIndex, GetPlayerInvItemNum(TradeIndex, Player(TradeIndex).Trading(I).InvNum), 0)
                                Exit For
                                End If
                        End If
                        End If
                    Next X
                Next I

                Call PlayerMsg(index, "The trade was successful!", BRIGHTGREEN)
                Call PlayerMsg(TradeIndex, "The trade was successful!", BRIGHTGREEN)

                Call SendInventory(index)
                Call SendInventory(TradeIndex)
            Else
                If Player(index).TradeItemMax2 < Player(index).TradeItemMax Then
                    Call PlayerMsg(index, "Your inventory is full!", BRIGHTRED)
                    Call PlayerMsg(TradeIndex, GetPlayerName(index) & "'s inventory is full!", BRIGHTRED)
                End If

                If Player(TradeIndex).TradeItemMax2 < Player(TradeIndex).TradeItemMax Then
                    Call PlayerMsg(TradeIndex, "Your inventory is full!", BRIGHTRED)
                    Call PlayerMsg(index, GetPlayerName(TradeIndex) & "'s inventory is full!", BRIGHTRED)
                End If
            End If

            Player(index).TradePlayer = 0
            Player(index).InTrade = False
            Player(index).TradeOk = 0

            Player(TradeIndex).TradePlayer = 0
            Player(TradeIndex).InTrade = False
            Player(TradeIndex).TradeOk = 0

            Call SendDataTo(index, "qtrade" & END_CHAR)
            Call SendDataTo(TradeIndex, "qtrade" & END_CHAR)
        End If
    End If
End Sub
```
Now go to modTypes, look for;

```
Type PlayerTradeRec
    InvNum As Long
    InvName As String
End Type
```
Replace this with;

```
Type PlayerTradeRec
    InvNum As Long
    InvName As String
    InvVal As Long
End Type
```
I think this about covers it all up. With it all done correctly, you should beable to now trade currency and stackables. Credits aren't needed as I posted this for eclipse.

EDIT: I'm sorry I forgot to fix the chat messages as Ambardia has 2 seperate chat boxes lol. This is fixed now, and should work.

EDIT: Give_Currency commands has been changed to GiveItem commands sorry lol.

EDIT: This is the most updated code with all the fixes added.
Link to comment
Share on other sites

  • 2 weeks later...
I'm not sure whether you had created the sub 'Give_Currency' or not, But i was unable to find it. I've also downloaded a fresh EE2.7 and it was not there either…

EDIT: I've supplemented the sub with Sub 'GiveItem' for now, it works fine. Nice work
Link to comment
Share on other sites

  • 2 weeks later...
This works great, thanks! There are a couple of things I'm worried about, though:

-When you offer an unstackable item, it's displays it fine on your screen, but for the other trader, you would see it with a value of 0\. Example: The item is a Sword. I offer it, and it says "Sword." For the other person, it would be displayed as "Sword (0)."

-When you remove an item in the trade, the other trader still sees it there, even though it was removed. Example: I offer the Sword and remove it. For me, it doesn't show it, but for the other trader, he/she will still see "Sword (0)" as an offered item.

Do you think you can help me with these?
Link to comment
Share on other sites

To fix the 0 Value of the item showing, in the Client , modHandleData, look for;

```
If casestring = "updatetradeitem" Then

```
Replace it with this;

```
    If casestring = "updatetradeitem" Then
        n = Val(parse(1))

        Trading2(n).InvNum = Val(parse(2))
        Trading2(n).InvName = parse(3)
        Trading2(n).InvVal = Val(parse(4))

        If STR(Trading2(n).InvNum) <= 0 Then
            frmPlayerTrade.Items2.List(n - 1) = n & ": "
        Else
If Item(Trading2(n).InvNum).Type = ITEM_TYPE_CURRENCY Or Item(Trading2(n).InvNum).Stackable = 1 Then
          frmPlayerTrade.Items2.List(n - 1) = n & ": " & Trim$(Trading2(n).InvName) & " / " & Int(Trading2(n).InvVal) & ""
Else
          frmPlayerTrade.Items2.List(n - 1) = n & ": " & Trim$(Trading2(n).InvName) & ""
End If
        End If
        Exit Sub
    End If

```
Hm thanks for pointing that remove bug out to me.. Not hard to fix though.

In the Server / modHandleData, look for Packet_UpdateTradeInventory

Replace that code with this;

```
Public Sub Packet_UpdateTradeInventory(ByVal index As Long, ByVal TradeIndex As Long, ByVal ItemNum As Long, ByVal ItemName As String, ByVal ItemValue As Long)
    Player(index).Trading(TradeIndex).InvNum = ItemNum
    Player(index).Trading(TradeIndex).InvName = Trim$(ItemName)
    Player(index).Trading(TradeIndex).InvVal = ItemValue

    If Player(index).Trading(TradeIndex).InvNum = 0 Then
        Player(index).TradeItemMax = Player(index).TradeItemMax - 1
        Player(index).TradeOk = 0
        Player(TradeIndex).TradeOk = 0

        Call SendDataTo(index, "trading" & SEP_CHAR & 0 & END_CHAR)
        Call SendDataTo(TradeIndex, "trading" & SEP_CHAR & 0 & END_CHAR)
    Else
        Player(index).TradeItemMax = Player(index).TradeItemMax + 1
    End If

    If Player(index).Trading(TradeIndex).InvNum > 0 Then
    Call SendDataTo(Player(index).TradePlayer, "updatetradeitem" & SEP_CHAR & TradeIndex & SEP_CHAR & Player(index).Trading(TradeIndex).InvNum & SEP_CHAR & Player(index).Trading(TradeIndex).InvName & SEP_CHAR & Player(index).Trading(TradeIndex).InvVal & END_CHAR)
    Else
    Call SendDataTo(Player(index).TradePlayer, "updatetradeitem" & SEP_CHAR & TradeIndex & SEP_CHAR & 0 & SEP_CHAR & vbNullString & SEP_CHAR & 0 & END_CHAR)
End If
End Sub

```
I haven't tested these codes so make a backup of your sources before placing these in. Hopefully it works but I haven't got the time to test them right now.
Link to comment
Share on other sites

Ok in your Client , frmPlayerTrade, open the code and look for Command4_Click
remove and replace that with this;

```
Private Sub Command4_Click()
    Dim i As Long, n As Long
    i = Items1.ListIndex + 1

    If Trading(i).InvNum <= 0 Then
        MsgBox "No item to remove!"
        Exit Sub
    End If

    PlayerInv1.List(Trading(i).InvNum - 1) = Mid$(Trim$(PlayerInv1.List(Trading(i).InvNum - 1)), 1, Len(PlayerInv1.List(Trading(i).InvNum - 1)) - 3)
    Items1.List(i - 1) = n & ": "
    Trading(i).InvNum = 0
    Trading(i).InvName = vbNullString
    Trading(i).InvVal = 0
    Call SendData("updatetradeinv" & SEP_CHAR & i & SEP_CHAR & 0 & SEP_CHAR & vbNullString & SEP_CHAR & 0 & END_CHAR)
    Command1.ForeColor = &H80000012
End Sub

```
Then in your Client , modhandledata, look again for casestring = "updatetradeitem"
Replace that whole code with this;

```
    ' ::::::::::::::::::::::::::::::
    ' :: Stop trading with player ::
    ' ::::::::::::::::::::::::::::::
    If casestring = "updatetradeitem" Then
        n = Val(parse(1))

        Trading2(n).InvNum = Val(parse(2))
        Trading2(n).InvName = parse(3)
        Trading2(n).InvVal = Val(parse(4))

        If Trading2(n).InvNum <= 0 Then
            frmPlayerTrade.Items2.List(n - 1) = n & ": "
Exit Sub
End If

If Item(Trading2(n).InvNum).Type = ITEM_TYPE_CURRENCY Or Item(Trading2(n).InvNum).Stackable = 1 Then
          frmPlayerTrade.Items2.List(n - 1) = n & ": " & Trim$(Trading2(n).InvName) & " / " & Int(Trading2(n).InvVal) & ""
Else
          frmPlayerTrade.Items2.List(n - 1) = n & ": " & Trim$(Trading2(n).InvName) & ""
End If
Exit Sub
        End If

```
That should fix it. Sorry I was a bit pre-occupied with some other stuff.

EDIT: Whole code in original post has been edited to fix all these bugs. Thanks.
Link to comment
Share on other sites

  • 3 weeks later...

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...