Purpose: To support packet 199.
Difficulty: 9/10
Files Modified: Player.class, PacketManager.class
Files Created: NPCOption3.class
Credits: The Java Guru(Annexation), and Me.
Step 1:
Go into your Packet Handler Folder.
Add this:*CHANGE THE IMPORTS TO YOURS*
Name it: NPCOption3.java
Code:
/*
* Class NPCOption3
*
* Version 1.0
*
* Sunday, September 13, 2009
*
* Created by a Person
*/
package net.com.codeusa.net.packethandler;
import net.com.codeusa.Server;
import net.com.codeusa.Engine;
import net.com.codeusa.npcs.*;
import net.com.codeusa.model.skills.*;
import net.com.codeusa.model.games.*;
import net.com.codeusa.model.combat.*;
import net.com.codeusa.model.Player;
import net.com.codeusa.util.Misc;
public class NPCOption3 implements Packet {
public void handlePacket(Player p, int packetId, int packetSize) {
if (p == null || p.stream == null) {
return;
}
if (!p.npcOption3) {
int npcId = p.stream.readUnsignedWordBigEndian();
if (npcId <= 0 || npcId >= Engine.npcs.length || Engine.npcs[npcId] == null) {
return;
}
p.clickId = npcId;
p.clickX = Engine.npcs[npcId].absX;
p.clickY = Engine.npcs[npcId].absY;
if (Misc.getDistance(p.absX, p.absY, p.clickX, p.clickY) > 30) {
return;
}
p.npcOption3 = true;
}
if (p.clickId <= 0 || p.clickId >= Engine.npcs.length || Engine.npcs[p.clickId] == null) {
p.npcOption3 = false;
return;
}
if (Misc.getDistance(p.absX, p.absY, p.clickX, p.clickY) > 1) {
return;
}
p.npcOption3 = false;
switch (p.clickId) {
default:
Misc.println("[" + p.username + "] Unhandled npc option 3: " + p.clickId);
break;
}
}
}
Step 2:
Open up PacketManager.java
Search for:
Code:
public NPCOption2 npcOption2 = new NPCOption2();
Under it, add:
Code:
public NPCOption3 npcOption3 = new NPCOption3();
Step 3:
Search for:
You should see:
Code:
case 52:
/*
* Second NPC option.
*/
npcOption2.handlePacket(p, packetId, packetSize);
break;
Under it, add:
Code:
case 199:
/*
* Third NPC option.
*/
npcOption3.handlePacket(p, packetId, packetSize);
break;
Step 4:
Open up Player.java
Search for:
Code:
public boolean npcOption2 = false;
Under it, add:
Code:
/**
* Clicked the third option on a NPC.
*/
public boolean npcOption3 = false;
Step 5:
Search for:
Under:
Code:
if (npcOption2) {
Engine.packets.npcOption2.handlePacket(this, 0, 0);
}
Add:
Code:
if (npcOption3) {
Engine.packets.npcOption3.handlePacket(this, 0, 0);
}
Step 6:
Search for:
Code:
npcOption2 = false;
Under it, add:
Code:
npcOption3 = false;
There you go.