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

Adding News To frmMain (Server Sided) - easy:D


Ariel
 Share

Recommended Posts

Adding News to a label in the frmMain from a file in the server folder.

Heya  :embarrassed: Im new Here :D
As well new in the packeting thing so i made it as an extra in already made pack, SendEXP Hope that still helps!

**First thing first, Make a .txt file named: ingame_news in the Server\Data folder!**

Server-Side:
Find:
```
Function GetNews()
'read news
    Dim tmpTxt As String, tmpArray() As String, i As Long
    ' load news
    Open App.Path & "\data\ingame_news.txt" For Input As #1
        Line Input #1, tmpTxt
    Close #1
    ' split breaks
    tmpArray() = Split(tmpTxt, "/nl")
      For i = 0 To UBound(tmpArray)
        news = frmServer.lblnews.Caption & tmpArray(i) & vbNewLine
    Next

End Function
```
Then search for:
```
Sub SendEXP(ByVal Index As Long)
```After the first "Dim"
add```
Call GetNews
```added after
```
Buffer.WriteLong GetPlayerNextLevel(Index)
```This:
```
Buffer.WriteString news
```
Server Side done!

Client-Side:
Before Editing the Client Make a label in the frmMain called lblNews.

Find:
```
Function IsTryingToMove() As Boolean
```Below the function add the function:
```
Function setNews(ByVal News As String)
frmMain.lblNews = News
End Function
```
Last find the sub```
Private Sub HandlePlayerExp
```and Add after the "Dim"
```
Dim News As String
```then before "Exit sub" add:
```
    News = Buffer.ReadString
    Call setNews(News)
```
Link to comment
Share on other sites

  • 2 weeks later...
This is really inefficient. Why are you sending the news every time the player gains exp? Surely you should just contact the server when the client loads up and get the text that way, or just upload the txt file for download in an autoupdater.
Link to comment
Share on other sites

This method 'works' but very inefficently.  A+ for effort on learning the packets though.

Your method of loading the news file should be done once at the Startup of the Server in Sub Main or whenever someone forces it to reload the News.txt file through a command or button.  This way the news is stored in memory on startup and not loading every time an individual player checks their EXP.

Next, rather than piggy backing with the SendEXP, create a seperate Enumerator for handling news.  You'll want to look in modEnumerations, and add something like SSendNews for example.  Create a seperate function that is called when a player joins the game in modPlayer.  Use that new function to send the news to that player when they connect, saving you a lot of data transfer from Server>Client whenever they gain EXP ;)  It's not hard to learn how to create new packets, you have the basis of it so far, so pick at it a bit more and learn. 

The biggest things to remember are:
1\. Add your Client or Server enumerator at the end of each array in modEnumerations on the client AND the server.  General rule of thumb is to put an S infront of a Server packet and C infront of a Client packet.
2\. A blank server packet will look something like this
```
Public Sub ThisIsMyNewServerSub(byval Index as Long)
Dim Buffer as clsBuffer
Set Buffer = New ClsBuffer
Buffer.WriteLong SMyNewEnumerator
Buffer.WriteString "Hello World!"
SendDataTo Index, Buffer.ToArray()
Set Buffer = Nothing
End Sub

```
You'd look in modHandleData and handle the SMyNewEnumerator and tell it what function to call when it finds a packet starting with that variable. ;)
Link to comment
Share on other sites

  • 1 month later...

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...