Dawntide Posted August 20, 2012 Author Share Posted August 20, 2012 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 outIf Options.Debug = 1 Then On Error GoTo errorhandlerSet Buffer = New clsBufferBuffer.WriteLong CGiveCurrencyBuffer.WriteLong invslotSendData Buffer.ToArray()Set Buffer = Nothing' Error handlerExit Suberrorhandler:HandleError "GiveCurrency", "modClientTCP", Err.Number, Err.Description, Err.Source, Err.HelpContextErr.ClearExit SubEnd Sub```server side:```Sub HandleGiveCurrency(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)Dim Buffer As clsBufferDim invSlot As LongDim itemnum As LongDim Amount As LongSet Buffer = New clsBufferBuffer.WriteBytes Data()invSlot = Buffer.ReadLong' give goldGiveInvItem index, 1, Amount' send confirmation messagePlayerMsg index, "You received" & Amount & "gold.", BrightGreenSet Buffer = NothingEnd 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 More sharing options...
Joyce Posted August 20, 2012 Share Posted August 20, 2012 What on earth is this supposed to do, and why are you sending random stuff you're not using? Link to comment Share on other sites More sharing options...
Dawntide Posted August 20, 2012 Author Share Posted August 20, 2012 It is supposed to give the player a certain amount of money.i modified the sellitem Sub. Link to comment Share on other sites More sharing options...
Joyce Posted August 20, 2012 Share Posted August 20, 2012 Why would you handle this client side? That's just asking for people exploiting the packet and gain unlimited supplies of gold. Link to comment Share on other sites More sharing options...
Dawntide Posted August 20, 2012 Author Share Posted August 20, 2012 I created a new form with a little minigame, if the player wins he should gain a certain amount of gold. how to do it without sending packets to the server? Link to comment Share on other sites More sharing options...
Joyce Posted August 20, 2012 Share Posted August 20, 2012 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 More sharing options...
Dawntide Posted August 20, 2012 Author Share Posted August 20, 2012 Sounds nice, but i'm a noob, could you please give me a little tutorial? Link to comment Share on other sites More sharing options...
Joyce Posted August 20, 2012 Share Posted August 20, 2012 Not really, I don't know how your system is structured.Anyway, what doesn't work with these two packet subs? Link to comment Share on other sites More sharing options...
Dawntide Posted August 20, 2012 Author Share Posted August 20, 2012 I do not tested them, you told me i am sending random stuff which i do not use.is there a example for the unique ID packet already in the clean copy of eclipse event system 2.3? I could copy and modify it Link to comment Share on other sites More sharing options...
Joyce Posted August 20, 2012 Share Posted August 20, 2012 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 More sharing options...
Dawntide Posted August 20, 2012 Author Share Posted August 20, 2012 Sorry, but i do not know how to define and send a ID. And how to return it? Link to comment Share on other sites More sharing options...
Joyce Posted August 20, 2012 Share Posted August 20, 2012 Wait, how are you opening the minigame? Not with a packet? Link to comment Share on other sites More sharing options...
Dawntide Posted August 20, 2012 Author Share Posted August 20, 2012 No its a simple imgButton on frmMain ![:)](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/smile.png) Link to comment Share on other sites More sharing options...
Joyce Posted August 20, 2012 Share Posted August 20, 2012 **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 Suberrorhandler: HandleError "SayMsg", "modClientTCP", Err.Number, Err.Description, Err.Source, Err.HelpContext Err.Clear Exit SubEnd 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 = NothingEnd 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 More sharing options...
Dawntide Posted August 20, 2012 Author Share Posted August 20, 2012 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 Suberrorhandler: HandleError "GiveCurrency", "modClientTCP", Err.Number, Err.Description, Err.Source, Err.HelpContext Err.Clear Exit SubEnd 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 clsBufferDim itemnum As LongDim amount As LongSet buffer = New clsBufferbuffer.WriteBytes Data()' give goldGiveInvItem index, 1, amount' send confirmation messagePlayerMsg index, "You received" & amount & " gold.", BrightGreenSet buffer = NothingEnd Sub```modEnumerations:```CGiveCurrency```Whats wrong? Link to comment Share on other sites More sharing options...
Joyce Posted August 20, 2012 Share Posted August 20, 2012 You never did a```amount = buffer.readlong```call. ![:P](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/tongue.png) Link to comment Share on other sites More sharing options...
Ruins of Hell Posted August 20, 2012 Share Posted August 20, 2012 ```Sub HandleGiveCurrency(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)Dim buffer As clsBufferDim itemnum As LongDim amount As LongSet buffer = New clsBufferbuffer.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.", BrightGreenSet buffer = NothingEnd Sub```**Edit:** sorry, this new forum doesn't alert on new replies. Link to comment Share on other sites More sharing options...
Dawntide Posted August 20, 2012 Author Share Posted August 20, 2012 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 More sharing options...
Joyce Posted August 20, 2012 Share Posted August 20, 2012 It's still there, but the URLs were changed with the new forum.. It should be somewhere in the boards.And wasn't there a GiveEXP sub? Or was that something I wrote myself. :S Link to comment Share on other sites More sharing options...
Ruins of Hell Posted August 20, 2012 Share Posted August 20, 2012 > 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 More sharing options...
Dawntide Posted August 20, 2012 Author Share Posted August 20, 2012 I used the search function of the forum and did not found it O.Ounfortunately there is no GiveEXP sub :/ Link to comment Share on other sites More sharing options...
Ruins of Hell Posted August 20, 2012 Share Posted August 20, 2012 You're close. It's Sub GivePlayerEXP. Link to comment Share on other sites More sharing options...
Dawntide Posted August 20, 2012 Author Share Posted August 20, 2012 Okay, i will check it after i fixed the gold mechanic.How to check if the player has more or exactly 50 gold?I can not find the right Sub Link to comment Share on other sites More sharing options...
Ruins of Hell Posted August 20, 2012 Share Posted August 20, 2012 Look at Function HasItem. Link to comment Share on other sites More sharing options...
Dawntide Posted August 21, 2012 Author Share Posted August 21, 2012 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 Suberrorhandler: HandleError "CheckCurrency", "modClientTCP", Err.Number, Err.Description, Err.Source, Err.HelpContext Err.Clear Exit SubEnd Sub``````Sub HandleCheckCurrency(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)Dim Buffer As clsBufferDim itemamount As LongSet Buffer = New clsBufferBuffer.WriteBytes Data()itemamount = Buffer.ReadLong' check golditemamount = HasItem(index, 1)If itemamount < 50 ThenPlayerMsg index, "Not enough gold.", BrightRedExit SubEnd IfSet Buffer = NothingEnd Sub```It does not work ![:(](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/sad.png) 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