[HELP]Spawning a NPC

05/22/2010 19:48 ryuchetval#1
Hey guys I was wondering if you can help me to spawn a single NPC like this...
I'm using LOTF 5017...

I'm trying to add Blue Mouse Quest and spawn the Blue Mouses....

What I know:

Spawn the mob(s) at a certain time after click.

What I don't know:

Remove the mob after the click.

Can anybody help me?:)
Thanks
05/22/2010 20:09 pro4never#2
You will need to write a npc spawn function... There is one for CoEmu in my random treasure hunt quest (both spawning and removal including other checks/random spawn locations) but that was for coemu... still a good example though.

Basically you will need to create a function that has inputs for mesh/id number/name/map/x/y for the npc you want to spawn and then use your npc spawn packet (look at where npcs are being loaded from the database in your source and then use that to find where your actual npc spawn code is.

From what I remember the easiest way to keep track of it would be to create a dictionary or hashtable to store the bluemouse Id/Uid's.. that way they are easier to track how many you have and remove them as needed (cause UID generation is random and that's one of the easy ways to remove the npc)

Then write another one for removal. I think it's just a matter of sending the entity remove packet, removing it from the servers npc dictionary (and bluemouse dictionary if you use that as well) and then update clients that were nearby it when it was removed.

Then just do your normal scripting for the npc and run a little thing on server startup to generate the bluemice where you want them.

Ooh and a random coord system to control where the bluemice can spawn in the mines (I have released that already in both it's own thread (random scrolls) and in my treasure hunt system... again.. coemu though) Or if you want fully random coords just write a random location system using the dmap checker.. those are lots of fun ^^
05/23/2010 09:17 ryuchetval#3
I found a friend that helped me with this and the ideeas are kinda the same

but thanks anyway :)
05/24/2010 00:14 Arcо#4
Code:
        public static Game.NPC SpawningNPC;
        public static void SpawnNPC()
        {
            string line = "8005 887 2 0 1036 162 168";
            SpawningNPC = new Game.NPC(line);
            Game.World.H_NPCs.Add(SpawningNPC.EntityID, SpawningNPC);
            Packets.SpawnNamedNPC(SpawningNPC, "SpawnedNPC");
        }
        public static void SendNPC(int x, int y)
        {
            foreach (Game.NPC N in Game.World.H_NPCs.Values)
            {
                if (N.EntityID == Convert.ToUInt16(8005))
                {
                    N.Loc.X = (ushort)x;
                    N.Loc.Y = (ushort)y;
                    Game.World.Spawn(N);
                    foreach (Game.Character C in Game.World.H_Chars)
                    {
                        C.MyClient.AddSend(Packets.SpawnNPC(N));
                        Game.World.Spawns(C, false);
                    }
                }
            }
        }
Here's something that might help.