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

Client receiving from Server =/


escfoe2
 Share

Recommended Posts

I know someone made a topic like this but no one explained what I needed…  I made a Kill Event on my server that has basically everything needed for a kill event! (First person to so many kills)  On the client...  I need it to get data from an .ini server-side!  The server has GetVar and PutVar but the only thing the Client has is WriteINI or ReadINI and they don't get values server-side just on the users PC..

The idea:  I've made a label and a shape just like the HP and MP bars..  It will show the number of kills (ex. 2/5) and the progress till completion...  All I need is the client to get .ini variables from the server-side folders..  Ugh I hope its not as difficult as it sounds...  Thanks for any help given!
Link to comment
Share on other sites

All you do is send a packet

```
Dim X As String
Dim Packet As String

X = GetVar()

Packet = "" & SEP_CHAR & index & SEP_CHAR & X & SEP_CHAR & END_CHAR

Call SendDataTo(index, Packet)

```
Link to comment
Share on other sites

So the X is like GetVar(what I want to get) but what else do I have to do??  anything server-side?  Also what goes in the quotation marks?

EDIT:  If the GetVar is all I have to change then thts pretty nifty…  Thanks for the help!
EDIT2:  From looking at the clients code it looks like I might need to put getvar in the quotations idk something along those lines to tell the server what I'm doing.. I'm not exactly sure lol I'd appreciate a lil more help!
Link to comment
Share on other sites

