Register for your free account! | Forgot your password?

You last visited: Today at 06:59

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

Advertisement



[Release] Npc spawning

Discussion on [Release] Npc spawning within the CO2 PServer Guides & Releases forum part of the CO2 Private Server category.

Reply
 
Old   #1
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,379
[Release] Npc spawning

Ok so this is sorta a mini/partial release. I'm tired and I really don't feel like finishing this (did conquer 1.0 not have blue mouse or is everything just fucked up on my end?...)

Anyways I wanted to finish up a blue mouse system for people but due to my own lazyness and stupidity I can't finish it up right now. Figured I may as well release what I have done for people to use.

THIS IS FOR COFUTURE CONQUER 1.0 SOURCE!

Co Emu will be virtually IDENTICAL, lotf will require a bit of conversion (you are welcome to do it if you want)

This is a simple way for people to add/remove npcs to their server while it's running via a command or have it used for npcs you want to move. Examples of uses would be...

-Blue mouse quest (as it exists on real co with randomly moving mice)
-Find the npc quest (random locations loaded from database. When used the npc jumps to a new location, etc)
-Having npcs only show up at certain times of days for events.

Or anything else you want really. Use some imagination!

Problem with current version: maybe I'm missing something but for the life of me I can't seem to de-spawn an npc client side unless I move my character. I'm sure it's simple enough but it's 3 am and I don't care to keep working on it (I've tried a few things... but w/e, no big deal)

Under Handlers>Functions.cs
Code:
public static void SpawnNpc(int id, int type, int subtype, int map, int x, int y, int direction, int flag)
        {//blabla
            {
                {
                    Struct.NPC NPC = new Struct.NPC();
                    NPC.Direction = direction;
                    NPC.Flag = flag;
                    NPC.ID = id;
                    NPC.Map = map;
                    NPC.SubType = subtype;
                    NPC.Type = type;
                    NPC.X = Convert.ToUInt16(x);
                    NPC.Y = Convert.ToUInt16(y);
                    if (Start.Npcs.ContainsKey(NPC.ID))
                    {
                        while (Start.Npcs.ContainsKey(NPC.ID))
                            NPC.ID = Start.Rand.Next(100, 10000);
                        Console.WriteLine("Npc Id in use, selected random id: " + NPC.ID);
                    }

                    Start.Npcs.Add(NPC.ID, NPC);
                    foreach (KeyValuePair<uint, COClient> Clients in Start.Clients)
                    {
                        if (Clients.Value.Char.Map == NPC.Map && Calculation.CanSee(NPC.X, NPC.Y, Clients.Value.Char.X, Clients.Value.Char.Y))
                        {
                            Spawn.All(Clients.Value, true);
                        }
                    }

                    Console.WriteLine("Successfuly added npc to server");


                }


            }
        }
So that's the spawn code for you as I currently have it. I was going to try to add custom npc names to it but again, lazy, late at night and I honestly forget how to do it.

Same area, simple despawn void for you

Code:
 public static void DespawnNpc(int RemovalType, int ID)
        {//blabla
            switch (RemovalType)
            {
                case 1://Npc Type
                    {
                        foreach (KeyValuePair<int, Struct.NPC> LoopId in Start.Npcs)
                        {
                            if (LoopId.Value.Type == ID)
                            {
                                Start.Npcs.Remove(LoopId.Value.ID);
                                Console.WriteLine("Found type in for each loop! " + Convert.ToInt32(LoopId.Value.Type));
                                break;
                            }
                        }
                        break;
                    }
                case 2://Npc Id
                    {
                        Start.Npcs.Remove(ID);
                        Console.WriteLine("Removed Npc ID: " + Convert.ToString(ID));
                        break;
                    }
            }

            
        }
note I have 2 types. That's because for the uid of npcs I used a random value and to find them again I wanted to be able to use their npc script Id #. I included the other one for if you want to do it that way. Either one should work just fine (just go offscreen and back on and it will be gone)

Annndd simple command to use ingame to test it.

Code:
if (Splitter[0] == "/addnpc")
                    {
                        int NpcUid = Start.Rand.Next(100, 10000);
                        Handler.SpawnNpc(NpcUid, Convert.ToInt32(Splitter[1]), Convert.ToInt32(Splitter[2]), Convert.ToInt32(Splitter[3]), Convert.ToInt32(Splitter[4]), Convert.ToInt32(Splitter[5]), 2, Convert.ToInt32(Splitter[6]));
                        return 2;
                    }
Code:
if (Splitter[0] == "/removenpc")
                    {
                        Handler.DespawnNpc(1, Convert.ToInt32(Splitter[1]));
                        return 2;
                    }
Implementation of the void is just that simple for any events, just use the Handler.NpcSpawn/DespawnNpc to control what is spawned where.


Anyways, hope some ppl enjoy it seeing as I'm never going to really use it.

Note: I just noticed when I was testing the early version of it... apparently I finished random events on my 1.0 server? wtf... I was playing and then it told me I missed my pk tournament. I didn't realize I ever finished that script :S
pro4never is offline  
Thanks
3 Users
Old 01/29/2010, 10:05   #2
 
coreymills's Avatar
 
elite*gold: 0
Join Date: Mar 2008
Posts: 555
Received Thanks: 99
nice work Pro
coreymills is offline  
Old 01/29/2010, 10:10   #3
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,379
Thanks,

If I get bored later I may combine this with my random scroll system to make an ACTUAL event/quest to find an npc (srsly... so many talk to npc A, bring item B to npc C for reward D quests on here...)

Anyways, that's off topic.
pro4never is offline  
Old 01/29/2010, 19:47   #4
 
CompacticCo's Avatar
 
elite*gold: 0
Join Date: Aug 2009
Posts: 424
Received Thanks: 108
Quote:
Originally Posted by pro4never View Post
Thanks,

If I get bored later I may combine this with my random scroll system to make an ACTUAL event/quest to find an npc (srsly... so many talk to npc A, bring item B to npc C for reward D quests on here...)

Anyways, that's off topic.
Nice, not going to be able to use this, but it's a great contribute.

Random question, who is that guy in your avatar?
CompacticCo is offline  
Old 01/29/2010, 19:54   #5

 
Kiyono's Avatar
 
elite*gold: 20
Join Date: Jun 2006
Posts: 3,296
Received Thanks: 925
Quote:
Originally Posted by CompacticCo View Post
Nice, not going to be able to use this, but it's a great contribute.

Random question, who is that guy in your avatar?
Michael Shanks?
Kiyono is offline  
Thanks
1 User
Old 01/29/2010, 20:08   #6
 
elite*gold: 0
Join Date: Feb 2009
Posts: 700
Received Thanks: 79
Shanks
copz1337 is offline  
Old 01/29/2010, 20:18   #7
 
elite*gold: 0
Join Date: Jan 2010
Posts: 116
Received Thanks: 33
Good job pro!
Jedex is offline  
Old 01/29/2010, 22:27   #8
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,379
Quote:
Originally Posted by CompacticCo View Post
Nice, not going to be able to use this, but it's a great contribute.

Random question, who is that guy in your avatar?
Yah, it's Michael Shanks, an actor.


@thread, I did end up writing this for CoEmu lastnight (actually I finished writing it into a random npc quest where every time you use the npc it bounces around the game world to random locations and gives out prizes)...

I may or may not release that at some point. After all this coding though I'm almost tempted to try to write a server again though. I really do miss having one >.<
pro4never is offline  
Reply


Similar Threads Similar Threads
Mob Spawning
01/02/2016 - Cabal Private Server - 5 Replies
Hello communty, Can one tell me how I can create in the game mobs. wenns goes with the id's Thanks in advance than in! MFG: <ZeroCool> GERMAN: Hallo kann mir vielleicht einer sagen wie ich im game mob spawne? und hat vielleicht jemand die idīs Danke als im vorraus."!"
[HELP]Spawning a NPC
05/24/2010 - CO2 Private Server - 3 Replies
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:
Need Spawning
12/19/2009 - Dekaron - 13 Replies
Hi Guys I Need Spawning Code :confused:
Spawning without losing exp?
01/15/2009 - Kal Online - 18 Replies
Hey I remmeber seeing somewhere a hack where you could spawn without losing exp (after dying) does anyone remmeber that and know if it still works.. if so how? :) thanks
Db spawning????
03/17/2008 - Conquer Online 2 - 2 Replies
Hi! I have 117 archer on eagle server, and i want to know , when the db spawns and what places ( min maks, thunder apes, sand elfs etc.) When is the server maintenances and how many hours i need to wait for db spawn on the right place:) Waiting for replies. Thank you.



All times are GMT +1. The time now is 07:00.


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.