zomb88 Posted April 30, 2013 Author Share Posted April 30, 2013 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 More sharing options...
abhi2011 Posted April 30, 2013 Share Posted April 30, 2013 The sub please. Link to comment Share on other sites More sharing options...
zomb88 Posted April 30, 2013 Author Share Posted April 30, 2013 ```Private Sub HandleSpawnNpc(ByVal Index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)Dim n As LongDim 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 SubErrorHandler: HandleError "HandleSpawnNpc", "modHandleData", Err.Number, Err.Description, Err.Source, Err.HelpContext Err.Clear Exit SubEnd 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 More sharing options...
abhi2011 Posted April 30, 2013 Share Posted April 30, 2013 Does the values of the other variables exist or does the pet values get wiped? Link to comment Share on other sites More sharing options...
zomb88 Posted April 30, 2013 Author Share Posted April 30, 2013 Yea they still exist just after the handlespawnnpc sub they go back to 0 or vbnullstring Link to comment Share on other sites More sharing options...
Lavos Posted April 30, 2013 Share Posted April 30, 2013 Not too sure how your pet system works, but with handling strings using vbnullstring is better than 0. Link to comment Share on other sites More sharing options...
escfoe2 Posted April 30, 2013 Share Posted April 30, 2013 Write down every major sub that uses '.Pet.Name' and '.Pet.Owner'Once you've done that, narrow down the ones that change it's values.Once you've done that, post what you have left here. Link to comment Share on other sites More sharing options...
zomb88 Posted May 1, 2013 Author Share Posted May 1, 2013 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 More sharing options...
escfoe2 Posted May 1, 2013 Share Posted May 1, 2013 > 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 sureThat'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/functionsIf done correctly, I can help you. Link to comment Share on other sites More sharing options...
abhi2011 Posted May 1, 2013 Share Posted May 1, 2013 Or just break execution after the packet is handled and run the client line by line. (Skipping lines that are in loops and stuff.)Edit: to do this press f8 Link to comment Share on other sites More sharing options...
zomb88 Posted May 1, 2013 Author Share Posted May 1, 2013 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 LongDim Y As LongDim i As LongDim NeedMap As ByteDim buffer As clsBuffer' If debug mode, handle error then exit outIf Options.Debug = 1 Then On Error GoTo ErrorHandlerGettingMap = TrueSet buffer = New clsBufferbuffer.WriteBytes Data()' Erase all players except selfFor i = 1 To MAX_PLAYERSIf i <> MyIndex ThenCall SetPlayerMap(i, 0)End IfNext' Erase all temporary tile valuesCall ClearMapNpcsCall ClearMapItemsCall ClearMap' clear the bloodFor i = 1 To MAX_BYTEBlood(i).X = 0Blood(i).Y = 0Blood(i).Sprite = 0Blood(i).timer = 0Next' Get map numX = buffer.ReadLong' Get revisionY = buffer.ReadLongIf FileExist(App.Path & MAP_PATH & "map" & X & MAP_EXT) ThenCall LoadMap(X)' Check to see if the revisions matchNeedMap = 1If Map.Revision = Y Then' We do so we dont need the mapNeedMap = 0End IfElseNeedMap = 1End If' Either the revisions didn't match or we dont have the map, so we need itSet buffer = New clsBufferbuffer.WriteLong CNeedMapbuffer.WriteLong NeedMapSendData buffer.ToArray()Set buffer = Nothing' Check if we get a map from someone else and if we were editing a map cancel it outIf InMapEditor ThenInMapEditor = FalsefrmEditor_Map.visible = FalseClearAttributeDialogueIf frmEditor_MapProperties.visible ThenfrmEditor_MapProperties.visible = FalseEnd IfEnd If' Error handlerExit SubErrorHandler:HandleError "HandleCheckForMap", "modHandleData", Err.Number, Err.Description, Err.Source, Err.HelpContextErr.ClearExit SubEnd 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 More sharing options...
zomb88 Posted May 1, 2013 Author Share Posted May 1, 2013 Currently i have it working with saving just one pet value to the map file however is there a better way to handle this Link to comment Share on other sites More sharing options...
escfoe2 Posted May 6, 2013 Share Posted May 6, 2013 Just ONE pet value? What is ONE pet value consisted of? Link to comment Share on other sites More sharing options...
zomb88 Posted May 6, 2013 Author Share Posted May 6, 2013 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 More sharing options...
abhi2011 Posted May 6, 2013 Share Posted May 6, 2013 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 More sharing options...
zomb88 Posted May 6, 2013 Author Share Posted May 6, 2013 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 More sharing options...
abhi2011 Posted May 6, 2013 Share Posted May 6, 2013 Don't make pets as NPCs. Other than keeping their data as NPC's don't do anything that is related to actual NPC's. Link to comment Share on other sites More sharing options...
Zeno Posted May 6, 2013 Share Posted May 6, 2013 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 More sharing options...
abhi2011 Posted May 7, 2013 Share Posted May 7, 2013 > 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 More sharing options...
zomb88 Posted May 7, 2013 Author Share Posted May 7, 2013 Made some nessessary changes and have it working.Thanks for the insight. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now