The Soul
Moderator
Number of posts : 8
Points :
Registration date : 2009-12-31
|
Subject: Handling Packet 40 Thu Dec 31, 2009 12:54 am |
|
|
This way is a lot more efficient than the huge if-statement lying in packet 40 checking every single continuous dialogue.
You'll first need to add an array (take every ID in packet 40 that the NpcDialogue var checks to see if it's equal). For example, do: - Code:
-
public int[] continueDialogue = { 29, 50, 232 }; Once you have an array you'll need to add this method: - Code:
-
public boolean continue(int ID) { // returns type boolean for(int i : continueDialogue) { // using enhanced for loop to loop through the continueDialogue array return i == ID ? true : false; // uses ternary operator to check if iterator, 'i' is equal to parameter variable, ID, and if it is, it will return true. If it doesn't, it will return false } } Under packet 40, once you've collected all of the data, replace it with: - Code:
-
case 40: // starts packet 40 if(continue(NpcDialogue)) // if you look back at the continue() method, it checks if the any elements in the array when you looped through it equaled NpcDialogue it would return true NpcDialogue++; // var NpcDialogue goes up in increments of 1 break; // ends packet 40 Although a small tutorial it should be beneficial.
|
|