Metode to remove a SobNPC

12/04/2012 02:50 zakkwilde_17#1
well guys... i'm here again... well... i have a little problem here... I need to do a method to remove a sobnpc when it have no Hitpoints... I have tryed alot of times and do some tests and don't got sucess...

My method to create a sobnpc working fine...

Creating a SobNPC...
Code:
                    SobNpcSpawn agility = new SobNpcSpawn
                    {
                        Name = "FlagTeste",
                        UID = 10105,
                        MapID = 1002,
                        X = 449,
                        Y = 449,
                        MaxHitpoints = 100000,
                        Hitpoints = 100000,
                        Mesh = 11150,
                        Type = Enums.NpcType.Stake
                    };
                    Kernel.Maps[(ushort)1002].AddNpc(agility);
Code:
public void AddNpc(INpc npc)
        {
            if (!this.Npcs.ContainsKey(npc.UID))
            {
                this.Npcs.Add(npc.UID, npc);
                this.Floor[npc.X, npc.Y, MapObjectType.InvalidCast, npc] = false;
                if (((npc.Mesh / 10) != 0x6c) && (npc.Type < ((Enums.NpcType)10)))
                {
                    ushort x = npc.X;
                    ushort y = npc.Y;
                    foreach (Enums.ConquerAngle angle in Angles)
                    {
                        ushort num3 = x;
                        ushort num4 = y;
                        UpdateCoordonatesForAngle(ref num3, ref num4, angle);
                        this.Floor[num3, num4, MapObjectType.InvalidCast, null] = false;
                    }
                }
            }
        }
Remove NPC code
Code:
                if (((attacker.MapID == 1002) && (attacked.UID == 10105)) && (attacked.Hitpoints <= damage))
                {
                    attacked.Hitpoints = 0;
                    SobNpcSpawn agility = new SobNpcSpawn
                    {
                        Name = "FlagTeste",
                        UID = 10105,
                        MapID = 1002,
                        X = 449,
                        Y = 449,
                        MaxHitpoints = 100000,
                        Hitpoints = attacked.Hitpoints,
                        Mesh = 11150,
                        Type = Enums.NpcType.Stake
                    };
                    Kernel.Maps[(ushort)1002].Removenpc(agility);

                }
The remove method is that
Code:
public void Removenpc(INpc npc)
        {
            if (this.Npcs.ContainsKey(npc.UID))
            {
                this.Npcs.Remove(npc.UID);
                this.Floor[npc.X, npc.Y, MapObjectType.InvalidCast, npc] = true;
                if (((npc.Mesh / 10) != 0x6c) && (npc.Type < ((Enums.NpcType)10)))
                {
                    ushort x = npc.X;
                    ushort y = npc.Y;
                    foreach (Enums.ConquerAngle angle in Angles)
                    {
                        ushort num3 = x;
                        ushort num4 = y;
                        UpdateCoordonatesForAngle(ref num3, ref num4, angle);
                        this.Floor[num3, num4, MapObjectType.InvalidCast, null] = true;
                    }
                }
            }
        }
That code to remove work to remove the npc from dictionary... But the sobnpc don't remove from screen... Someone can help here?
12/04/2012 10:34 pro4never#2
Doesn't look like you're sending a removal packet.

It's a general data subtype using the object UID to remove from clients still on the screen.
12/04/2012 15:31 |xabi|#3
Quote:
Originally Posted by pro4never View Post
Doesn't look like you're sending a removal packet.

It's a general data subtype using the object UID to remove from clients still on the screen.
when i use the general data subtype it removes the npc and i go some where and go back to the removal npc it doesn't remove !!
12/04/2012 15:55 _DreadNought_#4
Screen.
12/04/2012 16:44 zakkwilde_17#5
yep... i do it at screen:

