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

Exp & money packet


Dawntide
 Share

Recommended Posts

hey,

I need your help, i want to create 2 packets, which let me give the player exp and money or take it from him.

Due to the new forum, the only packet tutorial is gone, so i depend on you!

Here is my try on give player money/currency:

client side:

```

Public Sub GiveCurrency(ByVal invslot As Long)

Dim Buffer As clsBuffer

' If debug mode, handle error then exit out

If Options.Debug = 1 Then On Error GoTo errorhandler

Set Buffer = New clsBuffer

Buffer.WriteLong CGiveCurrency

Buffer.WriteLong invslot

SendData Buffer.ToArray()

Set Buffer = Nothing

' Error handler

Exit Sub

errorhandler:

HandleError "GiveCurrency", "modClientTCP", Err.Number, Err.Description, Err.Source, Err.HelpContext

Err.Clear

Exit Sub

End Sub

```

server side:

```

Sub HandleGiveCurrency(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)

Dim Buffer As clsBuffer

Dim invSlot As Long

Dim itemnum As Long

Dim Amount As Long

Set Buffer = New clsBuffer

Buffer.WriteBytes Data()

invSlot = Buffer.ReadLong

' give gold

GiveInvItem index, 1, Amount

' send confirmation message

PlayerMsg index, "You received" & Amount & "gold.", BrightGreen

Set Buffer = Nothing

End Sub

```

Please fix my errors AND explain me what to do and why i need to do it.

thanks in advance!
Link to comment
Share on other sites

Get the server to send a unique ID to the player when the minigame starts, then retain it server side.. If the game completes sent the unique ID along with the packet, and compare them. If they match, hand out the gold. If they don't, kick the user from the server for trying to cheat.
Link to comment
Share on other sites

Not really. Just send the ID along with your minigame open packet. ![:P](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/tongue.png)

Then when it's done, return it and send it back(Also don't forget to add your packet IDs to modEnumerations). :]
Link to comment
Share on other sites

**Client to Server packets**

First, let's look into modEnumerations, and head for the one where every item starts with a C. This list determines what packets the client can send in a readable format, and allows the client and server to recognize which one is which, this is why this list needs to be indentical on both the client and server.

For the sake of simplicity here, I'll use an existing one:

```
CSayMsg
```

Now that it's defined in this list, we can use it in to write a packet with.. So let's go into modClientTCP and write the sub that sends the data, which in this case would be:

```
Public Sub SayMsg(ByVal text As String)

Dim Buffer As clsBuffer

' If debug mode, handle error then exit out

If Options.Debug = 1 Then On Error GoTo errorhandler

Set Buffer = New clsBuffer

Buffer.WriteLong CSayMsg

Buffer.WriteString text

SendData Buffer.ToArray()

Set Buffer = Nothing

' Error handler

Exit Sub

errorhandler:

HandleError "SayMsg", "modClientTCP", Err.Number, Err.Description, Err.Source, Err.HelpContext

Err.Clear

Exit Sub

End Sub
```

We call that when we want it sent, of course and send ONLY the data we absolutely need(the Buffer.writeXXXX stuff after the first Buffer.Writelong, this one ALWAYS needs to be the packet ID we added above).

Now that we're done there, we can head into the server source and go into modHandleData, sub InitMessages, and we write a line such as this:

```
HandleDataSub(CSayMsg) = GetAddress(AddressOf HandleSayMsg)
```

This tells the server to forward anything that is received with that packet ID to the sub with the name of the bit we wrote in GetAddress(). That means we need to add the actual sub we are calling there, which is the following right here:

```
Private Sub HandleSayMsg(ByVal Index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)

Dim Msg As String

Dim i As Long

Dim Buffer As clsBuffer

Set Buffer = New clsBuffer

Buffer.WriteBytes Data()

Msg = Buffer.ReadString

' Prevent hacking

For i = 1 To Len(Msg)

' limit the ASCII

If AscW(Mid$(Msg, i, 1)) < 32 Or AscW(Mid$(Msg, i, 1)) > 126 Then

' limit the extended ASCII

If AscW(Mid$(Msg, i, 1)) < 128 Or AscW(Mid$(Msg, i, 1)) > 168 Then

' limit the extended ASCII

If AscW(Mid$(Msg, i, 1)) < 224 Or AscW(Mid$(Msg, i, 1)) > 253 Then

Mid$(Msg, i, 1) = ""

End If

End If

End If

Next

Call TextAdd("Map #" & GetPlayerMap(Index) & ": " & GetPlayerName(Index) & " says, '" & Msg & "'", ChatMap)

Call SayMsg_Map(GetPlayerMap(Index), Index, Msg, QBColor(White))

Call SendChatBubble(GetPlayerMap(Index), Index, targetPlayer, Msg, White)

Set Buffer = Nothing

End Sub
```

