[Guide\Release]Guards attack mobs

09/15/2008 13:17 Rechocto#1
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
Code:
public void TimerElapsed(object source, ElapsedEventArgs e)
{
In that block you will find:
Code:
            if (Target != null)
                Move();
(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:
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();
            }
now scroll up to
Code:
    public class SingleMob
    {
        public short PosX;
        public short PosY;
scroll down a bit till you find

Code:
        Character Target = null;
and replace it with
Code:
        Character Target = null;
        SingleMob Tgt = null;
Now find your Move() Function and go right under it (after the Move() block is closed off completely (}))

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;
        }
Almost done.

Next, go to Packets.cs and find
Code:
        public byte[] MobSkillUse(SingleMob Mob, Character Attacked, uint DMG, ushort SkillId, byte SkillLevel)
        {
after that block is closed off (}) add the following:

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;
        }
Next! go to your Other.cs file, and find

Code:
        public static Character CharNearest(uint X, uint Y, uint Map, bool Blue)
        {
after THAT block is closed of (})

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;
to
Code:
                this.Death = DateTime.Now;
                World.MobDissappear(this);
                return true;
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
09/16/2008 13:12 Zanzibar#2
Er.. Nice job..
09/16/2008 13:17 keving#3
ty dude i was workingon it but now ty :)

:handsdown::handsdown::handsdown::handsdown: :handsdown::handsdown::handsdown::handsdown: :handsdown::handsdown::handsdown::handsdown: :handsdown::handsdown::handsdown::handsdown: :handsdown::handsdown::handsdown:
:handsdown::handsdown::handsdown::handsdown: :handsdown::handsdown::handsdown::handsdown: :handsdown::handsdown::handsdown::handsdown: :handsdown::handsdown::handsdown::handsdown: :handsdown::handsdown::handsdown:
09/16/2008 13:21 Zanzibar#4
Uh.. This takes up a lot of memory lawl
09/16/2008 13:31 Rechocto#5
Quote:
Originally Posted by keving View Post
ty dude i was workingon it but no ty :)

:handsdown::handsdown::handsdown::handsdown::hands down::handsdown::handsdown:
Use the *thanks button :)


Quote:
Originally Posted by Zanzibar View Post
Uh.. This takes up a lot of memory lol
I mentioned it wasn't the most efficient way, just the easiest for people to look at and understand what it's doing :P (hopefully noobs wont just copy-paste, but actually try to learn from the script)
09/16/2008 13:37 Zanzibar#6
I sed lawl not lol >_<
09/16/2008 13:39 Rechocto#7
Quote:
Originally Posted by Zanzibar View Post
I used lol not lol >_<
I'm just correcting your pronunciation.. "ol" as in "Sol", the name of our sun, or "old", or "Toll", etc.. you sound like you were dropped on your head saying it like you are doing :)
09/16/2008 14:22 keving#8
@Rechocto: Pls add me at MSN: [Only registered and activated users can see links. Click Here To Register...]
09/16/2008 21:54 Zanzibar#9
Quote:
Originally Posted by Rechocto View Post
I'm just correcting your pronunciation.. "ol" as in "Sol", the name of our sun, or "old", or "Toll", etc.. you sound like you were dropped on your head saying it like you are doing :)
What if I was dropped on my head...
09/16/2008 22:21 Rechocto#10
special fred... momma dropped him, on his head.. now he's not so, bright--instead, he's just a little bit special


okay enough singing :p
09/17/2008 01:04 tao4229#11
Quote:
Originally Posted by Rechocto View Post
special fred... momma dropped him, on his head.. now he's not so, bright--instead, he's just a little bit special


okay enough singing :p
This is no pronunciation of "lol", you can pronounce it however you feel.

LAWLZ KAI.
09/17/2008 01:09 Rechocto#12
Dang-it Tao, you used to be cool =o
09/17/2008 10:17 konkizta#13
:handsdown::handsdown::handsdown:Thanks :handsdown::handsdown::handsdown:
:handsdown::handsdown: Thanks Thanks:handsdown::handsdown:
:handsdown: Thanks Thanks Thanks:handsdown::handsdown:
--Thanks Thanks Thanks Thanks--
:handsdown: Thanks Thanks Thanks:handsdown::handsdown:
:handsdown::handsdown: Thanks Thanks:handsdown::handsdown:
:handsdown::handsdown::handsdown: Thanks :handsdown::handsdown::handsdown:
09/17/2008 15:25 YukiXian#14
Cool ! Thank you very much, ... Btw.. .You know how to let an Guard move back to his Spawning place? Like when you are blue name and Out of range, They will folow you...
09/17/2008 15:48 Rechocto#15
you could either disable following, or add to Move() "If(Target == null && MType == 1 && (PosX != StartX || PosY != StartY)) { PosX = StartX; PosY = StartY; World.SurroundMobs(this); World.SpawnMobForPlayers(this, true); }"

or something :)