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

[EO] Trade State


Helladen
 Share

Recommended Posts

This is a modification of the Auto-Accept Trade Tutorial. Basically this fixes a few bugs, gets rid of the form button which is replaced with /trade, and converts the settings server side instead of it being until you log out.

I modified the quote.

@RavenStar:

> Hi all, I'm new here and thought I'd kick it off with a tutorial.
> This is my first tutorial I've ever written and I've only been using EO for 2 days now, so don't be too harsh with me  :rolleyes:
>
> This tutorial will alter the trade system currently in EO. Instead of having to accept a trade, you simply enable trade then anyone can open the trade window with you. Once the trade is over, it disables trade. I reckon this makes trading easier, where if there's a heap of players around, you don't need to find the one that wants to trade and then accept.
>
> **CLIENT SIDE**
>
> In modInput, find this;
> ```
>               Case "/who"
>                     SendWhosOnline
> ```Below it add this;
> ```
>                 Case "/trade"
>                     SendTradeState
> ```
> In modEnumerations, inside of Public Enum ClientPackets, find this;
> ```
>     CDeclineTrade
>     CTradeItem
>     CUntradeItem
> ```
> Add this below it;
> ```
> CTradeState
> ```
> In modClientTCP, add this to the very bottom;
> ```
> 'RavenStar
> Public Sub SendTradeState()
>     Dim Buffer As clsBuffer
>     Set Buffer = New clsBuffer
>     Buffer.WriteLong CTradeState
>     SendData Buffer.ToArray()
>     Set Buffer = Nothing
> End Sub
> ```
> That's it for the client side, now for the server side!
>
> **SERVER SIDE**
>
> In modEnumerations, inside of Public Enum ClientPackets, find this;
> ```
>     CDeclineTrade
>     CTradeItem
>     CUntradeItem
> ```
> Add this below it;
> ```
> CTradeState
> ```
> In modHandleData, inside of Public Sub InitMessages(), find this;
> ```
> HandleDataSub(CUntradeItem) = GetAddress(AddressOf HandleUntradeItem)
> ```
> Add this below it;
> ```
> HandleDataSub(CTradeState) = GetAddress(AddressOf HandleTradeState)
> ```
> At the bottom of modHandleData, add this;
> ```
> Sub HandleTradeState(ByVal Index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)
>    
>     If GetVar(App.Path & "\data\accounts\tradestate.ini", GetPlayerName(Index), "AllowTrade") = "" Then
>         Call PutVar(App.Path & "\data\accounts\tradestate.ini", GetPlayerName(Index), "AllowTrade", "1")
>     End If
>    
>     If GetVar(App.Path & "\data\accounts\tradestate.ini", GetPlayerName(Index), "AllowTrade") = "0" Then
>         Call PlayerMsg(Index, "Other players are now able to trade with you.", BrightGreen)
>         Call PutVar(App.Path & "\data\accounts\tradestate.ini", GetPlayerName(Index), "AllowTrade", "1")
>     Else
>         Call PlayerMsg(Index, "Other players are now unable to trade with you.", BrightGreen)
>         Call PutVar(App.Path & "\data\accounts\tradestate.ini", GetPlayerName(Index), "AllowTrade", "0")
>     End If
>    
> End Sub
> ```
> In modHandleData, find Sub HandleTradeRequest, replace the entire sub with this;
> ```
> Sub HandleTradeRequest(ByVal Index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)
>     Dim buffer As clsBuffer
>     Dim x As Long
>     Dim y As Long
>     Dim I As Long
>     Dim tradeTarget As Long
>  
>     Set buffer = New clsBuffer
>     buffer.WriteBytes Data()
>  
>     x = buffer.ReadLong
>     y = buffer.ReadLong
>  
>     Set buffer = Nothing
>  
>     ' Prevent subscript out of range
>     If x < 0 Or x > Map(GetPlayerMap(Index)).MaxX Or y < 0 Or y > Map(GetPlayerMap(Index)).MaxY Then Exit Sub
>
>     ' Check for a player
>     For I = 1 To MAX_PLAYERS
>         If IsPlaying(I) Then
>             If GetPlayerMap(Index) = GetPlayerMap(I) Then
>                 If GetPlayerX(I) = x Then
>                     If GetPlayerY(I) = y Then
>                         tradeTarget = I
>                     End If
>                 End If
>             End If
>         End If
>     Next
>  
>     ' Make sure we don't error
>     If tradeTarget <= 0 Or tradeTarget > MAX_PLAYERS Then Exit Sub
>  
>     ' Can't trade with yourself..
>     If tradeTarget = Index Then
>         PlayerMsg Index, "You can't trade with yourself.", BrightRed
>         Exit Sub
>     End If
>
>     If GetVar(App.Path & "\Data\accounts\tradestate.ini", GetPlayerName(Index), "AllowTrade") = "" Then
>         Call PutVar(App.Path & "\Data\accounts\tradestate.ini", GetPlayerName(Index), "AllowTrade", "1")
>     End If
>  
>     If GetVar(App.Path & "\Data\accounts\tradestate.ini", GetPlayerName(tradeTarget), "AllowTrade") = "1" Then
>         ' clear the trade timeout clientside
>         SendClearTradeTimer Index
>         ' clear the tradeRequest server-side
>         TempPlayer(Index).TradeRequest = 0
>         TempPlayer(tradeTarget).TradeRequest = 0
>         ' set that they're trading with each other
>         TempPlayer(Index).InTrade = tradeTarget
>         TempPlayer(tradeTarget).InTrade = Index
>         ' clear out their trade offers
>         For I = 1 To MAX_INV
>             TempPlayer(Index).TradeOffer(I).Num = 0
>             TempPlayer(Index).TradeOffer(I).Value = 0
>             TempPlayer(tradeTarget).TradeOffer(I).Num = 0
>             TempPlayer(tradeTarget).TradeOffer(I).Value = 0
>         Next
>         ' Used to init the trade window clientside
>         SendTrade Index, tradeTarget
>         SendTrade tradeTarget, Index
>         ' Send the offer data - Used to clear their client
>         SendTradeUpdate Index, 0
>         SendTradeUpdate Index, 1
>         SendTradeUpdate tradeTarget, 0
>         SendTradeUpdate tradeTarget, 1
>      
>         Exit Sub
>     Else
>         PlayerMsg Index, Trim$(GetPlayerName(tradeTarget)) & " is not accepting trades.", BrightRed
>     End If
>     SendClearTradeTimer Index
> End Sub
> ```
> All done! :)
>
> Now, if you want to trade with someone, they have to have their trade status enabled by pressing the label we made earlier. Once it's on, you can hit trade, click their character and the trade window will instantly open. You'll have to enable your trade before anyone else can initiate a trade with you.
> Once a trade has started, both players trade status is disabled, for safety measures :)
>
> There's probably a few parts that could do with some optimization but if you care about that then you can do it.
>
> Let me know how it goes, would be good to know if anyone ends up using this.  :azn:
Link to comment
Share on other sites

I did that but if you use different accounts, it would be more accurate. For example, if I store it on the account I have to send the client information to the server and so on. Much more work. Using a regular config file to check is so bad to do. This works fine.
Link to comment
Share on other sites

  • 3 weeks later...
@Helladen:

> I did that but if you use different accounts, it would be more accurate. For example, if I store it on the account I have to send the client information to the server and so on. Much more work. Using a regular config file to check is so bad to do. This works fine.

Bullshit.
Link to comment
Share on other sites

I personally have about 10 client configurations I added Robin. I don't need anymore, especially for a Trade State.

It takes about 3 seconds to add them so variables are fine to work with. I just didn't want to write a packet to check the option on the client.
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...