MADE BY CARLOSX55
FORUMS = WWW.ANC13NTSANDCARLOSX55.TK
Tut name: Making some npc`s unattackable
Difficulty: 1/10
Classes Modified Client.Java, we will also look at(but not touch) NPCHandler.Java just for learning reasons.
Step One - Introduction and learning of ints in NPCHandler.Java.
We will basically look at our NPCHandler just to learn some things that may, or may not be important. If you don't have what is here, the tutorial will most likely NOT work. If you have a question please post it here.
First, open up your NPCHandler.Java. You will see lots of stuff here. Type CTRL + F to open up your search. Find:
Code:
This will cause client crashes if we don't use this
If you can't find this, please PM me. You probably had a leecher go through your source and change anc13nts name to theirs. Limit down the search and try to find something similar. You should see something like the following:
Code:
if(slot == -1) return; // no free slot found
if(HP <= 0) { // This will cause client crashes if we don't use this

– anc13nts
HP = 3000;
}
This basically states that if the NPC spawned has <= 0 HP (an unattackable NPC), it will put it up to 3000 so that the client doesn't crash when the NPC is attacked.
That's our introduction. Now, this is going to be very important because we need to know the numbers: 3000, and <= 0.
Step Two - Using our knowledge of the HP int to make the NPC's unattackable.
Unlike the above step, this step is needed! This will make NPC's with <= 0 HP or 3000 HP unattackable.(NPC's that aren't declared or are set to unattackable in your NPC.CFG.)
Ok, this step is rather easy. To start, open up your client.java. You may close your NPC.java aswell.
Find the following:
Code:
case 131: //Magic on NPCs
This is your magic on NPC's case. Every time you try to use a magic spell on an NPC it will call this case. Thus, we need to add our code here.
If they aren't already there, add these ints:
Code:
int EnemyX2 = server.npcHandler.npcs[npcIndex].absX;
int EnemyY2 = server.npcHandler.npcs[npcIndex].absY;
int EnemyHP2 = server.npcHandler.npcs[npcIndex].HP;
These ints declare the NPC's X coord, Y coord, and HP. We only need the HP int, but it's best to put in the other ints aswell incase they are needed later. They were needed in my old code.
Now, you have your ints. All you need now is a code to use them. This is rather simple. Note the fact that EnemyHP2 is calling the HP int we saw in NPCHandler.java earlier!
If it is not there already, declare this boolean:
Code:
boolean Cant = false;
Under your new(?) boolean, add this code, or replace the code that is there:
Code:
if(server.npcHandler.npcs[npcIndex].attacknpc > 0 || EnemyHP2 == 3000 || EnemyHP2 <= 0) {
Cant = true;
sendMessage("You can't attack this npc!");
}
Now every time you attack an NPC with <= 0, 3000, or a "dueling NPC"(from another person's work... Delete it if you want.), it will say "You can't attack this npc!"
You will also probably get a message something like "You can't attack another player's summoned NPC!" depending on your base. Just delete the sendmessage for that as it doesn't matter.
Now, for those who didn't have the Cant boolean, find the following under your mage attacking case:
Code:
if((server.npcHandler.npcs[npcIndex]
Add this at the end of all of those variables:
Code:
&& !Cant
it should look something like this. This is what mine looks like:
Code:
if((server.npcHandler.npcs[npcIndex] != null) && (server.npcHandler.npcs[npcIndex].followPlayer < 1 || server.npcHandler.npcs[npcIndex].followPlayer == playerId) && slayer2 == true && !Cant && server.npcHandler.npcs[npcIndex].HP != 10000) {
Now you're done. You have all of your NPC's that don't have HP completely unattackable. This means shop owners, random NPC's, ect.
All NPC's that have 1 or more HP in your NPC.CFG file will be attackable, and those with <= 0 will not be attackable!
If you want to make an unattackable NPC attackable, open your NPC.CFG and find the ID of the NPC. Make the HP more than 1. Then compile, run, and you have that NPC attackable as well! You can do the exact opposite to make an NPC that is already attackable unattackable.
And that's it! You are done! Thanks for reading. If you used this, or even didn't, please leave a coment! I want to hear your coments weather they are good or bad. It isn't too hard to press reply and type a few words. I am not going to threaton to take things down because that hurts the people who actually reply aswell as those who don't.
Good luck adding this to your source. If you have any coments, questions, or suggestions please post them here or PM me!
NOTE: This is only coded to make NPC's unattackable by magic…
WWW.ANC13NTSANDCARLOSX55.TK