Richy420Rich Posted May 22, 2009 Author Share Posted May 22, 2009 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 IfEnd 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 = &H80000012End Sub ```Now go to modTypes, look for;```Type PlayerTradeRec InvNum As Long InvName As StringEnd Type```Replace this with;```Type PlayerTradeRec InvNum As Long InvName As String InvVal As LongEnd 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 SubEnd 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 IfExit 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 IfEnd 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 = 0End 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 IfEnd Sub```Now go to modTypes, look for;```Type PlayerTradeRec InvNum As Long InvName As StringEnd Type```Replace this with;```Type PlayerTradeRec InvNum As Long InvName As String InvVal As LongEnd 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 More sharing options...
tiggilyboo Posted June 3, 2009 Share Posted June 3, 2009 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 More sharing options...
Richy420Rich Posted June 3, 2009 Author Share Posted June 3, 2009 Actually I forgot. Give_Currency I believe came from one of Barons Superscripts, I hardcoded mostly all of the subs that were in Ambardia's main.txt, but yes, GiveItem should be what it is here. Thanks. Link to comment Share on other sites More sharing options...
Kimimaru Posted June 13, 2009 Share Posted June 13, 2009 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 More sharing options...
Richy420Rich Posted June 13, 2009 Author Share Posted June 13, 2009 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_UpdateTradeInventoryReplace 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 IfEnd 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 More sharing options...
Kimimaru Posted June 14, 2009 Share Posted June 14, 2009 Thanks! The 0 value of the item showing worked, but the other one didn't. Link to comment Share on other sites More sharing options...
Kimimaru Posted June 16, 2009 Share Posted June 16, 2009 Do you think you can fix the remove bug, please? Link to comment Share on other sites More sharing options...
Richy420Rich Posted June 16, 2009 Author Share Posted June 16, 2009 Ok in your Client , frmPlayerTrade, open the code and look for Command4_Clickremove 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 = &H80000012End 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 SubEnd 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 IfExit 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 More sharing options...
Kimimaru Posted June 16, 2009 Share Posted June 16, 2009 No problem, and thank you very much! It works perfectly now! Link to comment Share on other sites More sharing options...
marlongb Posted July 1, 2009 Share Posted July 1, 2009 Still contains an error, when you return a negative number, you get the money from another player.Example:Trade -1 Currency Link to comment Share on other sites More sharing options...
Glapus93 Posted July 8, 2009 Share Posted July 8, 2009 Man, It is not working on ED 2.0 :( Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now