Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[tut]how to make npcs attack back..not being aggresive[tut]

Initiate Mage
Joined
Aug 11, 2009
Messages
1
Reaction score
0
Discription:This is a pretty simple way to make npcs attack back and not have them aggresive like everyone tries to pass off as attacking back...Note: THIS WILL TAKE OUT AGGRESIVE ALL TOGETHER. Also there is a very similar post on this on moparscape forums(i made it, note wootfarren and farren wolf, very similar names). I have atleast posted this in 2 other places than i have mentioned as to spread the knowledge. I always have farren in my name. I also explain how to make them hit harder or not as hard.

Dificulty: 1/10 im gonna make it really easy and i will explain =)

Classes modified: NPCHandler.java

Source tested on: Allstar scape, should still work on most..idk about over 317

Advice
: Back up NPCHandler.java incase you mess up!!!

Part I
2745
This is the jad id, it is most likely aggresive, on most servers it is..jad should always fight back. If you cant find it search for
Code:
 npcs[i].StartKilling = person.playerId;
You should find it instantly...it looks like
Code:
                    for (Player p : server.playerHandler.players) {
                        client person = (client) p;

                        if (p != null && person != null) {
                            if (p != null && person != null) { 
                                if (person.distanceToPoint(npcs[i].absX,
                                        npcs[i].absY)
                                        <= 20
                                                && p.heightLevel
                                                        == npcs[i].heightLevel) {
                                    if (npcs[i].npcType == 1158
                                            || npcs[i].npcType == 2745) {
                                        npcs[i].StartKilling = person.playerId;
                                        npcs[i].RandomWalk = false;
                                        npcs[i].IsUnderAttack = true;
                                    } else if (person.distanceToPoint(
                                            npcs[i].absX, npcs[i].absY)
                                                    >= 21
                                                            || person.heightLevel
                                                                    != npcs[i].heightLevel) {
                                        if (npcs[i].npcType == 1158
                                                || npcs[i].npcType == 2745) {
                                            npcs[i].RandomWalk = true;
                                        }
                                    }
                                } 
                            }
                        }
                    }
This is the common aggresive code, by inputting a npc it will make it aggresive and kill any player near it.

Replace all of that with
Code:
                    for (Player p : server.playerHandler.players) {
                        client person = (client) p;

                        if (p != null && person != null) {
                            if (p != null && person != null) { 
                                if (person.distanceToPoint(npcs[i].absX,npcs[i].absY)<= 2 && p.heightLevel== npcs[i].heightLevel) {
                                    if ((npcs[i].npcType == 2745 
					|| npcs[i].npcType == 1158) 
					&& (npcs[i].IsUnderAttack == true)) {
                                        npcs[i].StartKilling = person.playerId;
                                        npcs[i].RandomWalk = false; //attack stuff low level
                                    
			            } else if ((npcs[i].npcType == 2745 
					    || npcs[i].npcType == 1158)
					 && (npcs[i].IsUnderAttack == false)) { 
                                        npcs[i].RandomWalk = true;
                                        npcs[i].IsUnderAttack = false; //run your butt away
                                     
				    } else if (person.distanceToPoint(npcs[i].absX, npcs[i].absY)>= 127 || person.heightLevel != npcs[i].heightLevel) {
                                        if ((npcs[i].npcType == 2745 
					    || npcs[i].npcType == 1158)
					    && (npcs[i].IsUnderAttack == true)) {
                                            npcs[i].StartKilling = person.playerId;
                                        npcs[i].RandomWalk = false; //attack stuff high level
                                        }
                                    }
                                } 
                            }
                        }
                    }

rework the npcs to what ever you want

Explaining what this means

First part:
Code:
                                if (person.distanceToPoint(npcs[i].absX,npcs[i].absY)<= 2 && p.heightLevel== npcs[i].heightLevel) {
                                    if ((npcs[i].npcType == 2745 
					|| npcs[i].npcType == 1158) 
					&& (npcs[i].IsUnderAttack == true)) {
                                        npcs[i].StartKilling = person.playerId;
                                        npcs[i].RandomWalk = false; //attack stuff low level
This basically means that any player under lvl 2(hence the <=2) will be attacked. Since my starter lvl is 4 it means that since there are no lvl 2s, so it will attack the person that is attacking it.

Second part
Code:
			            } else if ((npcs[i].npcType == 2745 
					    || npcs[i].npcType == 1158)
					 && (npcs[i].IsUnderAttack == false)) { 
                                        npcs[i].RandomWalk = true;
                                        npcs[i].IsUnderAttack = false; //run your butt away
This basically means that if you run away from the monster(stop attacking it). The npc will return to its original state..as in not aggresive towards you, so it wont follow you.

Third part
Code:
				    } else if (person.distanceToPoint(npcs[i].absX, npcs[i].absY)>= 127 || person.heightLevel != npcs[i].heightLevel) {
                                        if ((npcs[i].npcType == 2745 
					    || npcs[i].npcType == 1158)
					    && (npcs[i].IsUnderAttack == true)) {
                                            npcs[i].StartKilling = person.playerId;
                                        npcs[i].RandomWalk = false; //attack stuff high level
This basically means that any player above lvl 127 will be attacked instead of the person attacking it. Since the max lvl on my server is 126 it will only attack the person attacking it.

You can change <=2 and >=127 to any lvls that you wish.

Also to add more simply do a || npcs.npcType == NPCID) under one of the npcs..i.e
Code:
                                        if ((npcs[i].npcType == 2745 
					    || npcs[i].npcType == 1158
					    || npcs[i].npcType == 3200)
REMEMBER to move the ) from the one above to the one below..like this it was 1158) but now the 3200 has the )
You have to add the npc to each thing...so the low lvl, run away, and high lvl parts or it WILL NOT WORK.

Part II

If you do not do this step then the npc will hit about up to a 5

Search for
hitDiff = 4 + misc.random

You should find it immedietly, you will see a bunch of these
Code:
                        } else if (npcs[NPCID].npcType == 2256) {
                            npcs[NPCID].animNumber = 451; // Paladin attack 
                            hitDiff = 4 + misc.random(8);                                                 
                        } else if (npcs[NPCID].npcType == 50) {
                            npcs[NPCID].animNumber = 91; // KBD attack  
                            hitDiff = 4 + misc.random(35);                                             
                        } else if (npcs[NPCID].npcType == 18) {
                            npcs[NPCID].animNumber = 451; // Al-K'harid Warrior Attack
                            hitDiff = 4 + misc.random(2);

To add another simply put a
Code:
     } else if (npcs[NPCID].npcType == NPCID) {
                            npcs[NPCID].animNumber = 451; // NPCName attack
                            hitDiff = 4 + misc.random(2);
after a(this is an example) hitDiff = 4 + misc.random(15);
so it will look like
Code:
                        } else if (npcs[NPCID].npcType == 50) {
                            npcs[NPCID].animNumber = 91; // KBD attack  
                            hitDiff = 4 + misc.random(15); 
                                   } else if (npcs[NPCID].npcType == NPCID) {
                            npcs[NPCID].animNumber = 451; // NPCName attack
                            hitDiff = 4 + misc.random(2);

What does this mean?

Ok now to explain, the npcType is simply NPCID of the monster..so like 50 is kbd.
Now to explain the animNumber, it is simply the animation that the npc does while attacking
Now to explain the hitdiff...all it means is that a HitDiff of 4 is being added to a random number. So like hitDiff = 4 + misc.random(35);.
So that is a hitdiff of 4 being added to a random number between 1 and 35.
You can change the random number to anything..like hitDiff = 4 + misc.random(15); Now it will be a random number between 1 and 15 with 4 added to it and that will be the damage that the npc does to you..

CREDITS:
Absoloutly and utterly 100% to me.

Reminder
If you find a tutorial like this anywhere then TELL ME!! I will gladly change the credits
Have fun, hope this helped and please keep the post alive
This has been directly copied from my post on silab forums under the same name
Give me any critism, help out if you see that it is retarded :) -farren wolf

Note If you do want the aggresive back then just ask me! I haven't tried to put it back but i most likely can add it under the attack back function. If you try this back up NPCHandler before you do it!!

Please post if you can
 
Back
Top