[Release]5165 code to prohibit Guard attack

01/31/2010 11:11 kamote#1
hi guys let me share you this simple code that will prohibit players from attacking the guards in most city of CO. i hope this release will be useful.

here is the guide:

1. open Attack.cs in PacketHandling.

2. in Attack.cs look for this code
Code:
public static void Handle(Main.GameClient GC, byte[] Data)
3. above it add this code
Code:
        public static bool isCity(ushort mapID)
        {
            bool  retValue=false;
            switch(mapID)
            {
                case 1000:
                case 1002:
                case 1039:
                case 1213:
                case 1011:
                case 1036:
                case 2020:
                case 2021:
                    {
                        retValue = true;
                        break;
                    }
            }
       
            return(retValue); 
        }
4. then find this code
Code:
  if (Game.World.H_Mobs.Contains(GC.MyChar.Loc.Map))
                    {
                        Hashtable MapMobs = (Hashtable)Game.World.H_Mobs[GC.MyChar.Loc.Map];
                        if (MapMobs.Contains(TargetUID))
                        {
5. lastly add this code below;
Code:
if (PossMob.Mesh == 900 && isCity(PossMob.Loc.Map))
{
   GC.AddSend(Packets.ChatMessage(0, "SYSTEM", GC.MyChar.Name, "you cannot attack guard in this server", 2001, 0));
                        return;
 }
For Skills not to hit Guards follow this steps.

1. Open Skills.cs and search for
Quote:
void GetMobTargets(uint Single)
{
if (Info.ExtraEff == ExtraEffect.Ride || Info.ExtraEff == ExtraEffect.UnMount) return;
if (Info.Targetting == TargetType.Single)
{
if (World.H_Mobs.Contains(User.Loc.Map))
{
Mob M = (Mob)((Hashtable)(World.H_Mobs[User.Loc.Map]))[Single];
if (M != null && M.Alive && M.Mesh!=900)
MobTargets.Add(M, GetDamage(M));
}
}
else
{
bool RangeFromChar = true;
if (Info.Targetting == TargetType.FromSingle)
{
Mob M = (Mob)((Hashtable)(World.H_Mobs[User.Loc.Map]))[Single];
if (M != null && M.Alive && M.Mesh != 900)
{
MobTargets.Add(M, GetDamage(M));
AimX = M.Loc.X;
AimY = M.Loc.Y;
RangeFromChar = false;
}
}
else if (Info.Targetting != TargetType.Sector && Info.Targetting != TargetType.Linear && Info.Targetting != TargetType.Range && Info.Targetting != TargetType.FromPoint)
{
AimX = User.Loc.X;
AimY = User.Loc.Y;
RangeFromChar = true;
}
else
RangeFromChar = false;
Hashtable MapMobs = (Hashtable)World.H_Mobs[User.Loc.Map];
List<coords> Line = new List<coords>(5);
if (Info.Targetting == TargetType.Linear)
Line = MyMath.LineCoords(User.Loc.X, User.Loc.Y, AimX, AimY, 10);
if (MapMobs != null)
foreach (Mob M in MapMobs.Values)
{
if (M.Alive && M.Mesh != 900)
{
if ((!RangeFromChar && MyMath.PointDistance(AimX, AimY, M.Loc.X, M.Loc.Y) <= Info.MaxDist) || MyMath.PointDistance(User.Loc.X, User.Loc.Y, M.Loc.X, M.Loc.Y) <= Info.MaxDist)
if (Info.Targetting == TargetType.Sector && InSector(M.Loc.X, M.Loc.Y) || Info.Targetting != TargetType.Sector)
if (Info.Targetting == TargetType.Linear && Line.Contains(new coords(M.Loc.X, M.Loc.Y)) || Info.Targetting != TargetType.Linear)
if (User.PKMode == PKMode.PK || !M.NeedsPKMode && !MobTargets.Contains(M))
MobTargets.Add(M, GetDamage(M));
}
}
}
}
2. Change Your code with the red one.
end...
01/31/2010 11:58 ImmuneOne#2
Hey,

The thread is posted in the wrong sectioin, you are reported for doing that.
Please read the rules next time before you post in any section.

Regards,
ImmuneOne.
01/31/2010 11:59 Huseby#3
#Moved
01/31/2010 20:22 pro4never#4
Minor note: Why not use the guard name instead of the mesh? While people should be able to do that themselves... seems like some people might want to use the same mesh guards have for special quests/bosses or w/e. Ruling out an entire mesh instead of just a guard name (which shouldn't be changing on a regular basis anyways) seems a bit silly.

Other then that, good job!
02/01/2010 05:20 WHITELIONX#5
My chars are still running at and attacking guards >.<
02/01/2010 08:04 Arcо#6
Quote:
Originally Posted by WHITELIONX View Post
My chars are still running at and attacking guards >.<
Are those chars GM chars?
02/01/2010 09:41 WHITELIONX#7
[GM] and [PM] and normal chars lol
02/01/2010 09:42 Arcо#8
Try taking out,
if (GC.GM)
return;
02/01/2010 10:50 WHITELIONX#9
Would love to but I can`t build it until I have sorted the problem with the FB/SS thing lol. My source is throwing only two errors now "Extension methods must be defined in a non-generic static class" both are in MyMath.cs
02/01/2010 10:57 kamote#10
Quote:
Originally Posted by pro4never View Post
Minor note: Why not use the guard name instead of the mesh? While people should be able to do that themselves... seems like some people might want to use the same mesh guards have for special quests/bosses or w/e. Ruling out an entire mesh instead of just a guard name (which shouldn't be changing on a regular basis anyways) seems a bit silly.

Other then that, good job!
thanks for your suggestion... and for the compliment...
02/01/2010 14:00 WHITELIONX#11
Ok I have it now so that chars do not attack Guards but the only issue that caused it was because I called them Watchers and the source will only not attack anything with the word "Guard" in it. I stumbled across this because you can not attack WHSGuardian either ^^

Has anybody figured out how to not attack NPCs with magic attack yet?
02/02/2010 02:51 kamote#12
Quote:
Originally Posted by WHITELIONX View Post
Ok I have it now so that chars do not attack Guards but the only issue that caused it was because I called them Watchers and the source will only not attack anything with the word "Guard" in it. I stumbled across this because you can not attack WHSGuardian either ^^

Has anybody figured out how to not attack NPCs with magic attack yet?
change PossMob.Mesh==900 to PossMob.Name == "Watchers" .

check the updates...
02/03/2010 05:13 Jedex#13
#reported - double post
02/03/2010 07:20 WHITELIONX#14
Thank you kamote I might try that :D I am more concerned on being able to magic attack the NPCs though lol. I want to be able to not magic attack the NPCs.
02/03/2010 08:24 kamote#15
your welcome WHITELIONX... and don't forget to hit thanks if it work for you...