Thread: Dialog System

Page 1 of 2 12 LastLast
Results 1 to 10 of 13
  1. #1 Dialog System 
    Member

    Join Date
    Dec 2007
    Posts
    1,094
    Thanks given
    8
    Thanks received
    8
    Rep Power
    0
    I've been away for a while, so I'm going to post my dialog I'm working on. This continues dialog with player and npc faces + multi lines. *credits to pali and who ever released the player face one.

    Video:


    replace NPCOption1.java with this

    Code:
    /*
     * Class NPCOption1
     *
     * Version 1.0
     *
     * Friday, August 22, 2008
     *
     * Created by Palidino76
     */
    
    package palidino76.rs2.io.packets;
    
    import palidino76.rs2.Engine;
    import palidino76.rs2.players.Player;
    import palidino76.rs2.util.Misc;
    
    public class NPCOption1 implements Packet {
        /**
         * Handles the first NPC option.
         * @param p The Player which the frame should be handled for.
         * @param packetId The packet id this belongs to.
         * @param packetSize The amount of bytes being recieved for this packet.
         */
        public void handlePacket(Player p, int packetId, int packetSize) {
            if (p == null || p.stream == null) {
                return;
            }
            if (!p.npcOption1) {
                int npcId = p.stream.readUnsignedWordA();
                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.npcOption1 = true;
            }
            if (p.clickId <= 0 || p.clickId >= Engine.npcs.length || Engine.npcs[p.clickId] == null) {
                p.npcOption1 = false;
                return;
            }
            if (Misc.getDistance(p.absX, p.absY, p.clickX, p.clickY) > 1) {
                return;
            }
            p.npcOption1 = false;
    		talk(p, p.clickId);
        }
    	
    	public void talk(Player p, int npcId) {
    		reset(p);
    		switch (npcId) {
    			case 2:
    				p.stage[0] = true;
    				npcOneLine(p, 0, 9827, "Hans", "How are you on this lovely day?");
    				break;
    			case 3:
    				p.stage[1] = true;
    				npcOneLine(p, 1, 9827, "Man", "I am the MAN!");
    				break;
    			default:
    				Misc.println("[" + p.username + "] Unhandled npc option 1: " + p.clickId);
    				break;
    		}
    	}
    	
    	public void npcOneLine(Player p, int npcId, int animation, String npcName, String message) {
    		p.frames.showChatboxInterface(p, 241);
            p.frames.animateInterfaceId(p, animation, 241, 2);
            p.frames.setNPCId(p, npcId, 241, 2);
            p.frames.setString(p, npcName, 241, 3);
            p.frames.setString(p, message, 241, 4);
    	}
    	
    	public void npcTwoLine(Player p, int npcId, int animation, String npcName, String message, String message2) {
    		p.frames.showChatboxInterface(p, 242);
            p.frames.animateInterfaceId(p, animation, 242, 2);
            p.frames.setNPCId(p, npcId, 242, 2);
            p.frames.setString(p, npcName, 242, 3);
            p.frames.setString(p, message, 242, 4);
    		p.frames.setString(p, message2, 242, 5);
    	}
    	
    	public void npcThreeLine(Player p, int npcId, int animation, String npcName, String message, String message2, String message3) {
    		p.frames.showChatboxInterface(p, 243);
            p.frames.animateInterfaceId(p, animation, 243, 2);
            p.frames.setNPCId(p, npcId, 243, 2);
            p.frames.setString(p, npcName, 243, 3);
            p.frames.setString(p, message, 243, 4);
    		p.frames.setString(p, message2, 243, 5);
    		p.frames.setString(p, message3, 243, 6);
    	}
    	
    	public void npcFourLine(Player p, int npcId, int animation, String npcName, String message, String message2, String message3, String message4) {
    		p.frames.showChatboxInterface(p, 244);
            p.frames.animateInterfaceId(p, animation, 244, 2);
            p.frames.setNPCId(p, npcId, 244, 2);
            p.frames.setString(p, npcName, 244, 3);
            p.frames.setString(p, message, 244, 4);
    		p.frames.setString(p, message2, 244, 5);
    		p.frames.setString(p, message3, 244, 6);
    		p.frames.setString(p, message4, 244, 7);
    	}
    	
    	public void playerOneLine(Player p, int animation, String message) {
    		p.frames.showChatboxInterface(p, 64);
            p.frames.animateInterfaceId(p, animation, 64, 2);
            p.frames.setId(p, 64, 2);
            p.frames.setString(p, p.username, 64, 3);
    		p.frames.setString(p, message, 64, 4);
    	}
    	
    	public void playerTwoLine(Player p, int animation, String message, String message2) {
    		p.frames.showChatboxInterface(p, 65);
            p.frames.animateInterfaceId(p, animation, 65, 2);
            p.frames.setId(p, 65, 2);
            p.frames.setString(p, p.username, 65, 3);
    		p.frames.setString(p, message, 65, 4);
    		p.frames.setString(p, message2, 65, 5);
    	}
    	
    	public void playerThreeLine(Player p, int animation, String message, String message2, String message3) {
    		p.frames.showChatboxInterface(p, 66);
            p.frames.animateInterfaceId(p, animation, 66, 2);
            p.frames.setId(p, 66, 2);
            p.frames.setString(p, p.username, 66, 3);
    		p.frames.setString(p, message, 66, 4);
    		p.frames.setString(p, message2, 66, 5);
    		p.frames.setString(p, message3, 66, 6);
    	}
    	
    	public void playerFourLine(Player p, int animation, String message, String message2, String message3, String message4) {
    		p.frames.showChatboxInterface(p, 67);
            p.frames.animateInterfaceId(p, animation, 67, 2);
            p.frames.setId(p, 67, 2);
            p.frames.setString(p, p.username, 67, 3);
    		p.frames.setString(p, message, 67, 4);
    		p.frames.setString(p, message2, 67, 5);
    		p.frames.setString(p, message3, 67, 6);
    		p.frames.setString(p, message4, 67, 7);
    	}
    	
    	public boolean checkContinue(Player p) {
    		if (p.stage[0]) {
    			switch (p.iStage) {
    				case 0:
    					playerOneLine(p, 9846, "Npc chains work!");
    					p.iStage++;
    					break;
    				case 1:
    					npcOneLine(p, 0, 9827, "Hans", "Well, fuck you too!");
    					p.iStage++;
    					break;
    				case 2:
    					npcFourLine(p, 0, 9827, "Hans", "Well, I'm sorry for that.", "Here take this,", "just please don't hurt me.", "I beg you!");
    					Engine.playerItems.addItem(p, 1042, 1);
    					p.iStage++;
    					break;
    				default:
    					return false;
    			}
    			return true;
    		} else if (p.stage[1]) {
    			switch (p.iStage) {
    				case 0:
    					playerOneLine(p, 9846, "Cool?");
    					p.iStage++;
    					break;
    				case 1:
    					npcOneLine(p, 1, 9827, "Man", "Indeed!");
    					p.iStage++;
    					break;
    				case 2:
    					playerTwoLine(p, 9846, "So what is this place?", "Am I in jail?");
    					p.iStage++;
    					break;
    				case 3:
    					npcOneLine(p, 1, 9827, "Man", "Lawlz you are soooo drunk...");
    					p.iStage++;
    					break;
    				case 4:
    					playerFourLine(p, 9846, "Wow", "WILL", "YOU", "DIE!");
    					p.iStage++;
    					break;
    				default:
    					return false;
    			}
    			return true;
    		} else
    			return false;
    	}
    	
    	public void reset(Player p) {
    		for (int i = 0; i < p.stage.length; i++) {
    			p.stage[i] = false;
    		}
    		p.iStage = 0;
    	}
    }
    in PacketManager.java add this packet.

    Code:
    case 63:
    	/*
    	 * Click here to continue.
    	*/
    	if (!npcOption1.checkContinue(p))
    		p.frames.removeChatboxInterface(p);
    	break;
    in Player.java add these.

    Code:
    public boolean[] stage = new boolean[2];
    public int iStage;
    Thank you nicole for pointing that bug out. ;]

    It's pretty self explanitory, if you need help using it I can make a video, just request it. If you don't like it don't post. Have fun.
    Reply With Quote  
     

  2. Thankful users:


  3. #2  
    Renown Programmer

    Nikki's Avatar
    Join Date
    Aug 2008
    Posts
    3,992
    Thanks given
    553
    Thanks received
    1,078
    Rep Power
    5000
    Problem with continue, if another player comes and requests any dialog, you will have a problem with them and the continue, since the dialog will be set to the second player (not all players click continue right after), store the dialog currently shown in the player's file

    Not bad, but err, could use 1 method for player/npc dialog and just check..

    I already have a dialogue system, but this is basically the way to do it
    Please don't add/pm me asking for RSPS help!

    Links:
    - Pastebin
    - Sleeksnap

    Reply With Quote  
     

  4. #3  
    Registered Member
    timetodothis's Avatar
    Join Date
    Jul 2009
    Posts
    532
    Thanks given
    24
    Thanks received
    55
    Rep Power
    123
    I just like it because its much better then how most people handle it,

    Besides conventions good job i suppose,
    Reply With Quote  
     

  5. #4  
    Renown Programmer

    Nikki's Avatar
    Join Date
    Aug 2008
    Posts
    3,992
    Thanks given
    553
    Thanks received
    1,078
    Rep Power
    5000
    Quote Originally Posted by TimeIsNow View Post
    I just like it because its much better then how most people handle it,

    Besides conventions good job i suppose,
    Most people use 2 classes (a NPCDialogue class and actionbutton to handle continue), which is fine if you don't have 200 dialogues
    Please don't add/pm me asking for RSPS help!

    Links:
    - Pastebin
    - Sleeksnap

    Reply With Quote  
     

  6. #5  
    Member

    Join Date
    Dec 2007
    Posts
    1,094
    Thanks given
    8
    Thanks received
    8
    Rep Power
    0
    Quote Originally Posted by Nicole View Post
    Problem with continue, if another player comes and requests any dialog, you will have a problem with them and the continue, since the dialog will be set to the second player (not all players click continue right after), store the dialog currently shown in the player's file

    Not bad, but err, could use 1 method for player/npc dialog and just check..

    I already have a dialogue system, but this is basically the way to do it
    Did not even take that into mind, let me look into that. Thanks for pointing that out.
    Reply With Quote  
     

  7. #6  
    Registered Member
    timetodothis's Avatar
    Join Date
    Jul 2009
    Posts
    532
    Thanks given
    24
    Thanks received
    55
    Rep Power
    123
    Quote Originally Posted by Nicole View Post
    Most people use 2 classes (a NPCDialogue class and actionbutton to handle continue), which is fine if you don't have 200 dialogues
    "click here to continue" Is not an action button.
    Reply With Quote  
     

  8. #7  
    Member

    Join Date
    Dec 2007
    Posts
    1,094
    Thanks given
    8
    Thanks received
    8
    Rep Power
    0
    I fixed the bug, should work for more than 1 person now. Thanks Nicole.
    Reply With Quote  
     

  9. #8  
    Member Dialog System Market Banned
    Awak333's Avatar
    Join Date
    Dec 2009
    Age
    30
    Posts
    825
    Thanks given
    241
    Thanks received
    45
    Rep Power
    22
    nice
    Mystery Youtube Video: Give it some thought
    Then learn how real it is: You don't have to believe it, it is real
    Reply With Quote  
     

  10. #9  
    Super Donator

    Sydney's Avatar
    Join Date
    Jul 2009
    Age
    31
    Posts
    560
    Thanks given
    184
    Thanks received
    175
    Rep Power
    867
    Impressive, I think I should use this. I've been using a terrible version for NPC dialogue and I just haven't gotten around to fixing it. =)
    Rep4u


    Spoiler for lulz:








    Reply With Quote  
     

  11. #10  
    Meh. I can't code.

    Soulevoker's Avatar
    Join Date
    Sep 2007
    Age
    29
    Posts
    1,198
    Thanks given
    5
    Thanks received
    6
    Rep Power
    137
    This is a nice release, could handle things a bit differently, but 'tis nice. For the continue, add switch (npcId) as well.(Instead of using the boolean)

    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •