Info: Ever wanted to added talking to NPCs. Ever wanted them to tele you, or say a different thing when you have a certain item or something.
Difficulty: 4/10
[Only registered and activated users can see links. Click Here To Register...]
First we make the make the npc dialogue. Search for public void UpdateNPCChat() {
There will be all of the npc dialogue. The dialogue ids are labeled by cases, so for example case 15: would be npcdialogue 15. Find the last npcdialogue. For example if the last dialogue is case 27, make a new one called case 28: We are going to add some text in there.
The dialogue goes in the chatbox with the sendFrame164(4882);Code:sendFrame200(4883, 591);
sendFrame126(GetNpcName(NpcTalkTo), 4884);
sendFrame126("Hello free stuff plz", 4885);
sendFrame75(NpcTalkTo, 4883);
sendFrame164(4882);
NpcDialogueSend = true;
The GetNpcName(NpcTalkTo) is the npc you are talking to, it shows their name. The sendFrame75(NpcTalkTo, 4883); shows a picture of the npcs head. Finally of course the "Hello free stuff plz", replace what you want the npc to say.
Also we will need to add a break; at the end of that.
Final result:
To make the Npc say that, go to case 155: and in there add this.Code:case 28:
sendFrame200(4883, 591);
sendFrame126(GetNpcName(NpcTalkTo), 4884);
sendFrame126("Hello free stuff plz", 4885);
sendFrame75(NpcTalkTo, 4883);
sendFrame164(4882);
NpcDialogueSend = true
break;
Note packet 155 is the case for first click npc (first option on an npc)
In that case at the beginning search
Of course don't search the ""DIFFERENT"", only search the ending. The ""DIFFERENT"" varies from each server. For example mines is NPCIDCode:""DIFFERENT"" = server.npcHandler.npcs[NPCSlot].npcType;
Now in case 155 add.Code:NPCID = server.npcHandler.npcs[NPCSlot].npcType;
Remember change the ""DIFFERENT"" to what you have in your server. The "NpcWanneTalk" is the id of the npcdialogue. Which we made earlier is 28.Code:if(""DIFFERENT"" == ###){
skillX = server.npcHandler.npcs[NPCSlot].absX;
skillY = server.npcHandler.npcs[NPCSlot].absY;
NpcWanneTalk = 28;
}
That is how you make basic npc dialogue.
Features
Continious dialogue
Info: Make an npc speak in a dialogue chat box more then once.
First look at your first npc dialogue (lets go back):
Under that add the number that comes after that (case 29). Make a new case 29 and put different text in itCode:case 28:
sendFrame200(4883, 591);
sendFrame126(GetNpcName(NpcTalkTo), 4884);
sendFrame126("Hello free stuff plz", 4885);
sendFrame75(NpcTalkTo, 4883);
sendFrame164(4882);
NpcDialogueSend = true
break;
Now find case 40: Note there will be lots of case 40:'s probably, so keep searching case 40 until you see one with "NpcDialogue" in it.Code:case 29:
sendFrame200(4883, 591);
sendFrame126(GetNpcName(NpcTalkTo), 4884);
sendFrame126("Will you give me free stuff?", 4885);
sendFrame75(NpcTalkTo, 4883);
sendFrame164(4882);
NpcDialogueSend = true
break;
This is the case for adding up the npc dialogue.
In the first code of that you should see
We are going to add NpcDialogue 28 in there. Don't add 29, because if you add the 29, it'll add 1 the dialogue, and you haven't added any case 30: for npcdialogue.Code:if (NpcDialogue == # || morenumbers..||morenumbers..||keepsgoing..) {
NpcDialogue += 1;
NpcDialogueSend = false;
So yeah add NpcDialogue == 28 in there
As you can see the "NpcDialogue += 1;" means it adds up your NpcDialogue once.Code:if (NpcDialogue == # || NpcDialogue == 28 || morenumbers..||morenumbers..||keepsgoing..) {
NpcDialogue += 1;
NpcDialogueSend = false;
Well thats how you make npc dialogue continue. You can do as many cases as you want for the npcdialogue cases.
Making an NPC say something different when you have a certain item.
Ok in case 155: (explained this earlier go back and see if you haven't)
You would add something like this:
Ok if you look in the code, if you don't have the item, the npcdialogue will go to # 30. But if you do have the item, it'll go to case 31 of npcdialogue.Code:if(""DIFFERENT"" == ###){
if(!playerHasItem(####)){
skillX = server.npcHandler.npcs[NPCSlot].absX;
skillY = server.npcHandler.npcs[NPCSlot].absY;
NpcWanneTalk = 30;
}
if(playerHasItem(####)){
skillX = server.npcHandler.npcs[NPCSlot].absX;
skillY = server.npcHandler.npcs[NPCSlot].absY;
NpcWanneTalk = 31;
}
}
Of course you will need to add npcdialogue 30 + 31. You would made them something like
case 30 would be 'you don't have the item you noob' and case 31 would be 'thanks for the item'
Making an npc tele you in chat
Really easy just add teleportToX and teleportToY in the npcdialogue case example:
And of course you will need to add the talking in packet 155 (explained earlier)Code:case 99:
sendFrame200(4883, 591);
sendFrame126(GetNpcName(NpcTalkTo), 4884);
sendFrame126("Teleing you to blahblah land for not giving me free stuff", 4885);
sendFrame75(NpcTalkTo, 4883);
sendFrame164(4882);
NpcDialogueSend = true
teleportToX = x;
teleportToY = y;
break;
Well thats my tutorial, thanks for reading. If you have any suggestions please post. Also if you have read this please post thanks :)
