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;
}
}