Thread: [tut]make npc's auto attack you[tut]

Page 1 of 2 12 LastLast
Results 1 to 10 of 17
  1. #1 [tut]make npc's auto attack you[tut] 
    Registered Member


    Join Date
    Jul 2007
    Posts
    4,133
    Thanks given
    789
    Thanks received
    2,716
    Rep Power
    5000
    hey this is my tutorial about make npc's automatic attack you (explained)

    don't know if it's posted before if it is a mod please delete this

    we will start :

    first off you need to choose an npc wich you want to automatic attack you.
    i choosed and zamorak battle mage (id =912)

    ok so now go into npchandler.java and search for:

    Code:
    Moo
    under the last } there add:

    Code:
    {//battle mage zamorak
    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) <= 5 && person.heightLevel == npcs[i].heightLevel)
         if (npcs[i].npcType ==  912)
    {
        npcs[i].StartKilling = person.playerId;
        npcs[i].RandomWalk = false;
        npcs[i].IsUnderAttack = true;
    } else if (person.distanceToPoint(npcs[i].absX, npcs[i].absY) >= 5 || person.heightLevel != npcs[i].heightLevel)
         if (npcs[i].npcType == 912)
    {
        npcs[i].RandomWalk = true;
    }
    }
    }
    }
    }
    change the 912 to your npc id.
    what does this do? this makes it so that if your in range of the npc it will attack you.

    next search for:

    Code:
    npcs[i].updateRequired = true;
    u should see something like:

    Code:
    } else if (npcs[i].RandomWalk == false && npcs[i].IsUnderAttack == true) {
                                                    if(npcs[i].npcType == 1645 || npcs[i].npcType == 1241 || npcs[i].npcType == 1246 || npcs[i].npcType == 1159 || npcs[i].npcType == 54)
                                                    AttackPlayerMage(i);
                                                    else
    						AttackPlayer(i);
    add all those ids add:

    Code:
    npcs[i].npcType == 912 ||
    after the || 's

    again change the 912 to your npc id

    next search for:

    Code:
    if(npcs[i].StartKilling > 0) {
    u shuld see something like:

    Code:
    if(npcs[i].npcType == 1645 || npcs[i].npcType == 1246 || npcs[i].npcType == 54)
                                                    AttackPlayerMage(i);
                                                    else
                                                    AttackPlayer(i); 
                                                    }
    
                                                    }
                                                    else {
                                                    FollowPlayer(i);
                                                    }
    again add:

    Code:
    npcs[i].npcType == 1246
    after the || 's

    next search for:

    Code:
    if (person.distanceToPoint(npcs[i].absX, npcs[i].absY) >= 5)
    u should see this:

    Code:
    if (npcs[i].npcType != 1158 || npcs[i].npcType == 2745 || npcs[i].npcType == 2745)
    {
        npcs[i].RandomWalk = true;
    }
    }
    }
    }
    again add:

    Code:
    npcs[i].npcType == 2745 ||
    after the two || 's and change the 912 to your npc id

    next search for:

    Code:
    if (person.distanceToPoint(npcs[i].absX, npcs[i].absY) <= 20 && p.heightLevel == npcs[i].heightLevel)
    u should see:

    Code:
    if (npcs[i].npcType == 1158 || npcs[i].npcType == 2745 )
    {
        npcs[i].StartKilling = person.playerId;
        npcs[i].RandomWalk = false;
        npcs[i].IsUnderAttack = true;
    again add:

    Code:
    npcs[i].npcType == 912 ||
    and change the 912 to your npc ID

    now the intresting part comes:

    we now gonna add how the (in my case zamorak battle mages attack you)

    search for:

    Code:
    if (server.playerHandler.players[Player].IsDead == true) {
    u should see:

    Code:
    if (server.playerHandler.players[Player].IsDead == true) {
    						ResetAttackPlayer(NPCID);
    					} else {
                                                   npcs[NPCID].animNumber = 711; // mage attack
                                                   if(npcs[NPCID].npcType == 1645) {
                                                   p.stillgfx(369, p.absY, p.absX);
                                                   hitDiff = 6 + misc.random(43);
                                                   }
    after the last } add:

    Code:
    if(npcs[NPCID].npcType == 912) { //battle mage zamorak
    
    p.stillgfx(369, p.absY, p.absX);
    
                                                   hitDiff = 2 + misc.random(20); 
                                                   }
    il explain the code: the 369 is the gfx (this case ice barrage) change that to wich you want [Only registered and activated users can see links. ]

    for the gfx id's credits going to ant for this list.

    the:

    Code:
    misc.random(20);
    is how high he hits change the 20 higher or lower if u want them to hit higher/lower

    as last search for:

    Code:
    public boolean AttackNPCMage(int NPCID) {
    now u should see:

    Code:
    int EnemyX = server.npcHandler.npcs[npcs[NPCID].attacknpc].absX;
    		int EnemyY = server.npcHandler.npcs[npcs[NPCID].attacknpc].absY;
    		int EnemyHP = server.npcHandler.npcs[npcs[NPCID].attacknpc].HP;
    		int hitDiff = 0;
                    int Npchitdiff = 0;
                    int wepdelay = 0;
    		//hitDiff = misc.random(npcs[NPCID].MaxHit);
    			if (npcs[NPCID].actionTimer == 0) {
                             if (server.npcHandler.npcs[npcs[NPCID].attacknpc].IsDead == true) {
    					ResetAttackNPC(NPCID);
    					//npcs[NPCID].textUpdate = "Oh yeah I win bitch!";
    					//npcs[NPCID].textUpdateRequired = true;
                                            npcs[NPCID].animNumber = 2103;
    					npcs[NPCID].animUpdateRequired = true;
    					npcs[NPCID].updateRequired = true;
    under that u see:

    Code:
    } else  {
                                                   npcs[NPCID].animNumber = 711; // mage attack
                                                   if(npcs[NPCID].npcType == 1645) {
                                                   gfxAll(369, EnemyY, EnemyX);
                                                   hitDiff = 6 + misc.random(43);
                                                   }
    now under the last bracket of this code add:

    Code:
    if(npcs[NPCID].npcType == 912) {
                                                   gfxAll(369, EnemyY, EnemyX);
                                                   hitDiff = 2 + misc.random(20); 
                                                   }
    i explained the code earlier change the id to your npc id!

    this whas my tut i hope i helped yah rep apreciated!

    don't flame me if this is already posted it will be deleted then

    credits:

    npchandler.java: i think me
    gfx list: ant

    thanks for reading

    arvidje136
     

  2. #2  
    Respected Member


    Luke132's Avatar
    Join Date
    Dec 2007
    Age
    32
    Posts
    12,549
    Thanks given
    177
    Thanks received
    5,789
    Discord
    View profile
    Rep Power
    5000
    it is certainly explained better than the other way.
     

  3. #3  
    Casella
    Guest
    Good job, eat rep!
     

  4. #4  
    Registered Member


    Join Date
    Jul 2007
    Posts
    4,133
    Thanks given
    789
    Thanks received
    2,716
    Rep Power
    5000
    thanks i hope this helped for some people
     

  5. #5  
    kilermage
    Guest
    I will try to add this when I get home.
     

  6. #6  
    Registered Member


    Join Date
    Jul 2007
    Posts
    4,133
    Thanks given
    789
    Thanks received
    2,716
    Rep Power
    5000
    i'm glad you all like it
     

  7. #7  
    Registered Member Pheonix's Avatar
    Join Date
    Feb 2008
    Age
    26
    Posts
    287
    Thanks given
    0
    Thanks received
    0
    Rep Power
    50
    aye well done mate good tutorials, here have your well earned R3P i added to my server ty =)

    ~~Nightmare~~
    Name is spelled this way on purpose, before you ask. It's a personal choice, and matches with my YouTube: [Only registered and activated users can see links. ]
     

  8. #8  
    Registered Member


    Join Date
    Jul 2007
    Posts
    4,133
    Thanks given
    789
    Thanks received
    2,716
    Rep Power
    5000
    thanks mate gl further
     

  9. #9  
    Registered Member Pheonix's Avatar
    Join Date
    Feb 2008
    Age
    26
    Posts
    287
    Thanks given
    0
    Thanks received
    0
    Rep Power
    50
    hehe np still w8ing for my rep back :O

    ~~Nightmare~~
    Name is spelled this way on purpose, before you ask. It's a personal choice, and matches with my YouTube: [Only registered and activated users can see links. ]
     

  10. #10  
    Registered Member Rhys's Avatar
    Join Date
    Oct 2006
    Age
    26
    Posts
    532
    Thanks given
    1
    Thanks received
    1
    Rep Power
    45
    nice..(msg2sht)
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •