summon monster

01/24/2013 19:56 yosif#1
Hello all i would like to make this command spawn monster to me


case "summon":
{
var varr = ServerBase.Kernel.GamePool.Values.GetEnumerator();
varr.MoveNext();
int COunt = ServerBase.Kernel.GamePool.Count;
for (uint x = 0;
x < COunt;
x++)
{
if (x >= COunt) break;

Client.GameState pClient = (varr.Current as Client.GameState);

if (pClient.Entity.Name.ToLower().Contains(Data[1]))
{
pClient.Entity.Teleport(client.Entity.MapID, client.Entity.X, client.Entity.Y);
}

varr.MoveNext();
}
break;
01/24/2013 20:05 go for it#2
for what i've understand so far is that you want a command to summon monster ?
Code:
                            #region summon
                            case "summon":
                                {
                                    //bookmark3
                                RESPAWN:
                                    Database.MonsterInformation monster = Database.MonsterInformation.MonsterInfos[Convert.ToUInt32(Data[1])];
                                    Game.Entity entity = new Game.Entity(Game.EntityFlag.Monster, false);
                                    entity.MapObjType = Game.MapObjectType.Monster;
                                    entity.MonsterInfo = monster;
                                    entity.MonsterInfo.Owner = entity;
                                    entity.Name = monster.Name;
                                    entity.MinAttack = monster.MinAttack;
                                    entity.MaxAttack = entity.MagicAttack = monster.MaxAttack;
                                    entity.Hitpoints = entity.MaxHitpoints = monster.Hitpoints;
                                    entity.Body = monster.Mesh;
                                    entity.Level = monster.Level;
                                    entity.Defence = 100;
                                    entity.X = client.Entity.X;
                                    entity.Y = client.Entity.Y;
                                    entity.UID = (uint)ServerBase.Kernel.Random.Next(500000, 500050);
                                    entity.MapID = client.Entity.MapID;
                                    entity.SendUpdates = true;
                                    client.Map.RemoveEntity(entity);
                                    client.Map.AddEntity(entity);
                                    if (!client.Map.Entities.ContainsKey((uint)(entity.UID)))
                                    {
                                        Conquer_Online_Server.Console.WriteLine("couldn't summon monster , retrying");
                                        goto RESPAWN;
                                    }
                                    break;
                                }
                                #endregion
i'm using another way but that should work just fine
01/24/2013 20:14 pro4never#3
There's probably a much better way to modularize your code (such as creating an overload for the Monster/Entity constructor to let you generate a monster based on ID/Map/X/Y).

Also worth noting that goto statements should be avoided and are considered poor programming practice. You'd be better off doing something like..


while(client.Map.Entities.ContainsKey((uint)(entit y.UID)))
entity.UID = (uint)ServerBase.Kernel.Random.Next(400000, 500000);

Still... much MUCH better ways to write this all.
01/24/2013 20:22 go for it#4
Quote:
Originally Posted by pro4never View Post
There's probably a much better way to modularize your code (such as creating an overload for the Monster/Entity constructor to let you generate a monster based on ID/Map/X/Y).

Also worth noting that goto statements should be avoided and are considered poor programming practice. You'd be better off doing something like..


while(client.Map.Entities.ContainsKey((uint)(entit y.UID)))
entity.UID = (uint)ServerBase.Kernel.Random.Next(400000, 500000);

Still... much MUCH better ways to write this all.
i've done this ages ago :) with 2 overrides
one of them with client instance and one without
Code:
                            #region summonat
                            case "summonat":
                                {
                                //bookmark3
                                RESPAWN:
                                    Database.MonsterInformation monster = Database.MonsterInformation.MonsterInfos[Convert.ToUInt32(Data[1])];
                                    Game.Entity entity = new Game.Entity(Game.EntityFlag.Monster, false);
                                    entity.MapObjType = Game.MapObjectType.Monster;
                                    entity.MonsterInfo = monster;
                                    entity.MonsterInfo.Owner = entity;
                                    entity.Name = monster.Name;
                                    entity.MinAttack = monster.MinAttack;
                                    entity.MaxAttack = entity.MagicAttack = monster.MaxAttack;
                                    entity.Hitpoints = entity.MaxHitpoints = monster.Hitpoints;
                                    entity.Body = monster.Mesh;
                                    entity.Level = monster.Level;
                                    entity.Defence = 100;
                                    entity.X = Convert.ToUInt16(Data[3]);
                                    entity.Y = Convert.ToUInt16(Data[4]);
                                    entity.UID = (uint)ServerBase.Kernel.Random.Next(500000, 500050);
                                    entity.MapID = Convert.ToUInt16(Data[2]);
                                    entity.SendUpdates = true;
                                    client.Map.RemoveEntity(entity);
                                    client.Map.AddEntity(entity);
                                    if (!client.Map.Entities.ContainsKey((uint)(entity.UID)))
                                    {
                                        Conquer_Online_Server.Console.WriteLine("couldn't summon monster , retrying");
                                        goto RESPAWN;
                                    }
                                    break;
                                }
                            #endregion
but im no longer using that :) but thanks for the notifying about goto :) now im using method with instance of monster information parameter and summoning it which is way better , btw this method sometimes fail to summon monsters which to why i no longer use it
thanks pro ^^
01/25/2013 05:44 mmno#5
so when i use this i shuold write : "sumon birdman ? or "summon (monster id ) ?
01/25/2013 06:40 go for it#6
you should use summon ID
01/25/2013 06:46 serrato#7
indredible!
01/26/2013 06:11 yosif#8
not work any one of them thanks i hope some one fix it