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

MapNpcData over-riding somewhere


zomb88
 Share

Recommended Posts

Ive built a bass pet system for a modified version of ER.

I have the pet data being sent through the spawnnpc function but after the data gets handled client side within handlespawnnpc after the bytes are read (the data is there until the handlespawnnpc function has ended) but then it is gone must be something in the loop i am missing?
Link to comment
Share on other sites

```

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

Dim n 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.WriteBytes Data()

n = buffer.ReadLong

With MapNpc(n)

.Num = buffer.ReadLong

.X = buffer.ReadLong

.Y = buffer.ReadLong

.Dir = buffer.ReadLong

.Pet.Name = buffer.ReadString

.Pet.Owner = buffer.ReadLong

' Client use only

.xOffset = 0

.yOffset = 0

.Moving = 0

End With

' Error handler

Exit Sub

ErrorHandler:

HandleError "HandleSpawnNpc", "modHandleData", Err.Number, Err.Description, Err.Source, Err.HelpContext

Err.Clear

Exit Sub

End Sub

```

This is the client side HandleSpawnNpc Sub where the data comes in and stores .Pet.Name and .Pet.Owner for client side MapNpc's.

If i do a test at the end of this sub the Data is there i can see it but something after this sub is called is overriding or deleting the data. Maybe when NPC's refresh or something in the Loop?
Link to comment
Share on other sites

I have done that and i have run some tests. The information gets handled server side fine and sends to the client fine and the sub i posted the data is working fine but something else is executed after the handlespawnnpc sub i posted which is overriding it or changing it back to 0/vbnullstring like another call client side in game loop that updates map npcs or something im not sure
Link to comment
Share on other sites

> I have done that and i have run some tests. The information gets handled server side fine and sends to the client fine and the sub i posted the data is working fine but something else is executed after the handlespawnnpc sub i posted which is overriding it or changing it back to 0/vbnullstring like another call client side in game loop that updates map npcs or something im not sure

That's exactly what I just told you to look for.

* Setp 1: Press 'CTRL + F' in the client.
* Step 2: Input 'Pet.Name' or 'Pet.Owner'
* Step 3: Press enter or click 'Find' in the Find/Replace dialog.
* Step 4: Write down the sub/function you find them in.
* Step 5: Repeat steps 3 & 4 until you have found every location.
* Step 6: Post those locations here, not all of the code, just the names of the subs/functions

If done correctly, I can help you.
Link to comment
Share on other sites

I ran some more checks and found where the data is changing which is in HandleCheckForMap and I am pretty sure its the call ClearMapNpcs

```

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

Dim X As Long

Dim Y As Long

Dim i As Long

Dim NeedMap As Byte

Dim buffer As clsBuffer

' If debug mode, handle error then exit out

If Options.Debug = 1 Then On Error GoTo ErrorHandler

GettingMap = True

Set buffer = New clsBuffer

buffer.WriteBytes Data()

' Erase all players except self

For i = 1 To MAX_PLAYERS

If i <> MyIndex Then

Call SetPlayerMap(i, 0)

End If

Next

' Erase all temporary tile values

Call ClearMapNpcs

Call ClearMapItems

Call ClearMap

' clear the blood

For i = 1 To MAX_BYTE

Blood(i).X = 0

Blood(i).Y = 0

Blood(i).Sprite = 0

Blood(i).timer = 0

Next

' Get map num

X = buffer.ReadLong

' Get revision

Y = buffer.ReadLong

If FileExist(App.Path & MAP_PATH & "map" & X & MAP_EXT) Then

Call LoadMap(X)

' Check to see if the revisions match

NeedMap = 1

If Map.Revision = Y Then

' We do so we dont need the map

NeedMap = 0

End If

Else

NeedMap = 1

End If

' Either the revisions didn't match or we dont have the map, so we need it

Set buffer = New clsBuffer

buffer.WriteLong CNeedMap

buffer.WriteLong NeedMap

SendData buffer.ToArray()

Set buffer = Nothing

' Check if we get a map from someone else and if we were editing a map cancel it out

If InMapEditor Then

InMapEditor = False

frmEditor_Map.visible = False

ClearAttributeDialogue

If frmEditor_MapProperties.visible Then

frmEditor_MapProperties.visible = False

End If

End If

' Error handler

Exit Sub

ErrorHandler:

HandleError "HandleCheckForMap", "modHandleData", Err.Number, Err.Description, Err.Source, Err.HelpContext

Err.Clear

Exit Sub

End Sub

```

Do i have to save the mapnpc pet data in savemap and then load it in loadmap subs??
Link to comment
Share on other sites

The problem was that when a new npc spawns it saves only the npc number in the client side map file.

I have it now saving the npc number and the pet owner.

It is working fine but is this the best way to handle it?
Link to comment
Share on other sites

Why use the NPC Spawn? Make a new sub that handles this. A new type rec should hold all the Pets in server side, along with the player index number.

Send this data to the client, and make the server show the new Pet as an NPC.
Link to comment
Share on other sites

I have just added 1 extra value to be saved in client maps.

I have done all the above its just the way the client handles new map npcs. There is a new type rec to hold pet data but that is included in mapnpc data.
Link to comment
Share on other sites

Sounds like [background=rgb(248, 248, 248)]Call ClearMapNpcs [/background]is what's making your pets disappear.

IMO, Pets are essentially equipment. They're like a glorified paperdoll piece with a mind of their own. They look like NPCs, but they're not. When they're coded differently from NPCs, they aren't influenced by ClearMapNPCs.

I second the recommendation for a separate sub for pet-related spawning. I'd extend this to removing pets, pets moving, etc. For pet functions (if they talk randomly, attack, etc.), those can be done in existing subs. If you pets have commands (e.g.: come/wander/attack/sit/spin-on-the-spot) those should be separate subs.

You mentioned that you are using a petrec. Also be sure you have the type in both client and server side in modTypes. Any editing of an existing type (e.g. map types) must be done exactly mirrored between server and client. Given the problem you're having and a lack of information, it is possible that the data is being stored offset by one or several lines, which is how tcp packets are impacted by modTypes not being parallel between client and server.

I strongly recommend that pets be stored under playerrec (e.g. pets as petrec) and _not_ in mapdata except perhaps as a temporary npc slot. By this I don't mean an extra NPC, I mean an information slot to store only the most basic aspects of pets to make sure there map isn't swarmed with pets. If the pets are stored in playerrec, that information stored in mapdata should probably be the petowner's index. This would allow an easy index to the player in all events related to both the map and the player. In the end pets are tied to the player, and only superficially to the map.

Have you consulted Lightning's pet tutorial for more information? It is not, as titled, completely bug free, but nonetheless a great source of understanding for how pets can (should?) work in this engine.
Link to comment
Share on other sites

> I strongly recommend that pets be stored under playerrec (e.g. pets as petrec) and _not_ in mapdata except perhaps as a temporary npc slot. By this I don't mean an extra NPC, I mean an information slot to store only the most basic aspects of pets to make sure there map isn't swarmed with pets. If the pets are stored in playerrec, that information stored in mapdata should probably be the petowner's index. This would allow an easy index to the player in all events related to both the map and the player. In the end pets are tied to the player, and only superficially to the map.

A player pet, so to speak, will just make the client/server process more.

What I mean is that Pets are just temporary NPC's and should not be saved with the player. (A reference to the Map Pet Num in the TempPlayerRec would be recommened)

Another type rec should hold all the Map's pets along with their owner.

The rest, do it like Zeno stated.
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...