[EO 2 & 3]Target-Details Tutorial

Hey there, this is a new tutorial of mine. It has 1 part unfinished which I will have to finish soon. Don’t worry about it. It will be done ASAP.

CLIENT SIDE

Download the attachment. It has a picture box containing the details tab.

After adding the tab make a label. Name it whatever you like. Caption can also be whatever you like. (This part is the button that opens up the tab. Like the inv button. Since I don’t have a picture for a button I am using the method of a label.)

Okay now double click on your new label and add the following lines of code.

!


picOppDetails.Visible = True

picInventory.Visible = False

picCharacter.Visible = False

picSpells.Visible = False

picOptions.Visible = False

picParty.Visible = False

I suppose that is self explanatory. Now we have to make the target details tab invisible when another tab is open. To do that, find this line of code.


If Not picInventory.Visible Then

Now add this line of code in each case.


picOppDetails.Visible = False

Now that that is done we have to declare our packets.

In modEnumerations find


' Make sure SMSG_COUNT is below everything else

SMSG_COUNT

Above that add


STargetDetails

Now in modHandleData in the sub InitMessages add


HandleDataSub(STargetDetails) = GetAddress(AddressOf HandleTargetDetails)

Now at the end of the module add


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

Dim Name As String, maxHp As Long, HP As Long, Level As Long, Stat(1 To Stats.Stat_Count - 1) As Byte

Dim i As Long

Dim Buffer As clsBuffer

Set Buffer = New clsBuffer

Buffer.WriteBytes Data()

Name = Buffer.ReadString

Level = Buffer.ReadByte

maxHp = Buffer.ReadLong

HP = Buffer.ReadLong

For i = 1 To Stats.Stat_Count - 1

Stat(i) = Buffer.ReadByte

Next i

With frmMain

If Not Name = vbNullString Then

.lblOppName.Caption = Name

Else

.lblOppName.Caption = "No Target"

End If

.lblOppLevel.Caption = Level

For i = 1 To Stats.Stat_Count - 1

.lblOppStat(i).Caption = Stat(i)

Next i

If Not maxHp = 0 Then

.lblOppHp = HP & "/" & maxHp

Else

.lblOppHp = "No Target"

End If

End With

Set Buffer = Nothing

End Sub

in the same module find,


frmMain.imgHPBar.width = ((GetPlayerVital(MyIndex, Vitals.HP) / HPBar_Width) / (GetPlayerMaxVital(MyIndex, Vitals.HP) / HPBar_Width)) * HPBar_Width

Underneath, before the " error handler " add this


if mytargettype = target_type_player then

If myTarget = MyIndex Then

frmMain.lblOppHp = GetPlayerVital(MyIndex, HP) & "/" & Player(MyIndex).MaxVital(HP)

End If

end if

in the same module find

MapNpc(MapNpcNum).Vital(i) = Buffer.ReadLong

below that add

If myTargetType = TARGET_TYPE_NPC Then

If myTarget = MapNpc(MapNpcNum).num Then

frmMain.lblOppHp.Caption = MapNpc(MapNpcNum).Vital(HP) & "/" & Npc(myTarget).HP

End If

End If

I suppose that is the end of Client Side. There might be more. Just Don’t remember :P

SERVER-SIDE

Lets declare our packet. Go to modEnumeration and find


' Make sure SMSG_COUNT is below everything else

SMSG_COUNT

Above that add

STargetDetails

Go to modHandleData and find this

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

In this sub above every

sendtarget index

add

sendtargetdetails index

Now in modServerTCP add this at the bottom


Public Sub SendtargetDetails(ByVal index As Long)

Dim Buffer As clsBuffer

Dim target As Long, targetType As Long

Dim i As Long

target = TempPlayer(index).target

targetType = TempPlayer(index).targetType

Set Buffer = New clsBuffer

Buffer.WriteLong stargetdetails

Select Case targetType

Case TARGET_TYPE_PLAYER

Buffer.WriteString GetPlayerName(target)

Buffer.WriteByte GetPlayerLevel(target)

Buffer.WriteLong GetPlayerMaxVital(target, HP)

Buffer.WriteLong GetPlayerVital(target, HP)

For i = 1 To Stats.Stat_Count - 1

Buffer.WriteByte Player(target).stat(i)

Next i

Case TARGET_TYPE_NPC

With Npc(MapNpc(GetPlayerMap(index)).Npc(target).Num)

Buffer.WriteString Trim$(.Name)

Buffer.WriteByte .Level

Buffer.WriteLong .HP

Buffer.WriteLong MapNpc(GetPlayerMap(index)).Npc(target).Vital(HP)