Code:
if ((buffer.UID == 10105) && Crystals.AgilityCrystal == false)
                                        {
                                            foreach (IMapObject obj3 in this.Objects)
                                            {
                                                if ((obj3 != null) && (obj3.MapObjType == MapObjectType.Player))
                                                {
                                                    (obj3 as Entity).Owner.Send(buffer);
                                                    (obj3 as Entity).Owner.Screen.Remove(buffer);
                                                }
                                            }
                                            this.Owner.Map.Floor[buffer.X, buffer.Y, MapObjectType.SobNpc, null] = true;
                                            list.Add(buffer);
                                        }
it do a partial remove... can't attack the npc, and the npc disappears... But when i walk i can see the npc appearing and disappearing... so... the npc does not disappear completely.
12/05/2012 01:23 pro4never#6
there's 3 stages

#1: Send any packets relating to the npc (damage packets, etc)
#2: Remove/move the npc in your map code (so new users don't have it added to their screen)
#3: Remove it from users currently on the screen

You're obviously not doing #2 if it shows up again when you leave and come back. The ONLY way that can happen is if you're re sending the spawn packet to the client. That would be handled by your map code.
12/05/2012 16:35 _DreadNought_#7
If it's going then coming back you're not removing it from somewhere...
12/06/2012 04:57 zakkwilde_17#8
Quote:
Originally Posted by _DreadNought_ View Post
If it's going then coming back you're not removing it from somewhere...
The NPC is being removed from the dictionary of NPC ... That's right ... most of the screen, it refuses to leave ... I tested many things ... I'm already discouraged x.x

you have no idea what can be added for this to work?
12/06/2012 06:31 pro4never#9
It's literally not possible that the npc is not being referenced by your map code and yet when you come back on the screen it re-appears.

That's like saying "I moved my car out of my driveway but when I look in my driveway it's still there".
12/06/2012 16:42 zakkwilde_17#10
Quote:
Originally Posted by pro4never View Post
It's literally not possible that the npc is not being referenced by your map code and yet when you come back on the screen it re-appears.

That's like saying "I moved my car out of my driveway but when I look in my driveway it's still there".
That's the class to remove from screen... Can u check if something is wrong?

Code:
        
public bool Remove(IMapObject _object)
        {
            try
            {
                try
                {
                    if (this._objects.ContainsKey(_object.UID))
                    {
                        if (_object.MapObjType == MapObjectType.Item)
                        {
                            FloorItem item = _object as FloorItem;
                            item.Type = 2;
                            item.SendSpawn(this.Owner, false);
                            item.Type = 1;
                        }
                        else if (_object.MapObjType == MapObjectType.Player)
                        {
                            Data buffer = new Data(true)
                            {
                                UID = _object.UID,
                                ID = 0x87
                            };
                            this.Owner.Send(buffer);
                        }
                        else if (_object.MapObjType == MapObjectType.SobNpc)
                        {
                            Data data2 = new Data(true)
                            {
                                UID = _object.UID,
                                ID = 0x87
                            };
                            this.Owner.Send(data2);
                        }
                        this._objects.Remove(_object.UID);
                        this.UpdateArray();
                        return true;
                    }
                }
                catch
                {
                }
            }
            finally
            {
            }
            return false;
        }
12/06/2012 23:57 _DreadNought_#11
That looks fine, but I bet you there's a dictionary that still contains it and therefor your screen system read that and throw it back into your screen.

--Also I noticed that method is a bool, Tried doing if (Remove(obh)) { Console.Write("removed"); else { console.write("yoo no work"); }

hm?

Also... Breakpointing will solve your ENTIRE issue, it's not coding so you have no excuse such as "I don't know how to use it..." It's literally a few clicks ... [Only registered and activated users can see links. Click Here To Register...]

Everything you need to know, figure it out (should take a good 30 minutes to learn the basics and solve ur issue)... As I said it's no coding so you have no excuse to come back and say help i dont know how.
12/24/2012 02:51 zakkwilde_17#12
it can be closed... i have fixed it. tnx alot
12/24/2012 04:07 JohnHeatz#13
#Closed as requested