Guards attack Blue-Name players on just about every server, but other than my server I have only seen one or two where the guards attack other mobs. So Here is what you have to do to make guards attack mobs:
Note: if you cannot find part of what I have you search for, you are probably using a suckier and much more out-of-date source... or you are using a newer "better" source like Future\Reloaded.. My original source was ShadowCo, though it is much more updated now, and I suggest starting with this. It is very stable, and once you get used to it, easy to navigate.
First go into your Entities.cs file and find
In that block you will find:
(if you have a server with moving mobs, if not.. You'll need to write in a Move() Function, CharNearest() function, and a MobUseSkill() Function.. Come back when you have done this. (You can write some of that based on what you'll be adding)
Here in this release\guide I would like to note: this is not the best way to do this, I split it up and made it longer and less efficient to make it simpler for idiots to do. Now we continue:
replace the afformentioned code with:
now scroll up to
scroll down a bit till you find
and replace it with
Now find your Move() Function and go right under it (after the Move() block is closed off completely (}))
and add this function
Almost done.
Next, go to Packets.cs and find
after that block is closed off (}) add the following:
Next! go to your Other.cs file, and find
after THAT block is closed of (})
add:
And that's it! Recompile and restart your server and attract some Mobs to your gaurd!
optional: if you add a value to SingleMob.GetDamage() for enabling\disabling drops you can make guard-killed Mobs not drop items.
P.S:
at the end of your public bool GetDamage(uint Damage) { block for your single mobs you may want to change
to
just the sake of making sure whenever a mob dies, it actually falls over and dies, instead of standing there and fading away in place
Note: if you cannot find part of what I have you search for, you are probably using a suckier and much more out-of-date source... or you are using a newer "better" source like Future\Reloaded.. My original source was ShadowCo, though it is much more updated now, and I suggest starting with this. It is very stable, and once you get used to it, easy to navigate.
First go into your Entities.cs file and find
Code:
public void TimerElapsed(object source, ElapsedEventArgs e) {
Code:
if (Target != null) Move();
Here in this release\guide I would like to note: this is not the best way to do this, I split it up and made it longer and less efficient to make it simpler for idiots to do. Now we continue:
replace the afformentioned code with:
Code:
if (Target != null) { Move(); } else if (MType == 1) { Tgt = Other.MobNearest((uint)PosX, (uint)PosY, (uint)Map); if (Tgt != null && Tgt.Alive == true && Tgt.MType != 1 && MyMath.PointDistance(PosX, PosY, Tgt.PosX, Tgt.PosY) <= 10) Move2(); }
Code:
public class SingleMob { public short PosX; public short PosY;
Code:
Character Target = null;
Code:
Character Target = null; SingleMob Tgt = null;
and add this function
Code:
public void Move2() { LastMove = DateTime.Now; int DMG = General.Rand.Next(Convert.ToInt32(MinAtk), Convert.ToInt32(MaxAtk)); if (DMG < 1) DMG = 1; DMG *= 5; Tgt.GetDamage((uint)DMG); foreach (DictionaryEntry DE in World.AllChars) { Character Charr = (Character)DE.Value; if (Charr.MyClient.Online) if (MyMath.CanSeeBig(PosX, PosY, Charr.LocX, Charr.LocY)) { Charr.MyClient.SendPacket(General.MyPackets.MobSkillUse2(this, Tgt, (uint)DMG, 1320, 2)); } } Tgt = null; }
Next, go to Packets.cs and find
Code:
public byte[] MobSkillUse(SingleMob Mob, Character Attacked, uint DMG, ushort SkillId, byte SkillLevel) {
Code:
public byte[] MobSkillUse2(SingleMob Mob, SingleMob Attacked, uint DMG, ushort SkillId, byte SkillLevel) { ushort PacketType = 1105; byte[] Packet = new byte[32]; fixed (byte* p = Packet) { *((ushort*)p) = (ushort)Packet.Length; *((ushort*)(p + 2)) = (ushort)PacketType; *((uint*)(p + 4)) = (uint)Mob.UID; *((ushort*)(p + 8)) = (ushort)Attacked.PosX; *((ushort*)(p + 10)) = (ushort)Attacked.PosY; *((ushort*)(p + 12)) = (ushort)SkillId; *((ushort*)(p + 14)) = (ushort)SkillLevel; *(p + 16) = 1; *((uint*)(p + 20)) = (uint)Attacked.UID; *((uint*)(p + 24)) = (uint)DMG; } return Packet; }
Code:
public static Character CharNearest(uint X, uint Y, uint Map, bool Blue) {
add:
Code:
public static SingleMob MobNearest(uint X, uint Y, uint Map) { try { int ShortestDist = 30; SingleMob NearestMob = null; foreach (DictionaryEntry DE in Mobs.AllMobs) { SingleMob MOB = (SingleMob)DE.Value; if (MyMath.PointDistance(X, Y, MOB.PosX, MOB.PosY) < ShortestDist && MOB.MType != 1 && MOB.Alive && MOB.Map == Map) { NearestMob = MOB; ShortestDist = MyMath.PointDistance(X, Y, MOB.PosX, MOB.PosY); } } return NearestMob; } catch (Exception Exc) { General.WriteLine(Exc.ToString()); return null; } }
And that's it! Recompile and restart your server and attract some Mobs to your gaurd!
optional: if you add a value to SingleMob.GetDamage() for enabling\disabling drops you can make guard-killed Mobs not drop items.
P.S:
at the end of your public bool GetDamage(uint Damage) { block for your single mobs you may want to change
Code:
return true;
Code:
this.Death = DateTime.Now; World.MobDissappear(this); return true;