Originally posted by Dark Echo
MSE does not come with signs, so i thought for those people who want signs in their game here is a easy to follow tutorial i decided to write up.. I tried to do it so signs saved on the actually map, as in data1, date2 and data3, etc.. But that was much too comlicated, so i just made it a basic sign system with a .ini file..
Difficulty: 1/5
Part 1 - Server Side Go into modConstants and add:
Public Const MAX_SIGNS = 255 Find:
Public Const TILE_TYPE_KEYOPEN = 6 And add below it:
Public Const TILE_TYPE_SIGN = 7 Go into modDatabase and add:
Sub SaveSign(ByVal SignNum As Long) Dim FileName As String Dim i As Long
FileName = App.Path & "\data\signs.ini" Call PutVar(FileName, "SIGN" & SignNum, "Name", Trim(Sign(SignNum).Name)) Call PutVar(FileName, "SIGN" & SignNum, "Line1", Trim(Sign(SignNum).Line1)) Call PutVar(FileName, "SIGN" & SignNum, "Line2", Trim(Sign(SignNum).Line2)) End Sub
Sub SaveSigns() Dim i As Long
For i = 1 To MAX_SIGNS Call SaveSign(i) Next i End Sub
Sub LoadSigns() Dim FileName As String Dim i As Long
Call CheckSigns FileName = App.Path & "\data\signs.ini" For i = 1 To MAX_SIGNS Sign(i).Name = Trim(GetVar(FileName, "SIGN" & i, "Name")) Sign(i).Line1 = Trim(GetVar(FileName, "SIGN" & i, "Line1")) Sign(i).Line2 = Trim(GetVar(FileName, "SIGN" & i, "Line2")) DoEvents Next i End Sub
Sub CheckSigns() If Not FileExist("data\signs.ini") Then Call SaveSigns End If End Sub Go into modGameLogic and add:
Sub ClearSign(ByVal Index As Long) Sign(Index).Name = "" Sign(Index).Line1 = "" Sign(Index).Line2 = "" End Sub
Sub ClearSigns() Dim i As Long
For i = 1 To MAX_SIGNS Call ClearSign(i) Next i End Sub Go into modGeneral and find:
Call SetStatus("Loading spells...") Call LoadSpells And add below it:
Call SetStatus("Loading signs...") Call LoadSigns Go into modGlobals and add:
Public Sign(1 To MAX_SIGNS) As SignRec Go into modHandleData and add:
' :::::::::::::::::::::::::::::: ' :: Request edit sign packet :: ' :::::::::::::::::::::::::::::: If LCase(Parse(0)) = "requesteditsign" Then ' Prevent hacking If GetPlayerAccess(Index) < ADMIN_DEVELOPER Then Call HackingAttempt(Index, "Admin Cloning") Exit Sub End If Call SendDataTo(Index, "SIGNEDITOR" & SEP_CHAR & END_CHAR) Exit Sub End If ' :::::::::::::::::::::: ' :: Edit sign packet :: ' :::::::::::::::::::::: If LCase(Parse(0)) = "editsign" Then ' Prevent hacking If GetPlayerAccess(Index) < ADMIN_DEVELOPER Then Call HackingAttempt(Index, "Admin Cloning") Exit Sub End If ' The sign # n = Val(Parse(1)) ' Prevent hacking If n < 0 Or n > MAX_SIGNS Then Call HackingAttempt(Index, "Invalid Sign Index") Exit Sub End If Call AddLog(GetPlayerName(Index) & " editing sign #" & n & ".", ADMIN_LOG) Call SendEditSignTo(Index, n) End If ' :::::::::::::::::::::: ' :: Save sign packet :: ' :::::::::::::::::::::: If (LCase(Parse(0)) = "savesign") Then ' Prevent hacking If GetPlayerAccess(Index) < ADMIN_DEVELOPER Then Call HackingAttempt(Index, "Admin Cloning") Exit Sub End If ' Sign # n = Val(Parse(1)) ' Prevent hacking If n < 0 Or n > MAX_SIGNS Then Call HackingAttempt(Index, "Invalid Sign Index") Exit Sub End If ' Update the sign Sign(n).Name = Trim(Parse(2)) Sign(n).Line1 = Trim(Parse(3)) Sign(n).Line2 = Trim(Parse(4)) ' Save it Call SendUpdateSignToAll(n) Call SaveSign(n) Call AddLog(GetPlayerName(Index) & " saving sign #" & n & ".", ADMIN_LOG) Exit Sub End If ' :::::::::::::::::: ' :: Request Sign :: ' :::::::::::::::::: If (LCase(Parse(0)) = "requestsign") Then ' Sign # n = Val(Parse(1)) ' Prevent hacking If n < 0 Or n > MAX_SIGNS Then Call HackingAttempt(Index, "Invalid Sign Index") Exit Sub End If ' Send sign info Call SendSignTo(Index, n) End If Go into modServerTCP and add:
Sub SendSign(ByVal Index As Long) Dim i As Long
For i = 1 To MAX_SIGNS If Trim(Sign(i).Name) <> "" Then Call SendUpdateSignTo(Index, i) End If Next i End Sub
Sub SendUpdateSignToAll(ByVal SignNum As Long) Dim Packet As String
Packet = "UPDATESIGN" & SEP_CHAR & SignNum & SEP_CHAR & Trim(Sign(SignNum).Name) & SEP_CHAR & END_CHAR Call SendDataToAll(Packet) End Sub
Sub SendUpdateSignTo(ByVal Index As Long, ByVal SignNum As Long) Dim Packet As String
Packet = "UPDATESIGN" & SEP_CHAR & SignNum & SEP_CHAR & Trim(Sign(SignNum).Name) & SEP_CHAR & END_CHAR Call SendDataTo(Index, Packet) End Sub
Sub SendEditSignTo(ByVal Index As Long, ByVal SignNum As Long) Dim Packet As String
Packet = "EDITSIGN" & SEP_CHAR & SignNum & SEP_CHAR & Trim(Sign(SignNum).Name) & SEP_CHAR & Sign(SignNum).Line1 & SEP_CHAR & Sign(SignNum).Line2 & SEP_CHAR & END_CHAR Call SendDataTo(Index, Packet) End Sub
Sub SendSignTo(ByVal Index As Long, ByVal SignNum As Long) Dim Packet As String
Packet = "SIGN" & SEP_CHAR & SignNum & SEP_CHAR & Trim(Sign(SignNum).Name) & SEP_CHAR & Sign(SignNum).Line1 & SEP_CHAR & Sign(SignNum).Line2 & SEP_CHAR & END_CHAR Call SendDataTo(Index, Packet) End Sub Go into modTypes and add:
Type SignRec Name As String * NAME_LENGTH Line1 As String * NAME_LENGTH Line2 As String * NAME_LENGTH End Type
Thats all for the server side.. I will post the rest later, i'm tired.. I begun writing this tutorial without posting any code, and just explaining every line you should add in, but without actually telling you how to add it in.. Although, i got lazy and so i just begun posting the code.. Oh well.. Part 2 later..
Ok, i guess i might as well post this part up since well people need it.. Anyway, this part requires you to make two new forms, and a small adjustment to your mapeditor.. But i will explain this later..
Part 2 - Client Side Go into modClientTCP and add:
Sub SendRequestEditSign() Dim Packet As String
Packet = "REQUESTEDITSIGN" & SEP_CHAR & END_CHAR Call SendData(Packet) End Sub
Public Sub SendSaveSign(ByVal SignNum As Long) Dim Packet As String
With Sign(SignNum) Packet = "SAVESIGN" & SEP_CHAR & SignNum & SEP_CHAR & Trim(.Name) & SEP_CHAR & Trim(.Line1) & SEP_CHAR & Trim(.Line2) & SEP_CHAR & END_CHAR End With Call SendData(Packet) End Sub Go into modConstants and add:
Public Const MAX_SIGNS = 255 Find:
Public Const TILE_TYPE_KEYOPEN = 6 And add below it:
Public Const TILE_TYPE_SIGN = 7 Go into modGameLogic and find:
If .Type = TILE_TYPE_KEYOPEN Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "O", QBColor(White)) And add below it:
If .Type = TILE_TYPE_SIGN Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "S", QBColor(White)) Find:
' Request stats If LCase(Mid(MyText, 1, 6)) = "/trade" Then Call SendData("trade" & SEP_CHAR & END_CHAR) MyText = "" Exit Sub End If And add below it:
' Sign Dim SignPacket As String If Map.Tile(GetPlayerX(MyIndex), GetPlayerY(MyIndex)).Type = TILE_TYPE_SIGN Then SignNum = Map.Tile(GetPlayerX(MyIndex), GetPlayerY(MyIndex)).Data1 SignPacket = "requestsign" & SEP_CHAR & SignNum & SEP_CHAR & END_CHAR Call SendData(SignPacket) End If Find:
' Banning a player If LCase(Mid(MyText, 1, 4)) = "/ban" Then If Len(MyText) > 5 Then MyText = Mid(MyText, 6, Len(MyText) - 5) Call SendBan(MyText) MyText = "" End If Exit Sub End If And add below it:
' Editing sign request If Mid(MyText, 1, 10) = "/editsign" Then Call SendRequestEditSign MyText = "" Exit Sub End If End If Find:
If frmMapEditor.optKeyOpen.Value = True Then .Type = TILE_TYPE_KEYOPEN .Data1 = KeyOpenEditorX .Data2 = KeyOpenEditorY .Data3 = 0 End If And add below it:
If frmMapEditor.optSign.Value = True Then .Type = TILE_TYPE_SIGN .Data1 = SignNum .Data2 = 0 .Data3 = 0 End If And add in modGameLogic:
Public Sub SignEditorInit() frmSignEditor.txtSignName.Text = Trim(Sign(EditorIndex).Name) frmSignEditor.txtSignLine1.Text = Trim(Sign(EditorIndex).Line1) frmSignEditor.txtSignLine2.Text = Trim(Sign(EditorIndex).Line2) frmSignEditor.Show vbModal End Sub
Public Sub SignEditorOk() Sign(EditorIndex).Name = frmSignEditor.txtSignName.Text Sign(EditorIndex).Line1 = frmSignEditor.txtSignLine1.Text Sign(EditorIndex).Line2 = frmSignEditor.txtSignLine2.Text Call SendSaveSign(EditorIndex) InSignEditor = False Unload frmSignEditor End Sub
Public Sub SignEditorCancel() InSignEditor = False Unload frmSignEditor End Sub Go into modGlobals and add:
' Used for map sign number Public SignNum As Integer Find:
Public EditorIndex As Long And add below it:
Public InSignEditor As Boolean Find:
Public Spell(1 To MAX_SPELLS) As SpellRec And add below it:
Public Sign(1 To MAX_SIGNS) As SignRec Go into modHandleData and add:
' :::::::::::::::::::::::: ' :: Sign editor packet :: ' :::::::::::::::::::::::: If (LCase(Parse(0)) = "signeditor") Then InSignEditor = True frmIndex.Show frmIndex.lstIndex.Clear ' Add the names For i = 1 To MAX_SIGNS frmIndex.lstIndex.AddItem i & ": " & Trim(Sign(i).Name) Next i frmIndex.lstIndex.ListIndex = 0 Exit Sub End If ' :::::::::::::::::::::::: ' :: Update sign packet :: ' :::::::::::::::::::::::: If (LCase(Parse(0)) = "updatesign") Then n = Val(Parse(1)) ' Update the spell name Sign(n).Name = Trim(Parse(2)) Exit Sub End If ' :::::::::::::::::::::: ' :: Edit sign packet :: <- Used for sign editor admins only ' :::::::::::::::::::::: If (LCase(Parse(0)) = "editsign") Then n = Val(Parse(1)) ' Update the spell Sign(n).Name = Trim(Parse(2)) Sign(n).Line1 = Trim(Parse(3)) Sign(n).Line2 = Trim(Parse(4)) ' Initialize the spell editor Call SignEditorInit
Exit Sub End If
' :::::::::: ' :: Sign :: ' :::::::::: If LCase(Parse(0)) = "sign" Then frmMirage.picSign.Visible = True 'put all the data into the correct area frmMirage.lblSignName.Caption = Trim(Parse(2)) frmMirage.txtSignLine1.Text = Trim(Parse(3)) frmMirage.txtSignLine2.Text = Trim(Parse(4)) Exit Sub End If Go into modTypes and add:
Type SignRec Name As String * NAME_LENGTH Line1 As String * NAME_LENGTH Line2 As String * NAME_LENGTH End Type Go into your mapeditor pic or form and add a new option button called:
optSign Double click it and add:
frmSignChooser.Show vbModal Go into your frmIndex coding and find:
If InSpellEditor = True Then Call SendData("EDITSPELL" & SEP_CHAR & EditorIndex & SEP_CHAR & END_CHAR) End If And add below it:
If InSignEditor = True Then Call SendData("EDITSIGN" & SEP_CHAR & EditorIndex & SEP_CHAR & END_CHAR) End If Find:
InSpellEditor = False And add below it:
InSignEditor = False Go into your frmMirage and add a new picture box called:
picSign Make the visibility 'false' And add in the picture box one label called:
lblSignName And add in the picture box two text boxes called:
txtSignLine1 And
txtSignLine2 Make the two text boxes have 'multiline' And add in the picture box a command button called:
cmdSignClose Double click the command button and add:
If picSign.Visible = True Then picSign.Visible = False End If
Now, make a new form called:
frmSignChooser Add a new horizontal scroll bar called:
scrlSignNum Change the min and max value to '1' and '255' Add a new label called:
lblSignNum Change the caption to '1' Add two new command buttons call them:
cmdOk And
cmdCancel Go into the coding and add:
Private Sub cmdCancel_Click() Unload Me End Sub
Private Sub cmdOk_Click() SignNum = scrlSignNum.Value Unload Me End Sub
Private Sub scrlSignNum_Change() lblSignNum.Caption = STR(scrlSignNum.Value) End Sub Now, make a new form called:
frmSignEditor And add three new labels and label them Sign Name, Line1 and Line2. Add three new text boxes and call them:
txtSignName And
txtSignLine1 And
txtSignLine2 Make the three text boxes have a maximum value of 20. Add two new command buttons call them:
cmdOk And
cmdCancel Go into the coding and add:
Private Sub cmdCancel_Click() Call SignEditorCancel End Sub
Private Sub cmdOk_Click() Call SignEditorOk End Sub
That should be it, if i have missed anything out, please tell me and i will fix it right away.. :D Enjoy!!
|