And that should do it for sending the data, what you do with it really depends on what you're sending, I just wrote this here as a quick existing example. The same goes for back to the CLient, except this time we use the Enumeration list that starts with all S's.
Link to comment
Share on other sites

I tested it.

When the player wins the minigame, in the chat appears this text:

you received0 gold.

and in my inventory i got the icon of the currency but no amount, i can not drop it either. its just there.

Here is what i did:

client side:

```

Public Sub GiveCurrency(ByVal Amount As Long)

Dim Buffer As clsBuffer

' If debug mode, handle error then exit out

If Options.Debug = 1 Then On Error GoTo errorhandler

Set Buffer = New clsBuffer

Buffer.WriteLong CGiveCurrency

Buffer.WriteLong Amount

SendData Buffer.ToArray()

Set Buffer = Nothing

' Error handler

Exit Sub

errorhandler:

HandleError "GiveCurrency", "modClientTCP", Err.Number, Err.Description, Err.Source, Err.HelpContext

Err.Clear

Exit Sub

End Sub

```

modEnumerations:

```

CGiveCurrency

```

Minigame player wins:

```

lblResult = "You Won"

Call GiveCurrency(50)

```

server side:

modHandleData

```

HandleDataSub(CGiveCurrency) = GetAddress(AddressOf HandleGiveCurrency)

```

```

Sub HandleGiveCurrency(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)

Dim buffer As clsBuffer

Dim itemnum As Long

Dim amount As Long

Set buffer = New clsBuffer

buffer.WriteBytes Data()

' give gold

GiveInvItem index, 1, amount

' send confirmation message

PlayerMsg index, "You received" & amount & " gold.", BrightGreen

Set buffer = Nothing

End Sub

```

modEnumerations:

```

CGiveCurrency

```

Whats wrong?
Link to comment
Share on other sites

```

Sub HandleGiveCurrency(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)

Dim buffer As clsBuffer

Dim itemnum As Long

Dim amount As Long

Set buffer = New clsBuffer

buffer.WriteBytes Data()

amount = Buffer.ReadLong ' <-- make sure you actually READ the variable '

' give gold '

GiveInvItem index, 1, amount

' send confirmation message '

PlayerMsg index, "You received" & amount & " gold.", BrightGreen

Set buffer = Nothing

End Sub
```

**Edit:** sorry, this new forum doesn't alert on new replies.
Link to comment
Share on other sites

love you guys (no homo ![:D](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/biggrin.png))! You helped me understand this a little bit more, thanks.

What is the deal with the disappeared tutorial? I got the old one in my bookmarks, the thread was named: "[EO] (hopefully) simple packet tutorial"

How to handle the same exact thing with experience? I mean what to use instead of "giveinvitem"?

thanks!
Link to comment
Share on other sites

> love you guys (no homo ![:D](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/biggrin.png))! You helped me understand this a little bit more, thanks.
>
> What is the deal with the disappeared tutorial? I got the old one in my bookmarks, the thread was named: "[EO] (hopefully) simple packet tutorial"
>
> How to handle the same exact thing with experience? I mean what to use instead of "giveinvitem"?
>
> thanks!

I thought that tutorial was great too. [Luckily the new search is pretty awesome.](http://www.touchofdeathforums.com/community/index.php?/topic/115981-eo-hopefully-simple-packet-tutorial/) ![;)](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/wink.png)
Link to comment
Share on other sites

Yeah saw it, but i do not know how to use it.

```

Public Sub CheckCurrency(ByVal itemamount As Long)

Dim Buffer As clsBuffer

' If debug mode, handle error then exit out

If Options.Debug = 1 Then On Error GoTo errorhandler

Set Buffer = New clsBuffer

Buffer.WriteLong CCheckCurrency

Buffer.WriteLong itemamount

SendData Buffer.ToArray()

Set Buffer = Nothing

' Error handler

Exit Sub

errorhandler:

HandleError "CheckCurrency", "modClientTCP", Err.Number, Err.Description, Err.Source, Err.HelpContext

Err.Clear

Exit Sub

End Sub

```

```

Sub HandleCheckCurrency(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)

Dim Buffer As clsBuffer

Dim itemamount As Long

Set Buffer = New clsBuffer

Buffer.WriteBytes Data()

itemamount = Buffer.ReadLong

' check gold

itemamount = HasItem(index, 1)

If itemamount < 50 Then

PlayerMsg index, "Not enough gold.", BrightRed

Exit Sub

End If

Set Buffer = Nothing

End Sub

```

It does not work ![:(](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/sad.png)
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...