Need help with Richard Type NPC with random teleport

01/17/2013 23:32 hacksaw#1
Been trying to make an NPC like the Richard Quest where when you click him he will teleport to a random position on the map.
So far i have got it so that when you click the NPC he gives you a prize and then respawns in a new random position, The previous NPC is no longer active but never dissapears from the map, This happens for all new NPCs that it spawns.
The code im using is below, Can anyone help as to why the NPCs never dissapear?

Code:
                case 5012:
                    if (npcRequest.OptionID == 0)
                    {
                        INpc npc3;
                        if (Kernel.Rate(9))
                        {
                            client.Inventory.Add(0xb2396, 6, 1);
                            Kernel.SendWorldMessage(new Message(" " + client.Entity.Name + " as found the Box 1!!", System.Drawing.Color.White, 0x7e5), Kernel.GamePool.Values);
                            npc3 = new NpcSpawn
                            {
                                UID = 5012,
                                Mesh = 9307,
                                Type = Enums.NpcType.Talker,
                                X = (ushort)Program.BoxX,
                                Y = (ushort)Program.BoxY,
                                MapID = 1002
                            };
                            Kernel.Maps[(ushort)1002].RemoveEntity(npc3);
                            npc2 = new NpcSpawn
                            {
                                UID = 5012,
                                Mesh = 9307,
                                Type = Enums.NpcType.Talker,
                                X = 558,
                                Y = 325,
                            };
                            Program.BoxX = npc2.X;
                            Program.BoxY = npc2.Y;
                            npc2.MapID = 1002;
                            Kernel.Maps[(ushort)1002].AddNpc(npc2);
                        }
                        else if (Kernel.Rate(9))
                        {
                            client.Inventory.Add(0xb2396, 6, 1);
                            Kernel.SendWorldMessage(new Message("Congratulations, " + client.Entity.Name + " has found the Box 2!", System.Drawing.Color.White, 0x7e5), Kernel.GamePool.Values);
                            npc3 = new NpcSpawn
                            {
                                UID = 5012,
                                Mesh = 9307,
                                Type = Enums.NpcType.Talker,
                                X = (ushort)Program.BoxX,
                                Y = (ushort)Program.BoxY,
                                MapID = 1002
                            };
                            Kernel.Maps[(ushort)1002].RemoveEntity(npc3);
                            npc2 = new NpcSpawn
                            {
                                UID = 5012,
                                Mesh = 9307,
                                Type = Enums.NpcType.Talker,
                                X = 570,
                                Y = 267,
                            };
                            Program.BoxX = npc2.X;
                            Program.BoxY = npc2.Y;
                            npc2.MapID = 1002;
                            Kernel.Maps[(ushort)1002].AddNpc(npc2);
                        }
                        else if (Kernel.Rate(9))
                        {
                            client.Inventory.Add(0xb2396, 6, 1);
                            Kernel.SendWorldMessage(new Message("Congratulations, " + client.Entity.Name + " has found the Box 3!", System.Drawing.Color.White, 0x7e5), Kernel.GamePool.Values);
                            npc3 = new NpcSpawn
                            {
                                UID = 5012,
                                Mesh = 9307,
                                Type = Enums.NpcType.Talker,
                                X = (ushort)Program.BoxX,
                                Y = (ushort)Program.BoxY,
                                MapID = 1002
                            };
                            Kernel.Maps[(ushort)1002].RemoveEntity(npc3);
                            npc2 = new NpcSpawn
                            {
                                UID = 5012,
                                Mesh = 9307,
                                Type = Enums.NpcType.Talker,
                                X = 518,
                                Y = 320,
                            };
                            Program.BoxX = npc2.X;
                            Program.BoxY = npc2.Y;
                            npc2.MapID = 1002;
                            Kernel.Maps[(ushort)1002].AddNpc(npc2);
                        }
                    }
                    break;

Code:
        public void RemoveEntity(INpc npc)
        {
            if (this.Npcs.ContainsKey(npc.UID))
            {
                this.Npcs.Remove(npc.UID);
                this.Floor[npc.X, npc.Y, MapObjectType.Npc, npc] = true;
            }
        }
01/18/2013 04:23 pro4never#2
If you go offscreen and then back onto it is the old npc gone? if so then you are removing it server side and just need to inform local clients by sending a remove entity subtype of the general action packet (10010 I think subtype was 127 or something?) and that should solve your problem.

Check that this.Npcs.Remove is locating, removing and updating all local clients to the removal. That's prob where the issue lays.
01/18/2013 12:15 hacksaw#3
No the NPC's never dissapear at all, They all stay untill the server is restarted.