This Topic: [http://www.touchofdeathforums.com/smf/index.php/topic,61282.msg646458.html#msg646458](http://www.touchofdeathforums.com/smf/index.php/topic,61282.msg646458.html#msg646458)
You create the folder Charextras in Scripts and there are the #name#.ini Files. For an event use something like that:
```
If < PutVar("Scripts\charextras\" & GetPlayerName(Index) & ".ini", "KillCounter", "Kills", "#Number of kills needed#") Then
Call SetPlayerItem(index, #itemnumber#, #value#, #dir#)

```
Link to comment
Share on other sites

But there's no way to set a label client side with that, Revan. That would specifically call for a clunky scripted menu. The whole point of the source code is to get away from slow input like that. Your statement is backwards. He is asking about sending packets, not making a custom menu. It is you who is in the wrong board.

Esc, in the server, find where it sends a PlayerMsg. I've seen you around the scripting board, so I know you can understand it. Just go through the subs, following the flow of the PlayerMsg, from server to client. Then, make your own custom packet, modeling it after what you learned.
Link to comment
Share on other sites

I figured I'd also need something from the server…  I was just overlooking the client sending packets so I'll see what I can figure out and post if/when I get the correct response thanks...  I just needed a push in the right direction that's all lol
I can't seem to figure it out..  I observe the packets to and from but as I rework them it doesnt work..  I'm not understanding how they work...  I didn't think it would be so damn hard (XD) to get a variable from an .ini Server-Side!  I'ma keep trying Ballie...  I usually don't ask for things unless I need them...
Link to comment
Share on other sites

@Ballie:

> But there's no way to set a label client side with that, Revan. That would specifically call for a clunky scripted menu. The whole point of the source code is to get away from slow input like that. Your statement is backwards. He is asking about sending packets, not making a custom menu. It is you who is in the wrong board.
>
> Esc, in the server, find where it sends a PlayerMsg. I've seen you around the scripting board, so I know you can understand it. Just go through the subs, following the flow of the PlayerMsg, from server to client. Then, make your own custom packet, modeling it after what you learned.

I thought he wanted only an event xD
he neednt make it in menu but with the script you can make kill events.
Link to comment
Share on other sites

Think of sending packets like calling a subroutine. It's pretty similar to that, actually, in that it also has something like parameters in a way. Take this example:

```
Call PlayerMsg(Index, "Hi!", WHITE)
```
The first parameter here is the **Index**, and the second is the **Message**, which I inputted as "Hi!" The third parameter is the **color**, which I made "WHITE."

Now, let's basically do the same thing by sending a packet using different separators for the parameters instead of commas:

```
Call SendDataTo(Index, "playermsg" & SEP_CHAR & Index & SEP_CHAR & "Hi!" & SEP_CHAR & WHITE & END_CHAR)
```
Here, the separators are **SEP_CHAR**. The first parameter, known as **parse(1)** when handling the data in the Client, is **Index**. I'm sure you can figure out the second and third parameters. The **END_CHAR** statement is used to tell the Client that it's the end of the packet, one of the reasons why String packets are much worse than byte arrayed packets. The **"playermsg"** refers to the packet name, which is **parse(0)** in the Client **modHandleData**.

I hope that helped!
Link to comment
Share on other sites

Thanks for taking the time to explain that to me I really appreciate it!  I'm gonna  copy and paste it so I can reread it whenever…  Have a good one!  Ima post what I come up with here in a bit.
Ok I've got this in ModHandleData Server-Side:

```
Public Sub Packet_GetIniVar(ByVal Index As Long, ByVal FileName As String, ByVal Header As String, ByVal Footer As String)
    If FileName <> "" And Header <> "" And Footer <> "" Then
        Call SendDataTo(Index, "GETINIVAR" & SEP_CHAR & GetVar(App.Path & FileName, Header, Footer) & END_CHAR)
    End If
End Sub

```
Now I'm trying to figure out how to make it get the variable client-side lol…  Let me know if that's not right please
Link to comment
Share on other sites

Ahh but the code looks good so far right so:
```
Public Sub Packet_GetIniVar(ByVal Index As Long, ByVal FileName As String, ByVal Header As String, ByVal Footer As String)
    If FileName <> vbNullString And Header <> vbNullString And Footer <> vbNullString Then
        Call SendDataTo(Index, "GETINIVAR" & SEP_CHAR & GetVar(App.Path & FileName, Header, Footer) & END_CHAR)
    End If
End Sub

```
Not real sure on how to use LenB but I am guessing its If LenB(FileName) <> vbNullString or maybe something like that…  Now I'm working on figuring out how to the force the client to recieve this data when I want it...  I believe I'll use something like:
```
Public Sub Packet_GetIniVar(ByRef Parse() As String)
    Dim KillEventActive As Long
    Dim KillEventKillsNeeded As Long
    Dim KillEventPlayerKills As Long
    KillEventActive = GetVar("Kill Event.ini", "KILL EVENT", "kill_event_activated") 'Server Side
    KillEventKillsNeeded = GetVar("Kill Event.ini", "KILL EVENT", "kills_needed") 'Server Side
    KillEventPlayerKills = GetVar("Scripts\PlayerExtras\" & GetPlayerName(MyIndex) & ".ini", "KILL EVENT", "kill_event_activated") 'Server Side

        'Now here it will take charge of the label and shape...
        shpEVNT.Width = Val(Int(KillEventKillsNeeded) / Int(KillEventPlayerKills) * 640) 'Client Side
        lblEVNT.Caption = "~~ " & Int(KillEventPlayerKills) & " OUT OF " & Int(KillEventKillsNeeded) & " ~~"
End Sub

```
See how simple this should be lolz…
Getting the vars is my problem this whole time...  I know it will use Parses but can't point out how to make it...If someone were to finish this script for me or tell me a lil more...  It will boost my learning stature up really high!!  I need this so I can understand the real basis of the Eclipse Engine!
Link to comment
Share on other sites

LenB returns the length of a variable in bytes, so you would do this:

```
Public Sub Packet_GetIniVar(ByVal Index As Long, ByVal FileName As String, ByVal Header As String, ByVal Footer As String)
    If LenB(FileName) > 0 And LenB(Header) > 0 And LenB(Footer) > 0 Then
        Call SendDataTo(Index, "GETINIVAR" & SEP_CHAR & GetVar(App.Path & FileName, Header, Footer) & SEP_CHAR & GetVar("Kill Event.ini", "KILL EVENT", "kills_needed") & SEP_CHAR & GetVar("Scripts\PlayerExtras\" & GetPlayerName(Index) & ".ini", "KILL EVENT", "kill_event_activated") & END_CHAR)
    End If
End Sub

```
As for handling your packet data, you did correctly pass the **Parse()** variable through the Sub as **ByRef**, but you still didn't handle it correctly. I also don't know how many INI files you want to get variables from because you only sent information from one, while you tried receiving information from three. So, I'll do it with three since it seems like you wanted to do that. Try something like this:

Put this at the top of **modHandleData** in the **Client** where you see all of the **Case "(packetname)"** statements:

```
Case "getinivar"
    Call Packet_GetIniVar(Val(parse(1)), Val(parse(2)), Val(parse(3)))
    Exit Sub
```
```
Public Sub Packet_GetIniVar(ByVal KillEventActive As Long, ByVal KillEventKillsNeeded As Long, ByVal KillEventPlayerKills As Long)
        'Now here it will take charge of the label and shape...
        shpEVNT.Width = Val(Int(KillEventKillsNeeded) / Int(KillEventPlayerKills) * 640) 'Client Side
        lblEVNT.Caption = "~~ " & Int(KillEventPlayerKills) & " OUT OF " & Int(KillEventKillsNeeded) & " ~~"
End Sub
```
You forgot that **parses** are used to represent the variables once you've received the data from the server. **Parse(0)** is the packet name, which is already pre-handled, so all you have to do is write a new **Case** for its packet name. However, you still have to handle all of the other parses, which are all of the other parameters. I've done that when I made my call to **Packet_GetIniVar**.

Plus, if you get an error saying that your label (lblEVNT) or your shape (shpEVNT) has not been declared, you have to put the form name that those variables are in before, since you're not working within that form. If they are on **frmStable**, it would be like this:

```
frmStable.shpEVNT.Width = Val(Int(KillEventKillsNeeded) / Int(KillEventPlayerKills) * 640) 'Client Side
        frmStable.lblEVNT.Caption = "~~ " & Int(KillEventPlayerKills) & " OUT OF " & Int(KillEventKillsNeeded) & " ~~"
```
I hope that helps!
Link to comment
Share on other sites

I might actually be able to figure this out lol thanks you very much.. the part about addin it at the top of ModHandleData is what really made me understand how this works..  Now I'm gonna finish my code, post it, and test it…  Probably test it first but it will work or it won't so I'll post everything in a bit..  Thanks again this is a great community!!!

OK:  It isn't working yet but It's close, I have this so far:
Client-Side In ModHandleData I added a new Case:
```
Case "getinivar"
            Call Packet_GetIniVar(Val(Parse(1)), Val(Parse(2)), Val(Parse(3)))
            Exit Sub

```And here is the Packet_GetIniVar:
```
Public Sub Packet_GetIniVar(ByRef Parse() As String)
    If LenB(Parse(1)) > 0 And LenB(Parse(1)) = 1 Then
        If LenB(Parse(2)) > 0 Then
            If LenB(Parse(3)) > 0 Then
                frmStable.shpEVNT.Visible = True
                frmStable.lblEVNT.Visible = True

                shpEVNT.Width = Val(Int(Parse(2)) / Int(Parse(3)) * 640)
                lblEVNT.Caption = "~~ " & Int(Parse(3)) & " OUT OF " & Int(Parse(2)) & " ~~"
            End If
        End If
    Else
        frmStable.shpEVNT.Visible = False
        frmStable.lblEVNT.Visible = False
    End If
End Sub

```
Now this is Server-Side in ModHandleData…  I made another new case at the top:
```
Case "getinivar"
            Call Packet_GetIniVar(Index, Parse(1), Parse(2), Parse(3), Parse(4), Parse(5), Parse(6), Parse(7), Parse(8), Parse(9))
            Exit Sub

```
Yea I know its big but I have 3 ini's i need to check and 3 filenames, headers, and footers, so tht makes 9 lol And here is the Packet_GetIniVar:
```
Public Sub Packet_GetIniVar(ByVal Index As Long, ByVal FileName1 As String, ByVal Header1 As String, ByVal Footer1 As String, ByVal FileName2 As String, ByVal Header2 As String, ByVal Footer2 As String, ByVal FileName3 As String, ByVal Header3 As String, ByVal Footer3 As String)
    If FileName <> "" And Header <> "" And Footer <> "" Then
        Call SendDataTo(Index, "GETINIVAR" & SEP_CHAR & GetVar(App.Path & FileName1, Header1, Footer1) & SEP_CHAR & GetVar(App.Path & FileName2, Header2, Footer2) & SEP_CHAR & GetVar(App.Path & FileName3, Header3, Footer3) & END_CHAR)
    End If
End Sub

```
And there you have everything I've done in about 30mins lolz…  I can almost feel the success coming soon!  XD  If you see anything wrong let me know please!  Thanks for all help regarding my topic!!!
Link to comment
Share on other sites

@Robin:

> Would you lot stop bloody bolding random pieces of text? It's really off-putting.

Sorry, I only bold names of Subs, modules, forms, and some important variables so that the person I'm talking to doesn't miss them, but I'll stop.

@escfoe2:

> I might actually be able to figure this out lol thanks you very much.. the part about addin it at the top of ModHandleData is what really made me understand how this works..  Now I'm gonna finish my code, post it, and test it…  Probably test it first but it will work or it won't so I'll post everything in a bit..  Thanks again this is a great community!!!
>
> OK:  It isn't working yet but It's close, I have this so far:
> Client-Side In ModHandleData I added a new Case:
> ```
> Case "getinivar"
>             Call Packet_GetIniVar(Val(Parse(1)), Val(Parse(2)), Val(Parse(3)))
>             Exit Sub
>
> ```And here is the Packet_GetIniVar:
> ```
> Public Sub Packet_GetIniVar(ByRef Parse() As String)
>     If LenB(Parse(1)) > 0 And LenB(Parse(1)) = 1 Then
>         If LenB(Parse(2)) > 0 Then
>             If LenB(Parse(3)) > 0 Then
>                 frmStable.shpEVNT.Visible = True
>                 frmStable.lblEVNT.Visible = True
>            
>                 shpEVNT.Width = Val(Int(Parse(2)) / Int(Parse(3)) * 640)
>                 lblEVNT.Caption = "~~ " & Int(Parse(3)) & " OUT OF " & Int(Parse(2)) & " ~~"
>             End If
>         End If
>     Else
>         frmStable.shpEVNT.Visible = False
>         frmStable.lblEVNT.Visible = False
>     End If
> End Sub
>
> ```

Your server code is fine, but remember to replace the open quotations ("") with vbNullString. As for your Client code, you're still making mistakes with the parse() variable. Take a look at this:

```
Case "getinivar"
    Call Packet_GetIniVar(Val(Parse(1)), Val(Parse(2)), Val(Parse(3)))
    Exit Sub

```
In this code, you're already taking the values of the parses and carrying them into the Sub, so why did you pass parse() as a ByRef in your Packet_GetIniVar? You could do that if you wanted to, but you would have to pass Parse through the Sub as the only parameter, and then you would handle the individual parses (1, 2, 3) within the Sub. Instead of doing that, though, we've already handled the individual parses by passing them through Sub Packet_GetIniVar's parameters. So, all you would have to do is change your parameters in the Sub to have actual names and types. Here's how you should do it:

```
Public Sub Packet_GetIniVar(ByVal Number1 As Long, Number2 As Long, Number3 As Long)
    If LenB(Number1) > 0 And LenB(Number1) = 1 Then
        If LenB(Number2) > 0 Then
            If LenB(Number3) > 0 Then
                frmStable.shpEVNT.Visible = True
                frmStable.lblEVNT.Visible = True

                shpEVNT.Width = Val(Int(Number2) / Int(Number3) * 640)
                lblEVNT.Caption = "~~ " & Int(Number3) & " OUT OF " & Int(Number2) & " ~~"
            End If
        End If
    Else
        frmStable.shpEVNT.Visible = False
        frmStable.lblEVNT.Visible = False
    End If
End Sub

```
Replace Number1, Number2, and Number3 with the variable names you want.
Link to comment
Share on other sites

Well now I'm about to see if what I have actually works!!  Thankyou for the corrections I needed them…  I'll let you know if/when I get it to work..  But you're help is really making me understand this sooo much better now...

~~ Ok so I have 90% working and there are no errors BUT...  I can't get the Bar to display the right size...  (The shape which has a width of 650)  Here is all of my code:

CLIENT | On frm.Stable I have placed this bar (DUH) but I have also placed a timer to check for these values every so often...  It's code reads this:

```
Private Sub tmrKillEvent_Timer()
    If frmStable.Visible = True Then
        Call SendData("getinivar" & SEP_CHAR & "\Kill Event.ini" & SEP_CHAR & "KILL EVENT" & SEP_CHAR & "kill_event_activated" & SEP_CHAR & "\Kill Event.ini" & SEP_CHAR & "KILL EVENT" & SEP_CHAR & "kills_needed" & SEP_CHAR & "\Scripts\PlayerExtras\" & GetPlayerName(MyIndex) & ".ini" & SEP_CHAR & "KILL EVENT" & SEP_CHAR & "kill_event_kills" & END_CHAR)
    End If
End Sub

```
Notice there are 10 parameters counting the Parse(0) because I am calling for 3 different variable from .ini files and I need their Name, Header, and Variable to all be Parsed separate so that equals 9…  Now that you understand why it's like that lets move on...
Still CLIENT | In ModHandleData at the top there is a new case added which I already posted but I'm showing all again:

```
Case "getinivar"
            Call Packet_GetIniVar(Val(Parse(1)), Val(Parse(2)), Val(Parse(3)))
            Exit Sub

```
That code gets the 3 variables that the server sends after receiving the file data from the Client…  Now here is the Packet to handle that data once received:

```
Public Sub Packet_GetIniVar(ByVal KillEventActive As Long, KillEventKillsNeeded As Long, KillEventPlayerKills As Long)
    If LenB(KillEventActive) > 0 And Int(KillEventActive) = 1 Then
        If LenB(KillEventKillsNeeded) > 0 Then
            If LenB(KillEventPlayerKills) > 0 Then
                frmStable.shpEVNT.Visible = True
                frmStable.lblEVNT.Visible = True

                If Int(KillEventPlayerKills) > 0 Then
                    '  I got the bar to work right lol I was dividing the two in the wrong places
                    frmStable.shpEVNT.Width = Val(Int(KillEventPlayerKills) / Int(KillEventKillsNeeded) * 650)
                    frmStable.lblEVNT.Caption = "~~ " & Int(KillEventPlayerKills) & " OUT OF " & Int(KillEventKillsNeeded) & " ~~"
                Else
                    frmStable.shpEVNT.Width = 0
                    frmStable.lblEVNT.Caption = "~~ " & Int(KillEventPlayerKills) & " OUT OF " & Int(KillEventKillsNeeded) & " ~~"
                End If
            End If
        End If
    Else
        frmStable.shpEVNT.Visible = False
        frmStable.lblEVNT.Visible = False
    End If
End Sub

```
Now this is where my problem occurs…  I'm not sure how to properly show the fraction of the shape to the ammount of kills the player has to the ammount needed...  At the moment it shows a super extended bar...  I multiplied it by the same number as its length because I looked at how the HP bars were done and that is how they were done...  I'm not sure what to do but Ima keep trying.. thanks for all help I really appreciate it...  Oh I'll still post the server code too hang on:

SERVER | In ModHandleData there is a new case I've already shown but I'll show again:

```
Case "getinivar"
            Call Packet_GetIniVar(Index, Parse(1), Parse(2), Parse(3), Parse(4), Parse(5), Parse(6), Parse(7), Parse(8), Parse(9))
            Exit Sub

```
That will get all the file data that the Client sends to the Server…  Now this is the Packet that it calls:

```
Public Sub Packet_GetIniVar(ByVal Index As Long, ByVal FileName1 As String, ByVal Header1 As String, ByVal Footer1 As String, ByVal FileName2 As String, ByVal Header2 As String, ByVal Footer2 As String, ByVal FileName3 As String, ByVal Header3 As String, ByVal Footer3 As String)
On Error Resume Next

    If LenB(FileName1) > 0 And LenB(Header1) > 0 And LenB(Footer1) > 0 Then
        If LenB(FileName2) > 0 And LenB(Header2) > 0 And LenB(Footer2) > 0 Then
            If LenB(FileName3) > 0 And LenB(Header3) > 0 And LenB(Footer3) > 0 Then
                Call SendDataTo(Index, "GETINIVAR" & SEP_CHAR & GetVar(App.Path & FileName1, Header1, Footer1) & SEP_CHAR & GetVar(App.Path & FileName2, Header2, Footer2) & SEP_CHAR & GetVar(App.Path & FileName3, Header3, Footer3) & END_CHAR)
            End If
        End If
    End If
End Sub

```
It all is working fine for me except that bar XD  It's a lil difficult but hey what can I say…  It wouldn't be as fun if it was easy...  Thank you for all and any help given I really appreciate it all!!!
Link to comment
Share on other sites

  • 2 weeks later...
Sorry about double posting but my message is easily visible this way:  My code is now fully functional and I would not have been able to do it without the help of this community.  Ballie I appreciate your confidence in me and yes I did check over all of them completely but what Kimimaru pointed out to me was the cases at the top of ModHandleData… I did not see them at all and without them this wouldn't have been possible...  But without looking over the others as a reference, I would still be lost so I would like to take this time to thank you all and keep up the great work helping the community as I try to do myself!
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...