Hello Rune-Server members. Have any of you ever tried making an NPC teleport you when it dies and failed? Have you ever used a tutorial that caused the teleportation of players that did not deal the most damage to the monster? Well, I have a fix for you guys.
Difficulty: 1/10
Required Skills: How to read, how to copy, how to paste.
Purpose: To inform (Not to give you a bunch of codes and tell you exactly where to put them and claim this is a tutorial).
Base Tested On: Bulby's Strife (Should work for most 317's as long as they are Winterlove based)
Step One:
Open up your NpcHandler (NpcHandler.java)
Why?: This needs to be opened up so you can perform an editing task.
Step Two:
Locate your monster drops/effects on death in your NpcHandler.
How: Search for "Item2.random"
You should come up with something that looks like the following example...
Code:
if(npcs[NPCID].npcType == 59) {
ItemHandler.addItem(Item2.randomSpider(), npcs[NPCID].absX, npcs[NPCID].absY, 1, GetNpcKiller(NPCID), false);
}
Step Three:
Keep in mind that the npcType is the npc that you want to drop items or teleport you upon death, etc.
So, copy the above code, paste it under the last bracket of something that looks like the above code, and change the npcType from "59" to the ID of the NPC that you want to make teleport you to a location.
Now, delete "ItemHandler.addItem(Item2.randomSpider(), npcs[NPCID].absX, npcs[NPCID].absY, 1, GetNpcKiller(NPCID), false);"
Step Four:
The reason that this was deleted was because it was responsible for telling the server to drop the items for the method, randomSpider() in a different class known as item2 (item2.java is the editable file that is then compiled to modify the class), and this is not needed for the purpose of teleporting a player when the NPC dies.
So, now that you understand that, this is were it may get confusing.
In the space that was created upon deleting the above code, add the following:
Code:
client tele = (client) server.playerHandler.players[GetNpcKiller(NPCID)];
Now, let me explain this...
This is saying that the sever will use the client class to act on the player that dealt the most damage to the monster after it died, and it will recognize any variables in the client class as long as they are preceded by tele. in the npcHandler.
Difference from most tutorials: Most tutorials use something along the lines of...
Code:
int Player = npcs[NPCID].StartKilling;
client ppl = (client) server.playerHandler.players[Player];
This tells the server that the variable "ppl" only applies to whoever last started attacking the monster as opposed to who dealt the most damae to kill the monster, and this causes problems if a person is attacking a monster and someone else comes along and hits it once because that person is the one who gets teleported.
Step 5:
Now you should have something similar to:
Code:
if(npcs[NPCID].npcType == 59) {
client tele = (client) server.playerHandler.players[GetNpcKiller(NPCID)];
}
Now, understand that the client class uses "TeleportToX and TeleportToY for Winterlove bases to teleport players to different locations, so naturally, we must add those into this code.
Due the fact that we enabled this specific monster death in npcHandler to recognize all variables in the client class as long as they are preceded by "tele.", we can now add the following:
Code:
tele.teleportToX = ####;
tele.teleportToY = ####;
Note: You must change the ####'s to the X and Y coordinates that you wish the monster to teleport the player to on death.
So, your final code should look something like this example:
Code:
if(npcs[NPCID].npcType == 59) {
client tele = (client) server.playerHandler.players[GetNpcKiller(NPCID)];
tele.teleportToX = 3564;
tele.teleportToY = 3288;
}
Step 6:
Save the npcHandler class, compile your server files, and run your server.
Congratulate yourself on the successful completion of this tutorial.
Post questions or errors that you receive on this thread.
_________________________________
Other Uses:
Slayer skills (use the NPC death to coordinate with the client class in order to add experience and decrease monster counts, etc.)
Barrows (allow the brothers to teleport the proper player to a different brother upon death)
There are plenty of other uses for this accurate NPC death teleport.
~ Tetris