For i = 1 To Stats.Stat_Count - 1

Buffer.WriteByte .stat(i)

Debug.Print .stat(i)

Next i

End With

Case TARGET_TYPE_NONE

Buffer.WriteString vbNullString

Buffer.WriteByte 1

Buffer.WriteLong 0

Buffer.WriteLong 0

For i = 1 To Stats.Stat_Count - 1

Buffer.WriteByte 0

Next i

End Select

SendDataTo index, Buffer.ToArray

Set Buffer = Nothing

End Sub

in modCombat find


' purge target info of anyone who targetted dead guy

For i = 1 To Player_HighIndex

If IsPlaying(i) And IsConnected(i) Then

If Player(i).Map = GetPlayerMap(attacker) Then

If TempPlayer(i).target = TARGET_TYPE_PLAYER Then

If TempPlayer(i).target = victim Then

TempPlayer(i).target = 0

TempPlayer(i).targetType = TARGET_TYPE_NONE

SendTarget i

End If

End If

End If

End If

Next

Below ’ SendTarget i ’ ,add

sendtargetdetails i

in the same sub below

Call SendVital(victim, Vitals.HP)

below that add

sendtargetdetails(attacker)

find


'Loop through entire map and purge NPC from targets

For i = 1 To Player_HighIndex

If IsPlaying(i) And IsConnected(i) Then

If Player(i).Map = mapNum Then

If TempPlayer(i).targetType = TARGET_TYPE_NPC Then

If TempPlayer(i).target = mapNpcNum Then

TempPlayer(i).target = 0

TempPlayer(i).targetType = TARGET_TYPE_NONE

SendTarget i

End If

End If

End If

End If

Next

Below ’ sendtarget i ’ add

SendtargetDetails i

Use the full project search feature and find the following


sendtarget index

and add this bellow it


sendtargetdetails index

Thats all there is to the tutorials. If you think I missed something (like when you attack an update doesn’t happen) post below.

And also if there are compile errors post below as well.

Theres already an tutorial for that (One not fixed and one which is the same fixed by me)

😉 But thats nice too haha

Im happy to see again something from you

Oh, there was? Man. Oh well.

Please screenshot

Thanx

Buffer.WriteLong MapNpc(GetPlayerMap(index)).Npc(mapNpcNum).Vital(HP)

Error in this line :c “Sub index out of range”

Please help 😧 to fix

Screenshot of the error plz. I tried googling that error but nothing came up.

This is my error 😧

[attachment=645:fefe.JPG]

Hover over each variable. A tooltip is shown. On the variable that shows <subscript out="" of="" range="">paste that variable here.</subscript>

For i = 1 To Stats.Stat_Count - 1

Buffer.WriteByte .stat(i) <– <subscript out="" of="" range="">Debug.Print .stat(i) <– <subscript out="" of="" range="">Next i</subscript></subscript>

Please help in error Sbuscript out of Range D:!?

Do you have TeamViewer?

Yes i have 😧

Pass me your details, I will try to fix it remotely.

I, too have this problem. I can only view some NPC’s HP. Other then that, it RTE9’s on me. This is very upsetting. Mainly because this feature works so well, when it works. If there is a fix I’d recommend updating the tutorial. Thanks.

Run in the IDE. When it errors, click debug in the box. (Make sure debug mode is off)

The errored line will be highlighted. Copy paste it here. Hover through all the variables in the line of code that errors and type in the variable value which has the errors. (Var value will be Subscript out of Range.)

Ok, I didn’t quite understand what you meant… But here’s what I found. (Excuse my ignorance, I’m not very advanced with VB6 at all.)

This is the line that errors:

Buffer.WriteLong MapNpc(GetPlayerMap(index)).NPC(mapNpcNum).Vital(HP)

When I hovered over everything I found this:

(GetPlayerMap(index)) = 1

.NPC(mapNpcNum) = 0

And out of these lines of code… I found a few that (Subscript out of Range)'d

For i = 1 To Stats.Stat_Count - 1

Buffer.WriteByte .Stat(i) = (Subscript out of Range)

Debug.Print .Stat(i) = (Subscript out of Range)

Next i

End With

Also, for some reason it seems to display the stats of the first NPC in my NPC list… Rather than the actual map NPC… I’m very confused.

Ensure the following.

i > 1 < stats.stat_count - 1

target > 1 < Max_NPC

Why are you adding to server load for this feature? When you can do it just client side.

Because it isn’t’ always necessary for the client to get the npc/player details. This ensures that the details are valid.

all you need is the npc num and its current vitals (which already get sent anyway)??

Log in to reply