How do you make a monster spawn with a command?

01/07/2010 04:58 dragon89928#1
Is there a way to spawn a monster with a command in game (instantly), maybe like Gano or Titan? Also is it possible to remove that monster after x amount of time? So far I have already gotten the Timer and spawned the monster on server start but I want to be able to command when I want to spawn the monster. Thanks.
01/07/2010 05:19 pro4never#2
I had a command working for tnpcs and stuff but I haven't done it for mobs (although they should be virtually identical)

I'd suggest looking at how it's being imported from the database and then replicate that through a command (it should be fairly simple involving setting the stats for the monster, sending the spawn packet and then updating the clients)

Just look at how it's done in the source already and then replicate that through a command.

Good luck!
01/07/2010 06:41 dragon89928#3
I tried doing that, I just made a new global var that held the monster/spawn points and tried calling it using an npc but it just barfed exceptions everywhere. So I am not too sure how to go about this. But ill check your command out, thanks.

Edited:
I finally got the monster to spawn. But now the problem is it wont move. Not only that but only the char on screen at that time can see it (if i jump off screen from the spawned monster it disappears). Any suggestions how to integrate it into the current mobs so that the new mobs will move?
01/08/2010 02:52 pro4never#4
Sounds like in the source you are using, spawning the monster is only the first step. You will still have to integrate the actual functionality of the mob (moving, attacking, etc)

You are successfully displaying the monster to clients onscreen by using the spawn packet (basically says to client "this mob is on screen with these stats") but you are not actually creating the monster in the source. You are on the right track but it sounds like you still need to add the monster to the source's monster handling code (again, atk/def/move etc)
01/08/2010 04:14 dragon89928#5
Oh yeah, im using the 5165 source. Apparently there's a /spawn command but that one writes to file which would defeat the purpose of spawning temporarily so I couldn't use that (in case people were wondering why i didnt use that in the first place).

And as for the packets, I can't seem to find the monster handling code x.x. Actually, I think i know where it is, I just don't know how to implement the method the way i wanted to. Because if I load mobs again I'm pretty sure it will load all the mobs all over again so there will be 2x the number of monsters just to spawn the 1 i wanted. This is so frustrating..
01/08/2010 04:25 copz1337#6
I think it would be pointless because it would require the server to restart I believe.
01/08/2010 04:42 spare2#7
Quote:
Originally Posted by copz1337 View Post
I think it would be pointless because it would require the server to restart I believe.
No he could simply make a command that sends a monster spawn packet.
01/08/2010 04:54 dragon89928#8
Quote:
Originally Posted by copz1337 View Post
I think it would be pointless because it would require the server to restart I believe.
you only need a server restart if you load it into mobinfo.txt. But doing that will let the monster spawn every time the server starts

Quote:
Originally Posted by spare2 View Post
No he could simple make a command that sends a monster spawn packet.
Which i cant find. >.>
01/08/2010 04:57 spare2#9
Which source are you using?
01/08/2010 05:48 dragon89928#10
im using 5165. i can make the mob show itself but only if youre on screen at that time.
01/08/2010 06:12 .Ryu#11
Hey dragon if you'll look right inside the 5165 source and look for this command to add a NPC
So try to configure it to spawn a monster it might help...
Goodluck

, Peace Combat
01/08/2010 06:42 dragon89928#12
Yep, thats how I was able to make the monster show on screen. It still doesn't move though :/ I'm thinking its along the lines of LoadMobs(); but I'm not too sure how to change it.
01/08/2010 06:44 spare2#13
Well either Gano nor Titan is in the original MobInfo.txt.
To spawn a mob I coded this, //needs testing, I never tested it nor compiled it, put this where the commands are.
Code:
                        if (Cmd[0] == "/spawnmob") //SYNTAX: "/spawnmob 35" This will spawn SnowApe at where you are standing.
                        {
                            if (Cmd.Length == 2)
                            {
                                string mob_line = null;
                                StreamReader SR = new StreamReader(@"C:\OldCODB\MobInfos.txt", true);
                                while (SR.EndOfStream != false)
                                {
                                    string read = SR.ReadLine();
                                    if (read.StartsWith(Cmd[1]))//MobID
                                    {
                                        mob_line = read;
                                        break;
                                    }
                                }
                                if (mob_line != null)
                                {
                                    Game.Mob mob = new Game.Mob(mob_line);
                                    mob.Loc.X = (ushort)(GC.MyChar.Loc.X - 1);
                                    mob.Loc.Y = (ushort)(GC.MyChar.Loc.Y - 1);
                                    GC.AddSend(Packets.SpawnEntity(mob));
                                    GC.AddSend(Packets.ChatMessage(0, "SYSTEM", GC.MyChar.Name, mob.Name + " has been spawned!", 2001, 0));
                                }
                            }

                        }
To find the MobID, go to MobInfos.txt and find the name of the monster, the number before it is the mob ID. Tell me if it doesn't work I'll try to fix it.
Edit: This should spawn the mob right away without restart.
01/08/2010 06:55 dragon89928#14
hmm that looks like what i coded x.x but ill try it ill get back to you :p

edit:
Yep its the same as what I did, the monster spawns but its just there. Once you go off screen it just disappears >.<
01/08/2010 07:12 spare2#15
Quote:
Originally Posted by dragon89928 View Post
hmm that looks like what i coded x.x but ill try it ill get back to you :p

edit:
Yep its the same as what I did, the monster spawns but its just there. Once you go off screen it just disappears >.<
I know why, you have to add it to the mob hashtable so that way it gets processed through the Mob thread.
I'll do it tomorrow.
P.S. It's my first time working with this source so I don't exactly know it inside out yet.