Adding a Easy-To-Use Dialogue (NPC/Player) System
~Lester Knome's Easy-To-Use Tutorials~
MAKE SURE YOU MAKE A BACKUP
I made this after i saw what rog3r made xD (He had a mistake in his coding, but let's let lil rog3r figure it out.)
First save this to Dialogue.java:
Code:
public class Dialogue {
public void npcChat(int ID) {
client c = (client) server.playerHandler.players[ID];
/*Npc Chat*/
switch (c.NpcDialogue) {
/*
Example:
case 1:
npcChat("Oman dis nice", 454);
nextChat(2);
break;
case 2:
npcChat("Bai Bai", 454);
nextChat(-1);
break;
*/
}
}
public void option1(int ID) {
client c = (client) server.playerHandler.players[ID];
/*option1 for Choice*/
/*
Example:
if (c.NpcDialogue == 2) {
c.sendMessage("Hi :D");
}
*/
}
public void option2(int ID) {
client c = (client) server.playerHandler.players[ID];
/*option1 for Choice*/
/*
Example:
if (c.NpcDialogue == 2) {
c.sendMessage("Bye D:");
}
*/
}
public void playerChat(String text) { // Player talking.
client c = null;
c.sendFrame200(974, 595);
c.sendFrame126(c.playerName, 975);
c.sendFrame126(text, 976);
c.sendFrame126("", 977);
c.sendFrame185(974);
c.sendFrame164(973);
c.NpcDialogueSend = true;
}
public void playerChat(String text, String text2) { // Player talking.
client c = null;
c.sendFrame200(974, 595);
c.sendFrame126(c.playerName, 975);
c.sendFrame126(text, 976);
c.sendFrame126(text2, 977);
c.sendFrame185(973);
c.sendFrame164(973);
c.NpcDialogueSend = true;
}
public void npcChat(String text, int npc) { // NPC talking.
client c = null;
c.sendFrame200(4883, 591);
c.sendFrame126(c.GetNpcName(npc), 4884);
c.sendFrame126(text, 4885);
c.sendFrame126("Click here to continue.", 4886);
c.sendFrame75(npc, 4883);
c.sendFrame164(4882);
c.NpcDialogueSend = true;
}
public void npcChat(String text, String text2, int npc) { // NPC talking.
client c = null;
c.sendFrame200(4901, 591);
c.sendFrame126(c.GetNpcName(npc), 4902);
c.sendFrame126("", 4903);
c.sendFrame126(text, 4904);
c.sendFrame126(text2, 4905);
c.sendFrame126("", 4906);
c.sendFrame75(npc, 4901);
c.sendFrame164(4900);
}
public void choice(String option1, String option2) {
client c = null;
c.changeText126("Select an Option", 2460);
c.changeText126(option1, 2461);
c.changeText126(option2, 2462);
c.sendFrame164(2459);
}
public void nextChat(int next) {
if (next > 0) {
nextChat = next;
sendChat = true;
} else if(next == -1) {
nextChat = next;
}
}
public static int nextChat = -1;
public static boolean sendChat = false;
}
In server.java under:
Code:
public static PlayerHandler playerHandler = null;
Add:
Code:
public static Dialogue Dialogue = null;
And under:
Code:
playerHandler = new PlayerHandler();
Add:
Code:
Dialogue = new Dialogue();
Now in client.java in case 40, at the top, add:
Code:
if (server.Dialogue.sendChat) {
NpcDialogue = server.Dialogue.nextChat;
NpcDialogueSend = false;
server.Dialogue.sendChat = false;
} else if (server.Dialogue.nextChat == -1) {
server.Dialogue.sendChat = false;
NpcDialogue = 0;
NpcDialogueSend = false;
RemoveAllWindows();
}
Now under:
Add:
Code:
server.Dialogue.npcChat(playerId);
Now if you have a clickingMost.java, (If not look in packet 185 [Case 185:]) Look for:
Under that add:
clickingMost or any other handler:
Code:
server.Dialogue.option1(c.playerId);
else:
Code:
server.Dialogue.option1(playerId);
Now under:
add:
clickingMost or any other handler:
Code:
server.Dialogue.option2(c.playerId);
else:
Code:
server.Dialogue.option2(playerId);
Now to use, in:
Code:
public void npcChat(int ID) {
Under:
Code:
switch (c.NpcDialogue) {
add your dialogue.
Example:
Code:
case 1:
npcChat(line1", "line2", NpcID);
nextChat(Next 'case', 2);
break;
case 2:
npcChat("Npc Talking one line", NpcID);
nextChat(Skip 3, 4);
break;
case 3:
playerChat("Player Talking");
nextChat(To end, -1);
break;
case 4:
playerChat("Go Back to 3", "Line 2 of player talking");
nextChat(3);
break;
MAKE SURE YOU DON'T OVERRIDE ANY 'CASES' FROM CLIENT.JAVA
Previous Tutorial:[Only registered and activated users can see links. Click Here To Register...]
Next Tutorial: Adding a Easy-To-Use Quest System