Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Programming
You last visited: Today at 09:18

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



WTF? NPC/Map Help...

Discussion on WTF? NPC/Map Help... within the CO2 Programming forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
LepEatWorld's Avatar
 
elite*gold: 0
Join Date: Apr 2017
Posts: 76
Received Thanks: 25
WTF? NPC/Map Help...

As you can see, it'll update the NPC in the Database and for each player. If the map refreshes it will re-update the NPC back to the original view for the player. Also, weirdly enough, it'll add the same NPC to each map to it's original 1st location added:


Working on adding the Guild Controller scrolls into the source but, I'm getting this weird issue: I can add the NPC with the same UID to every map that the NPC does not exist in. It only updates to one map on the database, so it's not like it's making multiple. It's the same NPC with the same code.

This is the script I'm currently working with, it was from an example of Furniture from another source that I had lying around:
Code:
if (client.HasItem(720021))
                    {
                        client.DeleteItem(720021);
                        var _newNPC = new DbNpc()
                        {
                            UID = 102093,
                            Type = (NpcType)2,
                            Mesh = look,
                            X = packet.DataLow,
                            Y = packet.DataHigh,
                            Map = client.MapID
                        };
                        ServerDatabase.Context.Npcs.AddOrUpdate(_newNPC);
                        client.Map.Insert(new Npc(_newNPC));
                    }
                    break;
Code:
public Npc(DbNpc _npc)
        {
            BaseNpc = _npc;
            UID = _npc.UID;
            Location = new Point(_npc.X, _npc.Y);
            SpawnPacket = SpawnNpcPacket.Create(this);
            foreach (var player in PlayerManager.Players.Values)
            {
                player.Send(SpawnPacket);
            }
        }
Code:
public static SpawnNpcPacket Create(Npc _npc)
        {
            var packet = new SpawnNpcPacket();
            packet.UID = _npc.UID;
            packet.X = _npc.X;
            packet.Y = _npc.Y;
            packet.Mesh = _npc.Mesh;
            packet.Type = _npc.Type;
            if (_npc.Name != null && _npc.Name.Length > 0)
            {
                packet.Name = new NetStringPacker();
                packet.Name.AddString(_npc.Name);
            }

            return packet;
        }
LepEatWorld is offline  
Old 11/27/2022, 04:20   #2
 
Arcо's Avatar
 
elite*gold: 0
Join Date: Oct 2009
Posts: 8,778
Received Thanks: 5,299
Without looking at the code, it can be that the collection containing your NPCs isn't updating. Can we see your Map.Insert(Npc) function?
Arcо is online now  
Old 11/27/2022, 06:06   #3
 
LepEatWorld's Avatar
 
elite*gold: 0
Join Date: Apr 2017
Posts: 76
Received Thanks: 25
Quote:
Originally Posted by Arcо View Post
Without looking at the code, it can be that the collection containing your NPCs isn't updating. Can we see your Map.Insert(Npc) function?
Code:
        public bool Insert(ILocatableObject obj)
        {
            if (obj == null)
                return false;
            if (Objects.ContainsKey(obj.UID))
                return false;
            obj.Map = this;
            Objects.TryAdd(obj.UID, obj);
            return true;
        }
LepEatWorld is offline  
Old 11/27/2022, 07:14   #4
 
elite*gold: 80
Join Date: Sep 2007
Posts: 642
Received Thanks: 168
Code:
        public bool Insert(ILocatableObject obj)
        {
            if (obj == null)
                return false;
            if (Objects.ContainsKey(obj.UID))
                return false;
            obj.Map = this;
            Objects.TryAdd(obj.UID, obj);
            return true;
        }
I''m going to guess this returns false when you call it from the following (because it already exists):
Code:
if (client.HasItem(720021))
                    {
                        client.DeleteItem(720021);
                        var _newNPC = new DbNpc()
                        {
                            UID = 102093,
                            Type = (NpcType)2,
                            Mesh = look,
                            X = packet.DataLow,
                            Y = packet.DataHigh,
                            Map = client.MapID
                        };
                        ServerDatabase.Context.Npcs.AddOrUpdate(_newNPC);
                        client.Map.Insert(new Npc(_newNPC));
                    }
                    break;
Santa is offline  
Old 11/27/2022, 15:29   #5
 
LepEatWorld's Avatar
 
elite*gold: 0
Join Date: Apr 2017
Posts: 76
Received Thanks: 25
Quote:
Originally Posted by Santa View Post
I''m going to guess this returns false when you call it from the following (because it already exists):
Correct, I didn't realize until Arco pointed out the ContainsKey part. I got it working now, although I'm not too sure if this is the best solution to the project.
I added the following to the normal script:
Code:
foreach (var maps in MapManager.ActiveMaps.Values)
    maps.Remove(new Npc(_newNPC));
I tried to use a AddOrUpdate instead of a Insert but it wasn't working out for me, I'll need to look into why exactly it wasn't working at a later time. I also tried to put a Objects.TryUpdate inside the Insert method where the Object exist, but the same issue was occuring, so I gave up and decided to just remove and re-add rather than update.

Thank you both for the insight and if you have a better way of dealing with this I'd love to learn about it.
LepEatWorld is offline  
Reply


Similar Threads Similar Threads
Darkorbit ??? Graveyard map (Secret map - Bonus map) Mini game
12/22/2017 - DarkOrbit - 0 Replies
It's a little game. The story is on the secret map. ScreenShots http://prntscr.com/hr7a5b http://prntscr.com/hr7ayz http://prntscr.com/hr7baz http://prntscr.com/hr7a5b http://prntscr.com/hr7ayz http://prntscr.com/hr7baz LINK
Npc platzieren auf einer Map - NPC wird nie angezeigt?
04/16/2012 - Metin2 Private Server - 3 Replies
Npc.txt: n 96 82 0 0 0 0 5s 0 1 20087 So geht es auch nicht: m 96 82 0 0 0 0 5s 0 1 20087 Der NPC steht einfahc nicht bei den Kordis, habe schon alles versucht Bitte um Hilfe :>
Tele hack from map to map? or to higher lvl map?
01/19/2010 - Dekaron - 7 Replies
im lvl 84.. is there anyway i could go to maps higher than my level?.. im in dekaron SEA.. like, tomb of black dragon.. or whatever, higher level map..
[Help] I need help on knowing how to Create a Teleport NPC in a New Map.
05/20/2009 - EO PServer Hosting - 5 Replies
Hey Guys i was woundering if somebody Knows how to create a Teleport NPC for a New Map i made.



All times are GMT +1. The time now is 09:18.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.